/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

  • Committer: Robert Collins
  • Date: 2008-04-08 03:39:43 UTC
  • mto: This revision was merged to the branch mainline in revision 3350.
  • Revision ID: robertc@robertcollins.net-20080408033943-ihbgs5wyqnh61bit
 * ``VersionedFile.get_sha1`` is deprecated, please use
   ``VersionedFile.get_sha1s``. (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
    errors,
 
19
    mail_client,
 
20
    tests,
 
21
    urlutils,
 
22
    )
 
23
 
 
24
class TestMutt(tests.TestCase):
 
25
 
 
26
    def test_commandline(self):
 
27
        mutt = mail_client.Mutt(None)
 
28
        commandline = mutt._get_compose_commandline(None, None, 'file%')
 
29
        self.assertEqual(['-a', 'file%'], commandline)
 
30
        commandline = mutt._get_compose_commandline('jrandom@example.org',
 
31
                                                     'Hi there!', None)
 
32
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
 
33
                         commandline)
 
34
 
 
35
    def test_commandline_is_8bit(self):
 
36
        mutt = mail_client.Mutt(None)
 
37
        cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
 
38
            u'Hi there!', u'file%')
 
39
        self.assertEqual(
 
40
            ['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
 
41
            cmdline)
 
42
        for item in cmdline:
 
43
            self.assertFalse(isinstance(item, unicode),
 
44
                'Command-line item %r is unicode!' % item)
 
45
 
 
46
 
 
47
class TestThunderbird(tests.TestCase):
 
48
 
 
49
    def test_commandline(self):
 
50
        tbird = mail_client.Thunderbird(None)
 
51
        commandline = tbird._get_compose_commandline(None, None,
 
52
                                                     'file%')
 
53
        self.assertEqual(['-compose', "attachment='%s'" %
 
54
                          urlutils.local_path_to_url('file%')], commandline)
 
55
        commandline = tbird._get_compose_commandline('jrandom@example.org',
 
56
                                                     'Hi there!', None)
 
57
        self.assertEqual(['-compose', "subject='Hi there!',"
 
58
                                      "to='jrandom@example.org'"], commandline)
 
59
 
 
60
    def test_commandline_is_8bit(self):
 
61
        # test for bug #139318
 
62
        tbird = mail_client.Thunderbird(None)
 
63
        cmdline = tbird._get_compose_commandline(u'jrandom@example.org',
 
64
            u'Hi there!', u'file%')
 
65
        self.assertEqual(['-compose',
 
66
            ("attachment='%s'," % urlutils.local_path_to_url('file%')) +
 
67
            "subject='Hi there!',to='jrandom@example.org'",
 
68
            ], cmdline)
 
69
        for item in cmdline:
 
70
            self.assertFalse(isinstance(item, unicode),
 
71
                'Command-line item %r is unicode!' % item)
 
72
 
 
73
 
 
74
class TestEmacsMailMode(tests.TestCase):
 
75
 
 
76
    def test_commandline(self):
 
77
        eclient = mail_client.EmacsMailMode(None)
 
78
        commandline = eclient._get_compose_commandline(None, None, 'file%')
 
79
        self.assertEqual(['--eval', '(mail nil nil nil)',
 
80
                          '(mail-text)', '(newline)',
 
81
                          '(attach "file%")'], commandline)
 
82
 
 
83
        commandline = eclient._get_compose_commandline('jrandom@example.org',
 
84
                                                     'Hi there!', None)
 
85
        self.assertEqual(['--eval', '(mail nil "jrandom@example.org" "Hi there!")',
 
86
                          '(mail-text)', '(newline)'], commandline)
 
87
 
 
88
    def test_commandline_is_8bit(self):
 
89
        eclient = mail_client.EmacsMailMode(None)
 
90
        commandline = eclient._get_compose_commandline(u'jrandom@example.org',
 
91
            u'Hi there!', u'file%')
 
92
        self.assertEqual(['--eval', '(mail nil "jrandom@example.org" "Hi there!")',
 
93
                          '(mail-text)', '(newline)',
 
94
                          '(attach "file%")'], commandline)
 
95
        for item in commandline:
 
96
            self.assertFalse(isinstance(item, unicode),
 
97
                'Command-line item %r is unicode!' % item)
 
98
 
 
99
 
 
100
class TestXDGEmail(tests.TestCase):
 
101
 
 
102
    def test_commandline(self):
 
103
        xdg_email = mail_client.XDGEmail(None)
 
104
        self.assertRaises(errors.NoMailAddressSpecified,
 
105
                          xdg_email._get_compose_commandline,
 
106
                          None, None, 'file%')
 
107
        commandline = xdg_email._get_compose_commandline(
 
108
            'jrandom@example.org', None, 'file%')
 
109
        self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
 
110
                         commandline)
 
