/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 breezy/tests/test_mail_client.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    osutils,
23
23
    )
24
24
 
25
 
 
26
25
class TestMutt(tests.TestCase):
27
26
 
28
27
    def test_commandline(self):
32
31
        # The temporary filename is randomly generated, so it is not matched.
33
32
        self.assertEqual(['-a', 'file%', '-i'], commandline[:-1])
34
33
        commandline = mutt._get_compose_commandline('jrandom@example.org',
35
 
                                                    'Hi there!', None)
 
34
                                                     'Hi there!', None)
36
35
        self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
37
36
                         commandline)
38
37
 
39
38
    def test_commandline_is_8bit(self):
40
39
        mutt = mail_client.Mutt(None)
41
40
        cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
42
 
                                                u'Hi there!', u'file%')
 
41
            u'Hi there!', u'file%')
43
42
        self.assertEqual(
44
43
            ['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
45
44
            cmdline)
46
45
        for item in cmdline:
47
 
            self.assertTrue(isinstance(item, str),
48
 
                            'Command-line item %r is not a native string!' % item)
 
46
            self.assertFalse(isinstance(item, unicode),
 
47
                'Command-line item %r is unicode!' % item)
49
48
 
50
49
 
51
50
class TestThunderbird(tests.TestCase):
62
61
        self.assertEqual(['-compose', "body=bo%27dy,"
63
62
                                      "subject='Hi there!',"
64
63
                                      "to='jrandom@example.org'"],
65
 
                         commandline)
 
64
                                      commandline)
66
65
 
67
66
    def test_commandline_is_8bit(self):
68
67
        # test for bug #139318
69
68
        tbird = mail_client.Thunderbird(None)
70
69
        cmdline = tbird._get_compose_commandline(u'jrandom@example.org',
71
 
                                                 u'Hi there!', u'file%')
 
70
            u'Hi there!', u'file%')
72
71
        self.assertEqual(['-compose',
73
 
                          ("attachment='%s'," %
74
 
                           urlutils.local_path_to_url('file%'))
75
 
                          + "subject='Hi there!',to='jrandom@example.org'",
76
 
                          ], cmdline)
 
72
            ("attachment='%s'," % urlutils.local_path_to_url('file%')) +
 
73
            "subject='Hi there!',to='jrandom@example.org'",
 
74
            ], cmdline)
77
75
        for item in cmdline:
78
 
            self.assertTrue(isinstance(item, str),
79
 
                            'Command-line item %r is not a native string!' % item)
 
76
            self.assertFalse(isinstance(item, unicode),
 
77
                'Command-line item %r is unicode!' % item)
80
78
 
81
79
 
82
80
class TestEmacsMail(tests.TestCase):
108
106
    def test_commandline_is_8bit(self):
109
107
        eclient = mail_client.EmacsMail(None)
110
108
        commandline = eclient._get_compose_commandline(u'jrandom@example.org',
111
 
                                                       u'Hi there!', u'file%')
 
109
            u'Hi there!', u'file%')
112
110
        if eclient.elisp_tmp_file is not None:
113
111
            self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
114
112
        for item in commandline:
115
 
            self.assertTrue(isinstance(item, str),
116
 
                            'Command-line item %r is not a native string!' % item)
 
113
            self.assertFalse(isinstance(item, unicode),
 
114
                'Command-line item %r is unicode!' % item)
117
115
 
118
116
 
119
117
class TestXDGEmail(tests.TestCase):
120
118
 
121
119
    def test_commandline(self):
122
120
        xdg_email = mail_client.XDGEmail(None)
