/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2681.1.8 by Aaron Bentley
Add Thunderbird support to bzr send
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 (
3042.1.2 by Lukáš Lalinský
Don't use None as address in TestXDGEmail and add a test to check if it raises NoMailAddressSpecified with None.
18
    errors,
2681.1.8 by Aaron Bentley
Add Thunderbird support to bzr send
19
    mail_client,
20
    tests,
21
    urlutils,
22
    )
23
2790.2.1 by Keir Mierle
Add Mutt as a supported client email program. Also rearranges various listings
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
3234.2.6 by Alexander Belchenko
because every mail client has different rules to compose command line we should encode arguments to 8 bit string only when needed.
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
2681.1.8 by Aaron Bentley
Add Thunderbird support to bzr send
46
47
class TestThunderbird(tests.TestCase):
48
49
    def test_commandline(self):
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
50
        tbird = mail_client.Thunderbird(None)
2681.1.8 by Aaron Bentley
Add Thunderbird support to bzr send
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)
2681.2.1 by Lukáš Lalinsky
Support for Evolution mail client.
59
3234.2.3 by Alexander Belchenko
mail_client.py: provide new private method ExternalMailClient._get_compose_8bit_commandline to make bug #139318 testable (as Aaron requested).
60
    def test_commandline_is_8bit(self):
61
        # test for bug #139318
62
        tbird = mail_client.Thunderbird(None)
3234.2.6 by Alexander Belchenko
because every mail client has different rules to compose command line we should encode arguments to 8 bit string only when needed.
63
        cmdline = tbird._get_compose_commandline(u'jrandom@example.org',
64
            u'Hi there!', u'file%')
65
        self.assertEqual(['-compose',
3234.2.3 by Alexander Belchenko
mail_client.py: provide new private method ExternalMailClient._get_compose_8bit_commandline to make bug #139318 testable (as Aaron requested).
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
2681.2.1 by Lukáš Lalinsky
Support for Evolution mail client.
73
3324.4.1 by Xavier Maillard
Replace mail-mode call with compose-mail from GNU Emacs.
74
class TestEmacsMail(tests.TestCase):
3302.6.1 by Xavier Maillard
Add mail-mode GNU Emacs mail package as a mail_client option.
75
76
    def test_commandline(self):
3324.4.1 by Xavier Maillard
Replace mail-mode call with compose-mail from GNU Emacs.
77
        eclient = mail_client.EmacsMail(None)
78
79
        commandline = eclient._get_compose_commandline(None, 'Hi there!', None)
80
        self.assertEqual(['--eval', '(compose-mail nil "Hi there!")'],
81
                         commandline)
3302.6.1 by Xavier Maillard
Add mail-mode GNU Emacs mail package as a mail_client option.
82
83
        commandline = eclient._get_compose_commandline('jrandom@example.org',
3324.4.1 by Xavier Maillard
Replace mail-mode call with compose-mail from GNU Emacs.
84
                                                       'Hi there!', None)
85
        self.assertEqual(['--eval',
86
                          '(compose-mail "jrandom@example.org" "Hi there!")'],
87
                         commandline)
88
89
        # We won't be able to know the temporary file name at this stage
90
        # so we can't raise an assertion with assertEqual
91
        cmdline = eclient._get_compose_commandline(None, None, 'file%')
92
        commandline = ' '.join(cmdline)
93
        self.assertContainsRe(commandline, '--eval')
94
        self.assertContainsRe(commandline, '(compose-mail nil nil)')
95
        self.assertContainsRe(commandline, '(load .*)')
96
        self.assertContainsRe(commandline, '(bzr-add-mime-att \"file%\")')
3302.6.1 by Xavier Maillard
Add mail-mode GNU Emacs mail package as a mail_client option.
97
98
    def test_commandline_is_8bit(self):
3324.4.1 by Xavier Maillard
Replace mail-mode call with compose-mail from GNU Emacs.
99
        eclient = mail_client.EmacsMail(None)
3302.6.1 by Xavier Maillard
Add mail-mode GNU Emacs mail package as a mail_client option.
100
        commandline = eclient._get_compose_commandline(u'jrandom@example.org',
101
            u'Hi there!', u'file%')
102
        for item in commandline:
103
            self.assertFalse(isinstance(item, unicode),
104
                'Command-line item %r is unicode!' % item)
105
106
2681.1.23 by Aaron Bentley
Add support for xdg-email
107
class TestXDGEmail(tests.TestCase):
108
109
    def test_commandline(self):
110
        xdg_email = mail_client.XDGEmail(None)
3042.1.2 by Lukáš Lalinský
Don't use None as address in TestXDGEmail and add a test to check if it raises NoMailAddressSpecified with None.
111
        self.assertRaises(errors.NoMailAddressSpecified,
112
                          xdg_email._get_compose_commandline,
113
                          None, None, 'file%')
114
        commandline = xdg_email._get_compose_commandline(
115
            'jrandom@example.org', None, 'file%')
116
        self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
117
                         commandline)
2681.1.23 by Aaron Bentley
Add support for xdg-email
118
        commandline = xdg_email._get_compose_commandline(
119
            'jrandom@example.org', 'Hi there!', None)
120
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
121
                         commandline)
