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
26
class TestMutt(tests.TestCase):
28
def test_commandline(self):
29
mutt = mail_client.Mutt(None)
30
commandline = mutt._get_compose_commandline(
31
None, None, 'file%', body="hello")
32
# The temporary filename is randomly generated, so it is not matched.
33
self.assertEqual(['-a', 'file%', '-i'], commandline[:-1])
34
commandline = mutt._get_compose_commandline('jrandom@example.org',
36
self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
39
def test_commandline_is_8bit(self):
40
mutt = mail_client.Mutt(None)
41
cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
42
u'Hi there!', u'file%')
44
['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
47
self.assertTrue(isinstance(item, str),
48
'Command-line item %r is not a native string!' % item)
51
class TestThunderbird(tests.TestCase):
53
def test_commandline(self):
54
tbird = mail_client.Thunderbird(None)
55
commandline = tbird._get_compose_commandline(None, None,
57
self.assertEqual(['-compose', "attachment='%s'" %
58
urlutils.local_path_to_url('file%')], commandline)
59
commandline = tbird._get_compose_commandline('jrandom@example.org',
62
self.assertEqual(['-compose', "body=bo%27dy,"
63
"subject='Hi there!',"
64
"to='jrandom@example.org'"],
67
def test_commandline_is_8bit(self):
68
# test for bug #139318
69
tbird = mail_client.Thunderbird(None)
70
cmdline = tbird._get_compose_commandline(u'jrandom@example.org',
71
u'Hi there!', u'file%')
72
self.assertEqual(['-compose',
73
("attachment='%s'," % urlutils.local_path_to_url('file%')) +
74
"subject='Hi there!',to='jrandom@example.org'",
77
self.assertTrue(isinstance(item, str),
78
'Command-line item %r is not a native string!' % item)
81
class TestEmacsMail(tests.TestCase):
83
def test_commandline(self):
84
eclient = mail_client.EmacsMail(None)
86
commandline = eclient._get_compose_commandline(None, 'Hi there!', None)
87
self.assertEqual(['--eval', '(compose-mail nil "Hi there!")'],
90
commandline = eclient._get_compose_commandline('jrandom@example.org',
92
self.assertEqual(['--eval',
93
'(compose-mail "jrandom@example.org" "Hi there!")'],
96
# We won't be able to know the temporary file name at this stage
97
# so we can't raise an assertion with assertEqual
98
cmdline = eclient._get_compose_commandline(None, None, 'file%')
99
if eclient.elisp_tmp_file is not None:
100
self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
101
commandline = ' '.join(cmdline)
102
self.assertContainsRe(commandline, '--eval')
103
self.assertContainsRe(commandline, '(compose-mail nil nil)')
104
self.assertContainsRe(commandline, '(load .*)')
105
self.assertContainsRe(commandline, '(bzr-add-mime-att \"file%\")')
107
def test_commandline_is_8bit(self):
108
eclient = mail_client.EmacsMail(None)
109
commandline = eclient._get_compose_commandline(u'jrandom@example.org',
110
u'Hi there!', u'file%')
111
if eclient.elisp_tmp_file is not None:
112
self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
113
for item in commandline:
114
self.assertTrue(isinstance(item, str),
115
'Command-line item %r is not a native string!' % item)
118
class TestXDGEmail(tests.TestCase):
120
def test_commandline(self):
121
xdg_email = mail_client.XDGEmail(None)
122
self.assertRaises(mail_client.NoMailAddressSpecified,
123
xdg_email._get_compose_commandline,
125
commandline = xdg_email._get_compose_commandline(
126
'jrandom@example.org', None, 'file%')
127
self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
129
commandline = xdg_email._get_compose_commandline(
130
'jrandom@example.org', 'Hi there!', None, "bo'dy")
131
self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
132
'--body', "bo'dy"], commandline)
134
def test_commandline_is_8bit(self):
135
xdg_email = mail_client.XDGEmail(None)
136
cmdline = xdg_email._get_compose_commandline(u'jrandom@example.org',
137
u'Hi there!', u'file%')
139
['jrandom@example.org', '--subject', 'Hi there!',
140
'--attach', 'file%'],
143
self.assertTrue(isinstance(item, str),
144
'Command-line item %r is not a native string!' % item)
147
class TestEvolution(tests.TestCase):
149
def test_commandline(self):
150
evo = mail_client.Evolution(None)
151
commandline = evo._get_compose_commandline(None, None, 'file%')
152
self.assertEqual(['mailto:?attach=file%25'], commandline)
153
commandline = evo._get_compose_commandline('jrandom@example.org',
154
'Hi there!', None, 'bo&dy')
155
self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
156
'subject=Hi%20there%21'], commandline)
158
def test_commandline_is_8bit(self):
159
evo = mail_client.Evolution(None)
160
cmdline = evo._get_compose_commandline(u'jrandom@example.org',
161
u'Hi there!', u'file%')
163
['mailto:jrandom@example.org?attach=file%25&subject=Hi%20there%21'
167
self.assertTrue(isinstance(item, str),
168
'Command-line item %r is not a native string!' % item)
171
class TestKMail(tests.TestCase):
173
def test_commandline(self):
174
kmail = mail_client.KMail(None)
175
commandline = kmail._get_compose_commandline(None, None, 'file%')
176
self.assertEqual(['--attach', 'file%'], commandline)
177
commandline = kmail._get_compose_commandline('jrandom@example.org',
179
self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
182
def test_commandline_is_8bit(self):
183
kmail = mail_client.KMail(None)
184
cmdline = kmail._get_compose_commandline(u'jrandom@example.org',
185
u'Hi there!', u'file%')
187
['-s', 'Hi there!', '--attach', 'file%', 'jrandom@example.org'],
190
self.assertTrue(isinstance(item, str),
191
'Command-line item %r is not a native string!' % item)
194
class TestClaws(tests.TestCase):
196
def test_commandline(self):
197
claws = mail_client.Claws(None)
198
commandline = claws._get_compose_commandline(
199
'jrandom@example.org', None, 'file%')
201
['--compose', 'mailto:jrandom@example.org?', '--attach', 'file%'],
203
commandline = claws._get_compose_commandline(
204
'jrandom@example.org', 'Hi there!', None)
207
'mailto:jrandom@example.org?subject=Hi%20there%21'],
210
def test_commandline_is_8bit(self):
211
claws = mail_client.Claws(None)
212
cmdline = claws._get_compose_commandline(
213
u'jrandom@example.org', u'\xb5cosm of fun!', u'file%')
214
subject_string = urlutils.quote(
215
u'\xb5cosm of fun!'.encode(osutils.get_user_encoding(), 'replace'))
218
'mailto:jrandom@example.org?subject=%s' % subject_string,
223
self.assertTrue(isinstance(item, str),
224
'Command-line item %r is not a native string!' % item)
226
def test_with_from(self):
227
claws = mail_client.Claws(None)
228
cmdline = claws._get_compose_commandline(
229
u'jrandom@example.org', None, None, None, u'qrandom@example.com')
232
'mailto:jrandom@example.org?from=qrandom%40example.com'],
235
def test_to_required(self):
236
claws = mail_client.Claws(None)
237
self.assertRaises(mail_client.NoMailAddressSpecified,
238
claws._get_compose_commandline,
241
def test_with_body(self):
242
claws = mail_client.Claws(None)
243
cmdline = claws._get_compose_commandline(
244
u'jrandom@example.org', None, None, 'This is some body text')
247
'mailto:jrandom@example.org?body=This%20is%20some%20body%20text'],
251
class TestEditor(tests.TestCase):
253
def test_get_merge_prompt_unicode(self):
254
"""Prompt, to and subject are unicode, the attachement is binary"""
255
editor = mail_client.Editor(None)
256
prompt = editor._get_merge_prompt(u'foo\u1234',
259
u'qux\u1234'.encode('utf-8'))
260
self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
261
u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
262
editor._get_merge_prompt(u'foo', u'bar', u'baz', b'qux\xff')
265
class DummyMailClient(object):
267
def compose_merge_request(self, *args, **kwargs):
272
class DefaultMailDummyClient(mail_client.DefaultMail):
275
self.client = DummyMailClient()
277
def _mail_client(self):
281
class TestDefaultMail(tests.TestCase):
283
def test_compose_merge_request(self):
284
client = DefaultMailDummyClient()
287
directive = "directive",
289
client.compose_merge_request(to, subject, directive,
291
dummy_client = client.client
292
self.assertEqual(dummy_client.args, (to, subject, directive))
293
self.assertEqual(dummy_client.kwargs,
294
{"basename": basename, 'body': None})