~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
from bzrlib import (
 
18
    mail_client,
 
19
    tests,
 
20
    urlutils,
 
21
    )
 
22
 
 
23
 
 
24
class TestThunderbird(tests.TestCase):
 
25
 
 
26
    def test_commandline(self):
 
27
        tbird = mail_client.Thunderbird(None)
 
28
        commandline = tbird._get_compose_commandline(None, None,
 
29
                                                     'file%')
 
30
        self.assertEqual(['-compose', "attachment='%s'" %
 
31
                          urlutils.local_path_to_url('file%')], commandline)
 
32
        commandline = tbird._get_compose_commandline('jrandom@example.org',
 
33
                                                     'Hi there!', None)
 
34
        self.assertEqual(['-compose', "subject='Hi there!',"
 
35
                                      "to='jrandom@example.org'"], commandline)
 
36
 
 
37
 
 
38
class TestXDGEmail(tests.TestCase):
 
39
 
 
40
    def test_commandline(self):
 
41
        xdg_email = mail_client.XDGEmail(None)
 
42
        commandline = xdg_email._get_compose_commandline(None, None,
 
43
                                                         'file%')
 
44
        self.assertEqual([None, '--attach', 'file%'], commandline)
 
45
        commandline = xdg_email._get_compose_commandline(
 
46
            'jrandom@example.org', 'Hi there!', None)
 
47
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
 
48
                         commandline)
 
49
 
 
50
 
 
51
class TestEvolution(tests.TestCase):
 
52
 
 
53
    def test_commandline(self):
 
54
        evo = mail_client.Evolution(None)
 
55
        commandline = evo._get_compose_commandline(None, None, 'file%')
 
56
        self.assertEqual(['mailto:?attach=file%25'], commandline)
 
57
        commandline = evo._get_compose_commandline('jrandom@example.org',
 
58
                                                   'Hi there!', None)
 
59
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
 
60
                         commandline)
 
61
 
 
62
 
 
63
class TestKMail(tests.TestCase):
 
64
 
 
65
    def test_commandline(self):
 
66
        kmail = mail_client.KMail(None)
 
67
        commandline = kmail._get_compose_commandline(None, None, 'file%')
 
68
        self.assertEqual(['--attach', 'file%'], commandline)
 
69
        commandline = kmail._get_compose_commandline('jrandom@example.org',
 
70
                                                     'Hi there!', None)
 
71
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
 
72
                         commandline)
 
73
 
 
74
 
 
75
class TestEditor(tests.TestCase):
 
76
 
 
77
    def test_get_merge_prompt_unicode(self):
 
78
        """Prompt, to and subject are unicode, the attachement is binary"""
 
79
        editor = mail_client.Editor(None)
 
80
        prompt = editor._get_merge_prompt(u'foo\u1234',
 
81
                                        u'bar\u1234',
 
82
                                        u'baz\u1234',
 
83
                                        u'qux\u1234'.encode('utf-8'))
 
84
        self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
 
85
                              u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
 
86
        editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')