~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

  • Committer: Robert Collins
  • Date: 2007-11-09 17:50:31 UTC
  • mto: This revision was merged to the branch mainline in revision 2988.
  • Revision ID: robertc@robertcollins.net-20071109175031-agaiy6530rvbprmb
Change (without backwards compatibility) the
iter_lines_added_or_present_in_versions VersionedFile API to yield the
text version that each line is being returned from. This is useful for
reconcile in determining what inventories reference what texts.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
from bzrlib import (
 
18
    mail_client,
 
19
    tests,
 
20
    urlutils,
 
21
    )
 
22
 
 
23
class TestMutt(tests.TestCase):
 
24
 
 
25
    def test_commandline(self):
 
26
        mutt = mail_client.Mutt(None)
 
27
        commandline = mutt._get_compose_commandline(None, None, 'file%')
 
28
        self.assertEqual(['-a', 'file%'], commandline)
 
29
        commandline = mutt._get_compose_commandline('jrandom@example.org',
 
30
                                                     'Hi there!', None)
 
31
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
 
32
                         commandline)
 
33
 
 
34
 
 
35
class TestThunderbird(tests.TestCase):
 
36
 
 
37
    def test_commandline(self):
 
38
        tbird = mail_client.Thunderbird(None)
 
39
        commandline = tbird._get_compose_commandline(None, None,
 
40
                                                     'file%')
 
41
        self.assertEqual(['-compose', "attachment='%s'" %
 
42
                          urlutils.local_path_to_url('file%')], commandline)
 
43
        commandline = tbird._get_compose_commandline('jrandom@example.org',
 
44
                                                     'Hi there!', None)
 
45
        self.assertEqual(['-compose', "subject='Hi there!',"
 
46
                                      "to='jrandom@example.org'"], commandline)
 
47
 
 
48
 
 
49
class TestXDGEmail(tests.TestCase):
 
50
 
 
51
    def test_commandline(self):
 
52
        xdg_email = mail_client.XDGEmail(None)
 
53
        commandline = xdg_email._get_compose_commandline(None, None,
 
54
                                                         'file%')
 
55
        self.assertEqual([None, '--attach', 'file%'], commandline)
 
56
        commandline = xdg_email._get_compose_commandline(
 
57
            'jrandom@example.org', 'Hi there!', None)
 
58
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
 
59
                         commandline)
 
60
 
 
61
 
 
62
class TestEvolution(tests.TestCase):
 
63
 
 
64
    def test_commandline(self):
 
65
        evo = mail_client.Evolution(None)
 
66
        commandline = evo._get_compose_commandline(None, None, 'file%')
 
67
        self.assertEqual(['mailto:?attach=file%25'], commandline)
 
68
        commandline = evo._get_compose_commandline('jrandom@example.org',
 
69
                                                   'Hi there!', None)
 
70
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
 
71
                         commandline)
 
72
 
 
73
 
 
74
class TestKMail(tests.TestCase):
 
75
 
 
76
    def test_commandline(self):
 
77
        kmail = mail_client.KMail(None)
 
78
        commandline = kmail._get_compose_commandline(None, None, 'file%')
 
79
        self.assertEqual(['--attach', 'file%'], commandline)
 
80
        commandline = kmail._get_compose_commandline('jrandom@example.org',
 
81
                                                     'Hi there!', None)
 
82
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
 
83
                         commandline)
 
84
 
 
85
 
 
86
class TestEditor(tests.TestCase):
 
87
 
 
88
    def test_get_merge_prompt_unicode(self):
 
89
        """Prompt, to and subject are unicode, the attachement is binary"""
 
90
        editor = mail_client.Editor(None)
 
91
        prompt = editor._get_merge_prompt(u'foo\u1234',
 
92
                                        u'bar\u1234',
 
93
                                        u'baz\u1234',
 
94
                                        u'qux\u1234'.encode('utf-8'))
 
95
        self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
 
96
                              u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
 
97
        editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')