~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-27 05:35:00 UTC
  • mfrom: (4570 +trunk)
  • mto: (4634.6.29 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090727053500-q76zsn2dx33jhmj5
Merge bzr.dev.

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
16
 
17
17
import urllib
18
18
 
28
28
 
29
29
    def test_commandline(self):
30
30
        mutt = mail_client.Mutt(None)
31
 
        commandline = mutt._get_compose_commandline(None, None, 'file%')
32
 
        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])
33
35
        commandline = mutt._get_compose_commandline('jrandom@example.org',
34
36
                                                     'Hi there!', None)
35
 
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
 
37
        self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
36
38
                         commandline)
37
39
 
38
40
    def test_commandline_is_8bit(self):
40
42
        cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
41
43
            u'Hi there!', u'file%')
42
44
        self.assertEqual(
43
 
            ['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
 
45
            ['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
44
46
            cmdline)
45
47
        for item in cmdline:
46
48
            self.assertFalse(isinstance(item, unicode),
56
58
        self.assertEqual(['-compose', "attachment='%s'" %
57
59
                          urlutils.local_path_to_url('file%')], commandline)
58
60
        commandline = tbird._get_compose_commandline('jrandom@example.org',
59
 
                                                     'Hi there!', None)
60
 
        self.assertEqual(['-compose', "subject='Hi there!',"
61
 
                                      "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)
62
67
 
63
68
    def test_commandline_is_8bit(self):
64
69
        # test for bug #139318
119
124
        self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
120
125
                         commandline)
121
126
        commandline = xdg_email._get_compose_commandline(
122
 
            'jrandom@example.org', 'Hi there!', None)
123
 
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
124
 
                         commandline)
 
127
            'jrandom@example.org', 'Hi there!', None, "bo'dy")
 
128
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
 
129
                          '--body', "bo'dy"], commandline)
125
130
 
126
131
    def test_commandline_is_8bit(self):
127
132
        xdg_email = mail_client.XDGEmail(None)
143
148
        commandline = evo._get_compose_commandline(None, None, 'file%')
144
149
        self.assertEqual(['mailto:?attach=file%25'], commandline)
145
150
        commandline = evo._get_compose_commandline('jrandom@example.org',
146
 
                                                   'Hi there!', None)
147
 
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
148
 
                         commandline)
 
151
                                                   'Hi there!', None, 'bo&dy')
 
152
        self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
 
153
                          'subject=Hi%20there%21'], commandline)
149
154
 
150
155
    def test_commandline_is_8bit(self):
151
156
        evo = mail_client.Evolution(None)
188
193
    def test_commandline(self):
189
194
        claws = mail_client.Claws(None)
190
195
        commandline = claws._get_compose_commandline(
191
 
            None, None, 'file%')
 
196
            'jrandom@example.org', None, 'file%')
192
197
        self.assertEqual(
193
 
            ['--compose', 'mailto:?', '--attach', 'file%'], commandline)
 
198
            ['--compose', 'mailto:jrandom@example.org?', '--attach', 'file%'],
 
199
            commandline)
194
200
        commandline = claws._get_compose_commandline(
195
201
            'jrandom@example.org', 'Hi there!', None)
196
202
        self.assertEqual(
214
220
            self.assertFalse(isinstance(item, unicode),
215
221
                'Command-line item %r is unicode!' % item)
216
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
 
217
247
 
218
248
class TestEditor(tests.TestCase):
219
249
 
257
287
                                     basename=basename)
258
288
        dummy_client = client.client
259
289
        self.assertEqual(dummy_client.args, (to, subject, directive))
260
 
        self.assertEqual(dummy_client.kwargs, {"basename":basename})
 
290
        self.assertEqual(dummy_client.kwargs,
 
291
                         {"basename": basename, 'body': None})