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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
17
from bzrlib import (
27
24
class TestMutt(tests.TestCase):
32
29
self.assertEqual(['-a', 'file%'], commandline)
33
30
commandline = mutt._get_compose_commandline('jrandom@example.org',
35
self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
32
self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
38
35
def test_commandline_is_8bit(self):
40
37
cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
41
38
u'Hi there!', u'file%')
43
['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
40
['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
45
42
for item in cmdline:
46
43
self.assertFalse(isinstance(item, unicode),
56
53
self.assertEqual(['-compose', "attachment='%s'" %
57
54
urlutils.local_path_to_url('file%')], commandline)
58
55
commandline = tbird._get_compose_commandline('jrandom@example.org',
61
self.assertEqual(['-compose', "body=bo%27dy,"
62
"subject='Hi there!',"
63
"to='jrandom@example.org'"],
57
self.assertEqual(['-compose', "subject='Hi there!',"
58
"to='jrandom@example.org'"], commandline)
66
60
def test_commandline_is_8bit(self):
67
61
# test for bug #139318
77
71
'Command-line item %r is unicode!' % item)
80
class TestEmacsMail(tests.TestCase):
82
def test_commandline(self):
83
eclient = mail_client.EmacsMail(None)
85
commandline = eclient._get_compose_commandline(None, 'Hi there!', None)
86
self.assertEqual(['--eval', '(compose-mail nil "Hi there!")'],
89
commandline = eclient._get_compose_commandline('jrandom@example.org',
91
self.assertEqual(['--eval',
92
'(compose-mail "jrandom@example.org" "Hi there!")'],
95
# We won't be able to know the temporary file name at this stage
96
# so we can't raise an assertion with assertEqual
97
cmdline = eclient._get_compose_commandline(None, None, 'file%')
98
commandline = ' '.join(cmdline)
99
self.assertContainsRe(commandline, '--eval')
100
self.assertContainsRe(commandline, '(compose-mail nil nil)')
101
self.assertContainsRe(commandline, '(load .*)')
102
self.assertContainsRe(commandline, '(bzr-add-mime-att \"file%\")')
104
def test_commandline_is_8bit(self):
105
eclient = mail_client.EmacsMail(None)
106
commandline = eclient._get_compose_commandline(u'jrandom@example.org',
107
u'Hi there!', u'file%')
108
for item in commandline:
109
self.assertFalse(isinstance(item, unicode),
110
'Command-line item %r is unicode!' % item)
113
74
class TestXDGEmail(tests.TestCase):
115
76
def test_commandline(self):
122
83
self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
124
85
commandline = xdg_email._get_compose_commandline(
125
'jrandom@example.org', 'Hi there!', None, "bo'dy")
126
self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
127
'--body', "bo'dy"], commandline)
86
'jrandom@example.org', 'Hi there!', None)
87
self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
129
90
def test_commandline_is_8bit(self):
130
91
xdg_email = mail_client.XDGEmail(None)
146
107
commandline = evo._get_compose_commandline(None, None, 'file%')
147
108
self.assertEqual(['mailto:?attach=file%25'], commandline)
148
109
commandline = evo._get_compose_commandline('jrandom@example.org',
149
'Hi there!', None, 'bo&dy')
150
self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
151
'subject=Hi%20there%21'], commandline)
111
self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
153
114
def test_commandline_is_8bit(self):
154
115
evo = mail_client.Evolution(None)
186
147
'Command-line item %r is unicode!' % item)
189
class TestClaws(tests.TestCase):
191
def test_commandline(self):
192
claws = mail_client.Claws(None)
193
commandline = claws._get_compose_commandline(
196
['--compose', 'mailto:?', '--attach', 'file%'], commandline)
197
commandline = claws._get_compose_commandline(
198
'jrandom@example.org', 'Hi there!', None)
201
'mailto:jrandom@example.org?subject=Hi%20there%21'],
204
def test_commandline_is_8bit(self):
205
claws = mail_client.Claws(None)
206
cmdline = claws._get_compose_commandline(
207
u'jrandom@example.org', u'\xb5cosm of fun!', u'file%')
208
subject_string = urllib.quote(
209
u'\xb5cosm of fun!'.encode(osutils.get_user_encoding(), 'replace'))
212
'mailto:jrandom@example.org?subject=%s' % subject_string,
217
self.assertFalse(isinstance(item, unicode),
218
'Command-line item %r is unicode!' % item)
221
150
class TestEditor(tests.TestCase):
223
152
def test_get_merge_prompt_unicode(self):
230
159
self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
231
160
u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
232
161
editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')
235
class DummyMailClient(object):
237
def compose_merge_request(self, *args, **kwargs):
242
class DefaultMailDummyClient(mail_client.DefaultMail):
245
self.client = DummyMailClient()
247
def _mail_client(self):
251
class TestDefaultMail(tests.TestCase):
253
def test_compose_merge_request(self):
254
client = DefaultMailDummyClient()
257
directive = "directive",
259
client.compose_merge_request(to, subject, directive,
261
dummy_client = client.client
262
self.assertEqual(dummy_client.args, (to, subject, directive))
263
self.assertEqual(dummy_client.kwargs,
264
{"basename": basename, 'body': None})