~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: 2009-08-27 02:27:19 UTC
  • mfrom: (4634.3.19 gc-batching)
  • Revision ID: pqm@pqm.ubuntu.com-20090827022719-bl2yoqhpj3fcfczu
(andrew) Fix #402657: 2a fetch over dumb transport reads one group at
        a time.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import urllib
16
18
 
17
19
from bzrlib import (
18
20
    errors,
19
21
    mail_client,
20
22
    tests,
21
23
    urlutils,
 
24
    osutils,
22
25
    )
23
26
 
24
27
class TestMutt(tests.TestCase):
25
28
 
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',
31
36
                                                     'Hi there!', None)
32
 
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
 
37
        self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
33
38
                         commandline)
34
39
 
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%')
39
44
        self.assertEqual(
40
 
            ['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
 
45
            ['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
41
46
            cmdline)
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',
56
 
                                                     'Hi there!', None)
57
 
        self.assertEqual(['-compose', "subject='Hi there!',"
58
 
                                      "to='jrandom@example.org'"], commandline)
 
61
                                                     'Hi there!', None,
 
62
                                                     "bo'dy")
 
63
        self.assertEqual(['-compose', "body=bo%27dy,"
 
64
                                      "subject='Hi there!',"
 
65
                                      "to='jrandom@example.org'"],
 
66
                                      commandline)
59
67
 
60
68
    def test_commandline_is_8bit(self):
61
69
        # test for bug #139318
116
124
        self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
117
125
                         commandline)
118
126
        commandline = xdg_email._get_compose_commandline(
119
 
            'jrandom@example.org', 'Hi there!', None)
120
 
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
121
 
                         commandline)
 
127
            'jrandom@example.org', 'Hi there!', None, "bo'dy")
 
128
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
 
129
                          '--body', "bo'dy"], commandline)
122
130
 
123
131
    def test_commandline_is_8bit(self):
124
132
        xdg_email = mail_client.XDGEmail(None)
140
148
        commandline = evo._get_compose_commandline(None, None, 'file%')
141
149
        self.assertEqual(['mailto:?attach=file%25'], commandline)
142
150
        commandline = evo._get_compose_commandline('jrandom@example.org',
143
 
                                                   'Hi there!', None)
144
 
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
145
 
                         commandline)
 
151
                                                   'Hi there!', None, 'bo&dy')
 
152
        self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
 
153
                          'subject=Hi%20there%21'], commandline)
146
154
 
147
155
    def test_commandline_is_8bit(self):
148
156
        evo = mail_client.Evolution(None)
180
188
                'Command-line item %r is unicode!' % item)
181
189
 
182
190
 
 
191
class TestClaws(tests.TestCase):
 
192
 
 
193
    def test_commandline(self):
 
194
        claws = mail_client.Claws(None)
 
195
        commandline = claws._get_compose_commandline(
 
196
            'jrandom@example.org', None, 'file%')
 
197
        self.assertEqual(
 
198
            ['--compose', 'mailto:jrandom@example.org?', '--attach', 'file%'],
 
199
            commandline)
 
200
        commandline = claws._get_compose_commandline(
 
201
            'jrandom@example.org', 'Hi there!', None)
 
202
        self.assertEqual(
 
203
            ['--compose',
 
204
             'mailto:jrandom@example.org?subject=Hi%20there%21'],
 
205
            commandline)
 
206
 
 
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'))
 
213
        self.assertEqual(
 
214
            ['--compose',
 
215
             'mailto:jrandom@example.org?subject=%s' % subject_string,
 
216
             '--attach',
 
217
             'file%'],
 
218
            cmdline)
 
219
        for item in cmdline:
 
220
            self.assertFalse(isinstance(item, unicode),
 
221
                'Command-line item %r is unicode!' % item)
 
222
 
 
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')
 
227
        self.assertEqual(
 
228
            ['--compose',
 
229
             'mailto:jrandom@example.org?from=qrandom%40example.com'],
 
230
            cmdline)
 
231
 
 
232
    def test_to_required(self):
 
233
        claws = mail_client.Claws(None)
 
234
        self.assertRaises(errors.NoMailAddressSpecified,
 
235
                          claws._get_compose_commandline,
 
236
                          None, None, 'file%')
 
237
 
 
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')
 
242
        self.assertEqual(
 
243
            ['--compose',
 
244
             'mailto:jrandom@example.org?body=This%20is%20some%20body%20text'],
 
245
            cmdline)
 
246
 
 
247
 
183
248
class TestEditor(tests.TestCase):
184
249
 
185
250
    def test_get_merge_prompt_unicode(self):
222
287
                                     basename=basename)
223
288
        dummy_client = client.client
224
289
        self.assertEqual(dummy_client.args, (to, subject, directive))
225
 
        self.assertEqual(dummy_client.kwargs, {"basename":basename})
 
290
        self.assertEqual(dummy_client.kwargs,
 
291
                         {"basename": basename, 'body': None})