~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 14:01:20 UTC
  • mfrom: (3280.2.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080316140120-i3yq8yr1l66m11h7
Start 1.4 development

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
18
    errors,
21
19
    mail_client,
22
20
    tests,
23
21
    urlutils,
24
 
    osutils,
25
22
    )
26
23
 
27
24
class TestMutt(tests.TestCase):
32
29
        self.assertEqual(['-a', 'file%'], commandline)
33
30
        commandline = mutt._get_compose_commandline('jrandom@example.org',
34
31
                                                     'Hi there!', None)
35
 
        self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
 
32
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
36
33
                         commandline)
37
34
 
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%')
42
39
        self.assertEqual(
43
 
            ['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
 
40
            ['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
44
41
            cmdline)
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',
59
 
                                                     'Hi there!', None,
60
 
                                                     "bo'dy")
61
 
        self.assertEqual(['-compose', "body=bo%27dy,"
62
 
                                      "subject='Hi there!',"
63
 
                                      "to='jrandom@example.org'"],
64
 
                                      commandline)
 
56
                                                     'Hi there!', None)
 
57
        self.assertEqual(['-compose', "subject='Hi there!',"
 
58
                                      "to='jrandom@example.org'"], commandline)
65
59
 
66
60
    def test_commandline_is_8bit(self):
67
61
        # test for bug #139318
77
71
                'Command-line item %r is unicode!' % item)
78
72
 
79
73
 
80
 
class TestEmacsMail(tests.TestCase):
81
 
 
82
 
    def test_commandline(self):
83
 
        eclient = mail_client.EmacsMail(None)
84
 
 
85
 
        commandline = eclient._get_compose_commandline(None, 'Hi there!', None)
86
 
        self.assertEqual(['--eval', '(compose-mail nil "Hi there!")'],
87
 
                         commandline)
88
 
 
89
 
        commandline = eclient._get_compose_commandline('jrandom@example.org',
90
 
                                                       'Hi there!', None)
91
 
        self.assertEqual(['--eval',
92
 
                          '(compose-mail "jrandom@example.org" "Hi there!")'],
93
 
                         commandline)
94
 
 
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%\")')
103
 
 
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)
111
 
 
112
 
 
113
74
class TestXDGEmail(tests.TestCase):
114
75
 
115
76
    def test_commandline(self):
122
83
        self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
123
84
                         commandline)
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!'],
 
88
                         commandline)
128
89
 
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)
 
110
                                                   'Hi there!', None)
 
111
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
 
112
                         commandline)
152
113
 
153
114
    def test_commandline_is_8bit(self):
154
115
        evo = mail_client.Evolution(None)
186
147
                'Command-line item %r is unicode!' % item)
187
148
 
188
149
 
189
 
class TestClaws(tests.TestCase):
190
 
 
191
 
    def test_commandline(self):
192
 
        claws = mail_client.Claws(None)
193
 
        commandline = claws._get_compose_commandline(
194
 
            None, None, 'file%')
195
 
        self.assertEqual(
196
 
            ['--compose', 'mailto:?', '--attach', 'file%'], commandline)
197
 
        commandline = claws._get_compose_commandline(
198
 
            'jrandom@example.org', 'Hi there!', None)
199
 
        self.assertEqual(
200
 
            ['--compose',
201
 
             'mailto:jrandom@example.org?subject=Hi%20there%21'],
202
 
            commandline)
203
 
 
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'))
210
 
        self.assertEqual(
211
 
            ['--compose',
212
 
             'mailto:jrandom@example.org?subject=%s' % subject_string,
213
 
             '--attach',
214
 
             'file%'],
215
 
            cmdline)
216
 
        for item in cmdline:
217
 
            self.assertFalse(isinstance(item, unicode),
218
 
                'Command-line item %r is unicode!' % item)
219
 
 
220
 
 
221
150
class TestEditor(tests.TestCase):
222
151
 
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')
233
 
 
234
 
 
235
 
class DummyMailClient(object):
236
 
 
237
 
    def compose_merge_request(self, *args, **kwargs):
238
 
        self.args = args
239
 
        self.kwargs = kwargs
240
 
 
241
 
 
242
 
class DefaultMailDummyClient(mail_client.DefaultMail):
243
 
 
244
 
    def __init__(self):
245
 
        self.client = DummyMailClient()
246
 
 
247
 
    def _mail_client(self):
248
 
        return self.client
249
 
 
250
 
 
251
 
class TestDefaultMail(tests.TestCase):
252
 
 
253
 
    def test_compose_merge_request(self):
254
 
        client = DefaultMailDummyClient()
255
 
        to = "a@b.com"
256
 
        subject = "[MERGE]"
257
 
        directive = "directive",
258
 
        basename = "merge"
259
 
        client.compose_merge_request(to, subject, directive,
260
 
                                     basename=basename)
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})