/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: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

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