111
        commandline = xdg_email._get_compose_commandline(
 
112
            'jrandom@example.org', 'Hi there!', None)
 
113
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
 
114
                         commandline)
 
115
 
 
116
    def test_commandline_is_8bit(self):
 
117
        xdg_email = mail_client.XDGEmail(None)
 
118
        cmdline = xdg_email._get_compose_commandline(u'jrandom@example.org',
 
119
            u'Hi there!', u'file%')
 
120
        self.assertEqual(
 
121
            ['jrandom@example.org', '--subject', 'Hi there!',
 
122
             '--attach', 'file%'],
 
123
            cmdline)
 
124
        for item in cmdline:
 
125
            self.assertFalse(isinstance(item, unicode),
 
126
                'Command-line item %r is unicode!' % item)
 
127
 
 
128
 
 
129
class TestEvolution(tests.TestCase):
 
130
 
 
131
    def test_commandline(self):
 
132
        evo = mail_client.Evolution(None)
 
133
        commandline = evo._get_compose_commandline(None, None, 'file%')
 
134
        self.assertEqual(['mailto:?attach=file%25'], commandline)
 
135
        commandline = evo._get_compose_commandline('jrandom@example.org',
 
136
                                                   'Hi there!', None)
 
137
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
 
138
                         commandline)
 
139
 
 
140
    def test_commandline_is_8bit(self):
 
141
        evo = mail_client.Evolution(None)
 
142
        cmdline = evo._get_compose_commandline(u'jrandom@example.org',
 
143
            u'Hi there!', u'file%')
 
144
        self.assertEqual(
 
145
            ['mailto:jrandom@example.org?attach=file%25&subject=Hi%20there%21'
 
146
            ],
 
147
            cmdline)
 
148
        for item in cmdline:
 
149
            self.assertFalse(isinstance(item, unicode),
 
150
                'Command-line item %r is unicode!' % item)
 
151
 
 
152
 
 
153
class TestKMail(tests.TestCase):
 
154
 
 
155
    def test_commandline(self):
 
156
        kmail = mail_client.KMail(None)
 
157
        commandline = kmail._get_compose_commandline(None, None, 'file%')
 
158
        self.assertEqual(['--attach', 'file%'], commandline)
 
159
        commandline = kmail._get_compose_commandline('jrandom@example.org',
 
160
                                                     'Hi there!', None)
 
161
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
 
162
                         commandline)
 
163
 
 
164
    def test_commandline_is_8bit(self):
 
165
        kmail = mail_client.KMail(None)
 
166
        cmdline = kmail._get_compose_commandline(u'jrandom@example.org',
 
167
            u'Hi there!', u'file%')
 
168
        self.assertEqual(
 
169
            ['-s', 'Hi there!', '--attach', 'file%', 'jrandom@example.org'],
 
170
            cmdline)
 
171
        for item in cmdline:
 
172
            self.assertFalse(isinstance(item, unicode),
 
173
                'Command-line item %r is unicode!' % item)
 
174
 
 
175
 
 
176
class TestEditor(tests.TestCase):
 
177
 
 
178
    def test_get_merge_prompt_unicode(self):
 
179
        """Prompt, to and subject are unicode, the attachement is binary"""
 
180
        editor = mail_client.Editor(None)
 
181
        prompt = editor._get_merge_prompt(u'foo\u1234',
 
182
                                        u'bar\u1234',
 
183
                                        u'baz\u1234',
 
184
                                        u'qux\u1234'.encode('utf-8'))
 
185
        self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
 
186
                              u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
 
187
        editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')
 
188
 
 
189
 
 
190
class DummyMailClient(object):
 
191
 
 
192
    def compose_merge_request(self, *args, **kwargs):
 
193
        self.args = args
 
194
        self.kwargs = kwargs
 
195
 
 
196
 
 
197
class DefaultMailDummyClient(mail_client.DefaultMail):
 
198
 
 
199
    def __init__(self):
 
200
        self.client = DummyMailClient()
 
201
 
 
202
    def _mail_client(self):
 
203
        return self.client
 
204
 
 
205
 
 
206
class TestDefaultMail(tests.TestCase):
 
207
 
 
208
    def test_compose_merge_request(self):
 
209
        client = DefaultMailDummyClient()
 
210
        to = "a@b.com"
 
211
        subject = "[MERGE]"
 
212
        directive = "directive",
 
213
        basename = "merge"
 
214
        client.compose_merge_request(to, subject, directive,
 
215
                                     basename=basename)
 
216
        dummy_client = client.client
 
217
        self.assertEqual(dummy_client.args, (to, subject, directive))
 
218
        self.assertEqual(dummy_client.kwargs, {"basename":basename})