~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 14:01:20 UTC
  • mfrom: (3280.2.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080316140120-i3yq8yr1l66m11h7
Start 1.4 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib import (
18
18
    errors,
19
19
    mail_client,
20
20
    tests,
21
21
    urlutils,
22
 
    osutils,
23
22
    )
24
23
 
25
24
class TestMutt(tests.TestCase):
26
25
 
27
26
    def test_commandline(self):
28
27
        mutt = mail_client.Mutt(None)
29
 
        commandline = mutt._get_compose_commandline(
30
 
            None, None, 'file%', body="hello")
31
 
        # The temporary filename is randomly generated, so it is not matched.
32
 
        self.assertEqual(['-a', 'file%', '-i'], commandline[:-1])
 
28
        commandline = mutt._get_compose_commandline(None, None, 'file%')
 
29
        self.assertEqual(['-a', 'file%'], commandline)
33
30
        commandline = mutt._get_compose_commandline('jrandom@example.org',
34
31
                                                     'Hi there!', None)
35
 
        self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
 
32
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
36
33
                         commandline)
37
34
 
38
35
    def test_commandline_is_8bit(self):
40
37
        cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
41
38
            u'Hi there!', u'file%')
42
39
        self.assertEqual(
43
 
            ['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
 
40
            ['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
44
41
            cmdline)
45
42
        for item in cmdline:
46
43
            self.assertFalse(isinstance(item, unicode),
56
53
        self.assertEqual(['-compose', "attachment='%s'" %
57
54
                          urlutils.local_path_to_url('file%')], commandline)
58
55
        commandline = tbird._get_compose_commandline('jrandom@example.org',
59
 
                                                     'Hi there!', None,
60
 
                                                     "bo'dy")
61
 
        self.assertEqual(['-compose', "body=bo%27dy,"
62
 
                                      "subject='Hi there!',"
63
 
                                      "to='jrandom@example.org'"],
64
 
                                      commandline)
 
56
                                                     'Hi there!', None)
 
57
        self.assertEqual(['-compose', "subject='Hi there!',"
 
58
                                      "to='jrandom@example.org'"], commandline)
65
59
 
66
60
    def test_commandline_is_8bit(self):
67
61
        # test for bug #139318
77
71
                'Command-line item %r is unicode!' % item)
78
72
 
79
73
 
80
 
class TestEmacsMail(tests.TestCase):
81
 
 
82
 
    def test_commandline(self):
83
 
        eclient = mail_client.EmacsMail(None)
84
 
 
85
 
        commandline = eclient._get_compose_commandline(None, 'Hi there!', None)
86
 
        self.assertEqual(['--eval', '(compose-mail nil "Hi there!")'],
87
 
                         commandline)
88
 
 
89
 
        commandline = eclient._get_compose_commandline('jrandom@example.org',
90
 
                                                       'Hi there!', None)
91
 
        self.assertEqual(['--eval',
92
 
                          '(compose-mail "jrandom@example.org" "Hi there!")'],
93
 
                         commandline)
94
 
 
95
 
        # We won't be able to know the temporary file name at this stage
96
 
        # so we can't raise an assertion with assertEqual
97
 
        cmdline = eclient._get_compose_commandline(None, None, 'file%')
98
 
        if eclient.elisp_tmp_file is not None:
99
 
            self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
100
 
        commandline = ' '.join(cmdline)
101
 
        self.assertContainsRe(commandline, '--eval')
102
 
        self.assertContainsRe(commandline, '(compose-mail nil nil)')
103
 
        self.assertContainsRe(commandline, '(load .*)')
104
 
        self.assertContainsRe(commandline, '(bzr-add-mime-att \"file%\")')
105
 
 
106
 
    def test_commandline_is_8bit(self):
107
 
        eclient = mail_client.EmacsMail(None)
108
 
        commandline = eclient._get_compose_commandline(u'jrandom@example.org',
109
 
            u'Hi there!', u'file%')
110
 
        if eclient.elisp_tmp_file is not None:
111
 
            self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
112
 
        for item in commandline:
113
 
            self.assertFalse(isinstance(item, unicode),
114
 
                'Command-line item %r is unicode!' % item)
115
 
 
116
 
 
117
74
class TestXDGEmail(tests.TestCase):
118
75
 
119
76
    def test_commandline(self):
126
83
        self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
127
84
                         commandline)
128
85
        commandline = xdg_email._get_compose_commandline(
129
 
            'jrandom@example.org', 'Hi there!', None, "bo'dy")
130
 
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
131
 
                          '--body', "bo'dy"], commandline)
 
86
            'jrandom@example.org', 'Hi there!', None)
 
87
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
 
88
                         commandline)
132
89
 
133
90
    def test_commandline_is_8bit(self):
