/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: 2010-05-05 00:05:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5206.
  • Revision ID: robertc@robertcollins.net-20100505000529-ltmllyms5watqj5u
Make 'pydoc bzrlib.tests.build_tree_shape' useful.

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
 
from .. import (
 
17
import urllib
 
18
 
 
19
from bzrlib import (
18
20
    errors,
19
21
    mail_client,
20
22
    tests,
22
24
    osutils,
23
25
    )
24
26
 
25
 
 
26
27
class TestMutt(tests.TestCase):
27
28
 
28
29
    def test_commandline(self):
32
33
        # The temporary filename is randomly generated, so it is not matched.
33
34
        self.assertEqual(['-a', 'file%', '-i'], commandline[:-1])
34
35
        commandline = mutt._get_compose_commandline('jrandom@example.org',
35
 
                                                    'Hi there!', None)
 
36
                                                     'Hi there!', None)
36
37
        self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
37
38
                         commandline)
38
39
 
39
40
    def test_commandline_is_8bit(self):
40
41
        mutt = mail_client.Mutt(None)
41
42
        cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
42
 
                                                u'Hi there!', u'file%')
 
43
            u'Hi there!', u'file%')
43
44
        self.assertEqual(
44
45
            ['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
45
46
            cmdline)
46
47
        for item in cmdline:
47
 
            self.assertTrue(isinstance(item, str),
48
 
                            'Command-line item %r is not a native string!' % item)
 
48
            self.assertFalse(isinstance(item, unicode),
 
49
                'Command-line item %r is unicode!' % item)
49
50
 
50
51
 
51
52
class TestThunderbird(tests.TestCase):
62
63
        self.assertEqual(['-compose', "body=bo%27dy,"
63
64
                                      "subject='Hi there!',"
64
65
                                      "to='jrandom@example.org'"],
65
 
                         commandline)
 
66
                                      commandline)
66
67
 
67
68
    def test_commandline_is_8bit(self):
68
69
        # test for bug #139318
69
70
        tbird = mail_client.Thunderbird(None)
70
71
        cmdline = tbird._get_compose_commandline(u'jrandom@example.org',
71
 
                                                 u'Hi there!', u'file%')
 
72
            u'Hi there!', u'file%')
72
73
        self.assertEqual(['-compose',
73
 
                          ("attachment='%s'," %
74
 
                           urlutils.local_path_to_url('file%'))
75
 
                          + "subject='Hi there!',to='jrandom@example.org'",
76
 
                          ], cmdline)
 
74
            ("attachment='%s'," % urlutils.local_path_to_url('file%')) +
 
75
            "subject='Hi there!',to='jrandom@example.org'",
 
76
            ], cmdline)
77
77
        for item in cmdline:
78
 
            self.assertTrue(isinstance(item, str),
79
 
                            'Command-line item %r is not a native string!' % item)
 
78
            self.assertFalse(isinstance(item, unicode),
 
79
                'Command-line item %r is unicode!' % 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.assertTrue(isinstance(item, str),
116
 
                            'Command-line item %r is not a native string!' % item)
 
115
            self.assertFalse(isinstance(item, unicode),
 
116
                'Command-line item %r is unicode!' % 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(mail_client.NoMailAddressSpecified,
 
123
        self.assertRaises(errors.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.assertTrue(isinstance(item, str),
145
 
                            'Command-line item %r is not a native string!' % item)
 
144
            self.assertFalse(isinstance(item, unicode),
 
145
                'Command-line item %r is unicode!' % 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.assertTrue(isinstance(item, str),
169
 
                            'Command-line item %r is not a native string!' % item)
 
168
            self.assertFalse(isinstance(item, unicode),
 
169
                'Command-line item %r is unicode!' % 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.assertTrue(isinstance(item, str),
192
 
                            'Command-line item %r is not a native string!' % item)
 
191
            self.assertFalse(isinstance(item, unicode),
 
192
                'Command-line item %r is unicode!' % 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 = urlutils.quote(
 
215
        subject_string = urllib.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.assertTrue(isinstance(item, str),
225
 
                            'Command-line item %r is not a native string!' % item)
 
224
            self.assertFalse(isinstance(item, unicode),
 
225
                'Command-line item %r is unicode!' % 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(mail_client.NoMailAddressSpecified,
 
238
        self.assertRaises(errors.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', b'qux\xff')
 
263
        editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')
264
264
 
265
265
 
266
266
class DummyMailClient(object):