/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: 2018-11-18 18:23:32 UTC
  • mto: This revision was merged to the branch mainline in revision 7197.
  • Revision ID: jelmer@jelmer.uk-20181118182332-viz1qvqese2mo9i6
Fix some more Bazaar references.

Show diffs side-by-side

added added

removed removed

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