134
91
        xdg_email = mail_client.XDGEmail(None)
150
107
        commandline = evo._get_compose_commandline(None, None, 'file%')
151
108
        self.assertEqual(['mailto:?attach=file%25'], commandline)
152
109
        commandline = evo._get_compose_commandline('jrandom@example.org',
153
 
                                                   'Hi there!', None, 'bo&dy')
154
 
        self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
155
 
                          'subject=Hi%20there%21'], commandline)
 
110
                                                   'Hi there!', None)
 
111
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
 
112
                         commandline)
156
113
 
157
114
    def test_commandline_is_8bit(self):
158
115
        evo = mail_client.Evolution(None)
190
147
                'Command-line item %r is unicode!' % item)
191
148
 
192
149
 
193
 
class TestClaws(tests.TestCase):
194
 
 
195
 
    def test_commandline(self):
196
 
        claws = mail_client.Claws(None)
197
 
        commandline = claws._get_compose_commandline(
198
 
            'jrandom@example.org', None, 'file%')
199
 
        self.assertEqual(
200
 
            ['--compose', 'mailto:jrandom@example.org?', '--attach', 'file%'],
201
 
            commandline)
202
 
        commandline = claws._get_compose_commandline(
203
 
            'jrandom@example.org', 'Hi there!', None)
204
 
        self.assertEqual(
205
 
            ['--compose',
206
 
             'mailto:jrandom@example.org?subject=Hi%20there%21'],
207
 
            commandline)
208
 
 
209
 
    def test_commandline_is_8bit(self):
210
 
        claws = mail_client.Claws(None)
211
 
        cmdline = claws._get_compose_commandline(
212
 
            u'jrandom@example.org', u'\xb5cosm of fun!', u'file%')
213
 
        subject_string = urlutils.quote(
214
 
            u'\xb5cosm of fun!'.encode(osutils.get_user_encoding(), 'replace'))
215
 
        self.assertEqual(
216
 
            ['--compose',
217
 
             'mailto:jrandom@example.org?subject=%s' % subject_string,
218
 
             '--attach',
219
 
             'file%'],
220
 
            cmdline)
221
 
        for item in cmdline:
222
 
            self.assertFalse(isinstance(item, unicode),
223
 
                'Command-line item %r is unicode!' % item)
224
 
 
225
 
    def test_with_from(self):
226
 
        claws = mail_client.Claws(None)
227
 
        cmdline = claws._get_compose_commandline(
228
 
            u'jrandom@example.org', None, None, None, u'qrandom@example.com')
229
 
        self.assertEqual(
230
 
            ['--compose',
231
 
             'mailto:jrandom@example.org?from=qrandom%40example.com'],
232
 
            cmdline)
233
 
 
234
 
    def test_to_required(self):
235
 
        claws = mail_client.Claws(None)
236
 
        self.assertRaises(errors.NoMailAddressSpecified,
237
 
                          claws._get_compose_commandline,
238
 
                          None, None, 'file%')
239
 
 
240
 
    def test_with_body(self):
241
 
        claws = mail_client.Claws(None)
242
 
        cmdline = claws._get_compose_commandline(
243
 
            u'jrandom@example.org', None, None, 'This is some body text')
244
 
        self.assertEqual(
245
 
            ['--compose',
246
 
             'mailto:jrandom@example.org?body=This%20is%20some%20body%20text'],
247
 
            cmdline)
248
 
 
249
 
 
250
150
class TestEditor(tests.TestCase):
251
151
 
252
152
    def test_get_merge_prompt_unicode(self):
259
159
        self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
260
160
                              u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
261
161
        editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')
262
 
 
263
 
 
264
 
class DummyMailClient(object):
265
 
 
266
 
    def compose_merge_request(self, *args, **kwargs):
267
 
        self.args = args
268
 
        self.kwargs = kwargs
269
 
 
270
 
 
271
 
class DefaultMailDummyClient(mail_client.DefaultMail):
272
 
 
273
 
    def __init__(self):
274
 
        self.client = DummyMailClient()
275
 
 
276
 
    def _mail_client(self):
277
 
        return self.client
278
 
 
279
 
 
280
 
class TestDefaultMail(tests.TestCase):
281
 
 
282
 
    def test_compose_merge_request(self):
283
 
        client = DefaultMailDummyClient()
284
 
        to = "a@b.com"
285
 
        subject = "[MERGE]"
286
 
        directive = "directive",
287
 
        basename = "merge"
288
 
        client.compose_merge_request(to, subject, directive,
289
 
                                     basename=basename)
290
 
        dummy_client = client.client
291
 
        self.assertEqual(dummy_client.args, (to, subject, directive))
292
 
        self.assertEqual(dummy_client.kwargs,
293
 
                         {"basename": basename, 'body': None})