123
 
        self.assertRaises(mail_client.NoMailAddressSpecified,
 
121
        self.assertRaises(errors.NoMailAddressSpecified,
124
122
                          xdg_email._get_compose_commandline,
125
123
                          None, None, 'file%')
126
124
        commandline = xdg_email._get_compose_commandline(
135
133
    def test_commandline_is_8bit(self):
136
134
        xdg_email = mail_client.XDGEmail(None)
137
135
        cmdline = xdg_email._get_compose_commandline(u'jrandom@example.org',
138
 
                                                     u'Hi there!', u'file%')
 
136
            u'Hi there!', u'file%')
139
137
        self.assertEqual(
140
138
            ['jrandom@example.org', '--subject', 'Hi there!',
141
139
             '--attach', 'file%'],
142
140
            cmdline)
143
141
        for item in cmdline:
144
 
            self.assertTrue(isinstance(item, str),
145
 
                            'Command-line item %r is not a native string!' % item)
 
142
            self.assertFalse(isinstance(item, unicode),
 
143
                'Command-line item %r is unicode!' % item)
146
144
 
147
145
 
148
146
class TestEvolution(tests.TestCase):
159
157
    def test_commandline_is_8bit(self):
160
158
        evo = mail_client.Evolution(None)
161
159
        cmdline = evo._get_compose_commandline(u'jrandom@example.org',
162
 
                                               u'Hi there!', u'file%')
 
160
            u'Hi there!', u'file%')
163
161
        self.assertEqual(
164
162
            ['mailto:jrandom@example.org?attach=file%25&subject=Hi%20there%21'
165
 
             ],
 
163
            ],
166
164
            cmdline)
167
165
        for item in cmdline:
168
 
            self.assertTrue(isinstance(item, str),
169
 
                            'Command-line item %r is not a native string!' % item)
 
166
            self.assertFalse(isinstance(item, unicode),
 
167
                'Command-line item %r is unicode!' % item)
170
168
 
171
169
 
172
170
class TestKMail(tests.TestCase):
183
181
    def test_commandline_is_8bit(self):
184
182
        kmail = mail_client.KMail(None)
185
183
        cmdline = kmail._get_compose_commandline(u'jrandom@example.org',
186
 
                                                 u'Hi there!', u'file%')
 
184
            u'Hi there!', u'file%')
187
185
        self.assertEqual(
188
186
            ['-s', 'Hi there!', '--attach', 'file%', 'jrandom@example.org'],
189
187
            cmdline)
190
188
        for item in cmdline:
191
 
            self.assertTrue(isinstance(item, str),
192
 
                            'Command-line item %r is not a native string!' % item)
 
189
            self.assertFalse(isinstance(item, unicode),
 
190
                'Command-line item %r is unicode!' % item)
193
191
 
194
192
 
195
193
class TestClaws(tests.TestCase):
221
219
             'file%'],
222
220
            cmdline)
223
221
        for item in cmdline:
224
 
            self.assertTrue(isinstance(item, str),
225
 
                            'Command-line item %r is not a native string!' % item)
 
222
            self.assertFalse(isinstance(item, unicode),
 
223
                'Command-line item %r is unicode!' % item)
226
224
 
227
225
    def test_with_from(self):
228
226
        claws = mail_client.Claws(None)
235
233
 
236
234
    def test_to_required(self):
237
235
        claws = mail_client.Claws(None)
238
 
        self.assertRaises(mail_client.NoMailAddressSpecified,
 
236
        self.assertRaises(errors.NoMailAddressSpecified,
239
237
                          claws._get_compose_commandline,
240
238
                          None, None, 'file%')
241
239
 
255
253
        """Prompt, to and subject are unicode, the attachement is binary"""
256
254
        editor = mail_client.Editor(None)
257
255
        prompt = editor._get_merge_prompt(u'foo\u1234',
258
 
                                          u'bar\u1234',
259
 
                                          u'baz\u1234',
260
 
                                          u'qux\u1234'.encode('utf-8'))
 
256
                                        u'bar\u1234',
 
257
                                        u'baz\u1234',
 
258
                                        u'qux\u1234'.encode('utf-8'))
261
259
        self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
262
260
                              u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
263
 
        editor._get_merge_prompt(u'foo', u'bar', u'baz', b'qux\xff')
 
261
        editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')
264
262
 
265
263
 
266
264
class DummyMailClient(object):