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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
19
from bzrlib import (
24
27
class TestMutt(tests.TestCase):
26
29
def test_commandline(self):
27
30
mutt = mail_client.Mutt(None)
28
commandline = mutt._get_compose_commandline(None, None, 'file%')
29
self.assertEqual(['-a', 'file%'], commandline)
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])
30
35
commandline = mutt._get_compose_commandline('jrandom@example.org',
32
self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
37
self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
35
40
def test_commandline_is_8bit(self):
37
42
cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
38
43
u'Hi there!', u'file%')
40
['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
45
['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
42
47
for item in cmdline:
43
48
self.assertFalse(isinstance(item, unicode),
53
58
self.assertEqual(['-compose', "attachment='%s'" %
54
59
urlutils.local_path_to_url('file%')], commandline)
55
60
commandline = tbird._get_compose_commandline('jrandom@example.org',
57
self.assertEqual(['-compose', "subject='Hi there!',"
58
"to='jrandom@example.org'"], commandline)
63
self.assertEqual(['-compose', "body=bo%27dy,"
64
"subject='Hi there!',"
65
"to='jrandom@example.org'"],
60
68
def test_commandline_is_8bit(self):
61
69
# test for bug #139318
89
97
# We won't be able to know the temporary file name at this stage
90
98
# so we can't raise an assertion with assertEqual
91
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)
92
102
commandline = ' '.join(cmdline)
93
103
self.assertContainsRe(commandline, '--eval')
94
104
self.assertContainsRe(commandline, '(compose-mail nil nil)')
99
109
eclient = mail_client.EmacsMail(None)
100
110
commandline = eclient._get_compose_commandline(u'jrandom@example.org',
101
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)
102
114
for item in commandline:
103
115
self.assertFalse(isinstance(item, unicode),
104
116
'Command-line item %r is unicode!' % item)
116
128
self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
118
130
commandline = xdg_email._get_compose_commandline(
119
'jrandom@example.org', 'Hi there!', None)
120
self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
131
'jrandom@example.org', 'Hi there!', None, "bo'dy")
132
self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
133
'--body', "bo'dy"], commandline)
123
135
def test_commandline_is_8bit(self):
124
136
xdg_email = mail_client.XDGEmail(None)
140
152
commandline = evo._get_compose_commandline(None, None, 'file%')
141
153
self.assertEqual(['mailto:?attach=file%25'], commandline)
142
154
commandline = evo._get_compose_commandline('jrandom@example.org',
144
self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
155
'Hi there!', None, 'bo&dy')
156
self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
157
'subject=Hi%20there%21'], commandline)
147
159
def test_commandline_is_8bit(self):
148
160
evo = mail_client.Evolution(None)
180
192
'Command-line item %r is unicode!' % item)
195
class TestClaws(tests.TestCase):
197
def test_commandline(self):
198
claws = mail_client.Claws(None)
199
commandline = claws._get_compose_commandline(
200
'jrandom@example.org', None, 'file%')
202
['--compose', 'mailto:jrandom@example.org?', '--attach', 'file%'],
204
commandline = claws._get_compose_commandline(
205
'jrandom@example.org', 'Hi there!', None)
208
'mailto:jrandom@example.org?subject=Hi%20there%21'],
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'))
219
'mailto:jrandom@example.org?subject=%s' % subject_string,
224
self.assertFalse(isinstance(item, unicode),
225
'Command-line item %r is unicode!' % item)
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')
233
'mailto:jrandom@example.org?from=qrandom%40example.com'],
236
def test_to_required(self):
237
claws = mail_client.Claws(None)
238
self.assertRaises(errors.NoMailAddressSpecified,
239
claws._get_compose_commandline,
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')
248
'mailto:jrandom@example.org?body=This%20is%20some%20body%20text'],
183
252
class TestEditor(tests.TestCase):
185
254
def test_get_merge_prompt_unicode(self):
222
291
basename=basename)
223
292
dummy_client = client.client
224
293
self.assertEqual(dummy_client.args, (to, subject, directive))
225
self.assertEqual(dummy_client.kwargs, {"basename":basename})
294
self.assertEqual(dummy_client.kwargs,
295
{"basename": basename, 'body': None})