122
3234.2.6 by Alexander Belchenko
because every mail client has different rules to compose command line we should encode arguments to 8 bit string only when needed.
123
    def test_commandline_is_8bit(self):
124
        xdg_email = mail_client.XDGEmail(None)
125
        cmdline = xdg_email._get_compose_commandline(u'jrandom@example.org',
126
            u'Hi there!', u'file%')
127
        self.assertEqual(
128
            ['jrandom@example.org', '--subject', 'Hi there!',
129
             '--attach', 'file%'],
130
            cmdline)
131
        for item in cmdline:
132
            self.assertFalse(isinstance(item, unicode),
133
                'Command-line item %r is unicode!' % item)
134
2681.1.23 by Aaron Bentley
Add support for xdg-email
135
2681.2.1 by Lukáš Lalinsky
Support for Evolution mail client.
136
class TestEvolution(tests.TestCase):
137
138
    def test_commandline(self):
139
        evo = mail_client.Evolution(None)
140
        commandline = evo._get_compose_commandline(None, None, 'file%')
2681.1.18 by Aaron Bentley
Refactor to increase code sharing, allow multiple command names for tbird
141
        self.assertEqual(['mailto:?attach=file%25'], commandline)
2681.2.1 by Lukáš Lalinsky
Support for Evolution mail client.
142
        commandline = evo._get_compose_commandline('jrandom@example.org',
143
                                                   'Hi there!', None)
2681.1.18 by Aaron Bentley
Refactor to increase code sharing, allow multiple command names for tbird
144
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
2681.2.1 by Lukáš Lalinsky
Support for Evolution mail client.
145
                         commandline)
2681.1.21 by Aaron Bentley
Refactor prompt generation to make it testable, test it with unicode
146
3234.2.6 by Alexander Belchenko
because every mail client has different rules to compose command line we should encode arguments to 8 bit string only when needed.
147
    def test_commandline_is_8bit(self):
148
        evo = mail_client.Evolution(None)
149
        cmdline = evo._get_compose_commandline(u'jrandom@example.org',
150
            u'Hi there!', u'file%')
151
        self.assertEqual(
152
            ['mailto:jrandom@example.org?attach=file%25&subject=Hi%20there%21'
153
            ],
154
            cmdline)
155
        for item in cmdline:
156
            self.assertFalse(isinstance(item, unicode),
157
                'Command-line item %r is unicode!' % item)
158
2681.1.21 by Aaron Bentley
Refactor prompt generation to make it testable, test it with unicode
159
2681.5.2 by ghigo
update docs and tests
160
class TestKMail(tests.TestCase):
161
162
    def test_commandline(self):
2681.1.35 by Aaron Bentley
Rename test var evo => kmail
163
        kmail = mail_client.KMail(None)
164
        commandline = kmail._get_compose_commandline(None, None, 'file%')
2681.5.2 by ghigo
update docs and tests
165
        self.assertEqual(['--attach', 'file%'], commandline)
2681.1.35 by Aaron Bentley
Rename test var evo => kmail
166
        commandline = kmail._get_compose_commandline('jrandom@example.org',
167
                                                     'Hi there!', None)
2681.5.2 by ghigo
update docs and tests
168
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
169
                         commandline)
