1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
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
27
class TestMutt(tests.TestCase):
29
def test_commandline(self):
30
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])
35
commandline = mutt._get_compose_commandline('jrandom@example.org',
37
self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
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%')
45
['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
48
self.assertFalse(isinstance(item, unicode),
49
'Command-line item %r is unicode!' % item)
52
class TestThunderbird(tests.TestCase):
54
def test_commandline(self):
55
tbird = mail_client.Thunderbird(None)
56
commandline = tbird._get_compose_commandline(None, None,
58
self.assertEqual(['-compose', "attachment='%s'" %
59
urlutils.local_path_to_url('file%')], commandline)
60
commandline = tbird._get_compose_commandline('jrandom@example.org',
63
self.assertEqual(['-compose', "body=bo%27dy,"
64
"subject='Hi there!',"
65
"to='jrandom@example.org'"],
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'",
78
self.assertFalse(isinstance(item, unicode),
79
'Command-line item %r is unicode!' % item)
82
class TestEmacsMail(tests.TestCase):
84
def test_commandline(self):
85
eclient = mail_client.EmacsMail(None)
87
commandline = eclient._get_compose_commandline(None, 'Hi there!', None)
88
self.assertEqual(['--eval', '(compose-mail nil "Hi there!")'],
91
commandline = eclient._get_compose_commandline('jrandom@example.org',
93
self.assertEqual(['--eval',
94
'(compose-mail "jrandom@example.org" "Hi there!")'],
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
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%\")')
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
for item in commandline:
111
self.assertFalse(isinstance(item, unicode),
112
'Command-line item %r is unicode!' % item)
115
class TestXDGEmail(tests.TestCase):
117
def test_commandline(self):
118
xdg_email = mail_client.XDGEmail(None)
119
self.assertRaises(errors.NoMailAddressSpecified,
120
xdg_email._get_compose_commandline,
122
commandline = xdg_email._get_compose_commandline(
123
'jrandom@example.org', None, 'file%')
124
self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
126
commandline = xdg_email._get_compose_commandline(
127
'jrandom@example.org', 'Hi there!', None, "bo'dy")
128
self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
129
'--body', "bo'dy"], commandline)
131
def test_commandline_is_8bit(self):
132
xdg_email = mail_client.XDGEmail(None)
133
cmdline = xdg_email._get_compose_commandline(u'jrandom@example.org',
134
u'Hi there!', u'file%')
136
['jrandom@example.org', '--subject', 'Hi there!',
137
'--attach', 'file%'],
140
self.assertFalse(isinstance(item, unicode),
141
'Command-line item %r is unicode!' % item)
144
class TestEvolution(tests.TestCase):
146
def test_commandline(self):
147
evo = mail_client.Evolution(None)
148
commandline = evo._get_compose_commandline(None, None, 'file%')
149
self.assertEqual(['mailto:?attach=file%25'], commandline)
150
commandline = evo._get_compose_commandline('jrandom@example.org',
151
'Hi there!', None, 'bo&dy')
152
self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
153
'subject=Hi%20there%21'], commandline)
155
def test_commandline_is_8bit(self):
156
evo = mail_client.Evolution(None)
157
cmdline = evo._get_compose_commandline(u'jrandom@example.org',
158
u'Hi there!', u'file%')
160
['mailto:jrandom@example.org?attach=file%25&subject=Hi%20there%21'
164
self.assertFalse(isinstance(item, unicode),
165
'Command-line item %r is unicode!' % item)
168
class TestKMail(tests.TestCase):
170
def test_commandline(self):
171
kmail = mail_client.KMail(None)
172
commandline = kmail._get_compose_commandline(None, None, 'file%')
173
self.assertEqual(['--attach', 'file%'], commandline)
174
commandline = kmail._get_compose_commandline('jrandom@example.org',
176
self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
179
def test_commandline_is_8bit(self):
180
kmail = mail_client.KMail(None)
181
cmdline = kmail._get_compose_commandline(u'jrandom@example.org',
182
u'Hi there!', u'file%')
184
['-s', 'Hi there!', '--attach', 'file%', 'jrandom@example.org'],
187
self.assertFalse(isinstance(item, unicode),
188
'Command-line item %r is unicode!' % item)
191
class TestClaws(tests.TestCase):
193
def test_commandline(self):
194
claws = mail_client.Claws(None)
195
commandline = claws._get_compose_commandline(
196
'jrandom@example.org', None, 'file%')
198
['--compose', 'mailto:jrandom@example.org?', '--attach', 'file%'],
200
commandline = claws._get_compose_commandline(
201
'jrandom@example.org', 'Hi there!', None)
204
'mailto:jrandom@example.org?subject=Hi%20there%21'],
207
def test_commandline_is_8bit(self):
208
claws = mail_client.Claws(None)
209
cmdline = claws._get_compose_commandline(
210
u'jrandom@example.org', u'\xb5cosm of fun!', u'file%')
211
subject_string = urllib.quote(
212
u'\xb5cosm of fun!'.encode(osutils.get_user_encoding(), 'replace'))
215
'mailto:jrandom@example.org?subject=%s' % subject_string,
220
self.assertFalse(isinstance(item, unicode),
221
'Command-line item %r is unicode!' % item)
223
def test_with_from(self):
224
claws = mail_client.Claws(None)
225
cmdline = claws._get_compose_commandline(
226
u'jrandom@example.org', None, None, None, u'qrandom@example.com')
229
'mailto:jrandom@example.org?from=qrandom%40example.com'],
232
def test_to_required(self):
233
claws = mail_client.Claws(None)
234
self.assertRaises(errors.NoMailAddressSpecified,
235
claws._get_compose_commandline,
238
def test_with_body(self):
239
claws = mail_client.Claws(None)
240
cmdline = claws._get_compose_commandline(
241
u'jrandom@example.org', None, None, 'This is some body text')
244
'mailto:jrandom@example.org?body=This%20is%20some%20body%20text'],
248
class TestEditor(tests.TestCase):
250
def test_get_merge_prompt_unicode(self):
251
"""Prompt, to and subject are unicode, the attachement is binary"""
252
editor = mail_client.Editor(None)
253
prompt = editor._get_merge_prompt(u'foo\u1234',
256
u'qux\u1234'.encode('utf-8'))
257
self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
258
u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
259
editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')
262
class DummyMailClient(object):
264
def compose_merge_request(self, *args, **kwargs):
269
class DefaultMailDummyClient(mail_client.DefaultMail):
272
self.client = DummyMailClient()
274
def _mail_client(self):
278
class TestDefaultMail(tests.TestCase):
280
def test_compose_merge_request(self):
281
client = DefaultMailDummyClient()
284
directive = "directive",
286
client.compose_merge_request(to, subject, directive,
288
dummy_client = client.client
289
self.assertEqual(dummy_client.args, (to, subject, directive))
290
self.assertEqual(dummy_client.kwargs,
291
{"basename": basename, 'body': None})