170
3234.2.6 by Alexander Belchenko
because every mail client has different rules to compose command line we should encode arguments to 8 bit string only when needed.
171
    def test_commandline_is_8bit(self):
172
        kmail = mail_client.KMail(None)
173
        cmdline = kmail._get_compose_commandline(u'jrandom@example.org',
174
            u'Hi there!', u'file%')
175
        self.assertEqual(
176
            ['-s', 'Hi there!', '--attach', 'file%', 'jrandom@example.org'],
177
            cmdline)
178
        for item in cmdline:
179
            self.assertFalse(isinstance(item, unicode),
180
                'Command-line item %r is unicode!' % item)
181
2681.5.2 by ghigo
update docs and tests
182
3921.2.3 by Gavin Panella
Tests for the Claws mail client.
183
class TestClaws(tests.TestCase):
184
185
    def test_commandline(self):
186
        claws = mail_client.Claws(None)
3921.2.4 by Gavin Panella
Use the --attach option, and don't specify a From: header.
187
        commandline = claws._get_compose_commandline(
188
            None, None, 'file%')
189
        self.assertEqual(
190
            ['--compose', 'mailto:?', '--attach', 'file%'], commandline)
191
        commandline = claws._get_compose_commandline(
192
            'jrandom@example.org', 'Hi there!', None)
193
        self.assertEqual(
194
            ['--compose',
195
             'mailto:jrandom@example.org?subject=Hi%20there%21'],
3921.2.3 by Gavin Panella
Tests for the Claws mail client.
196
            commandline)
197
198
    def test_commandline_is_8bit(self):
199
        claws = mail_client.Claws(None)
200
        cmdline = claws._get_compose_commandline(
3921.2.7 by Gavin Panella
Use a non-ascii character in test_commandline_is_8bit.
201
            u'jrandom@example.org', u'\xb5cosm of fun!', u'file%')
3921.2.3 by Gavin Panella
Tests for the Claws mail client.
202
        self.assertEqual(
203
            ['--compose',
3921.2.7 by Gavin Panella
Use a non-ascii character in test_commandline_is_8bit.
204
             'mailto:jrandom@example.org?subject=%C2%B5cosm%20of%20fun%21',
3921.2.4 by Gavin Panella
Use the --attach option, and don't specify a From: header.
205
             '--attach',
206
             'file%'],
3921.2.3 by Gavin Panella
Tests for the Claws mail client.
207
            cmdline)
208
        for item in cmdline:
209
            self.assertFalse(isinstance(item, unicode),
210
                'Command-line item %r is unicode!' % item)
211
212
2681.1.21 by Aaron Bentley
Refactor prompt generation to make it testable, test it with unicode
213
class TestEditor(tests.TestCase):
214
215
    def test_get_merge_prompt_unicode(self):
216
        """Prompt, to and subject are unicode, the attachement is binary"""
217
        editor = mail_client.Editor(None)
218
        prompt = editor._get_merge_prompt(u'foo\u1234',
219
                                        u'bar\u1234',
220
                                        u'baz\u1234',
221
                                        u'qux\u1234'.encode('utf-8'))
222
        self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
223
                              u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
224
        editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')
3270.3.2 by James Westby
Add a smoke test to check that the DefaultMail client passes through
225
226
227
class DummyMailClient(object):
228
229
    def compose_merge_request(self, *args, **kwargs):
230
        self.args = args
231
        self.kwargs = kwargs
232
233
234
class DefaultMailDummyClient(mail_client.DefaultMail):
235
236
    def __init__(self):
237
        self.client = DummyMailClient()
238
239
    def _mail_client(self):
240
        return self.client
241
242
243
class TestDefaultMail(tests.TestCase):
244
245
    def test_compose_merge_request(self):
246
        client = DefaultMailDummyClient()
247
        to = "a@b.com"
248
        subject = "[MERGE]"
249
        directive = "directive",
250
        basename = "merge"
251
        client.compose_merge_request(to, subject, directive,
252
                                     basename=basename)
253
        dummy_client = client.client
254
        self.assertEqual(dummy_client.args, (to, subject, directive))
255
        self.assertEqual(dummy_client.kwargs, {"basename":basename})