/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

  • Committer: Andrew Bennetts
  • Date: 2008-08-12 14:53:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3624.
  • Revision ID: andrew.bennetts@canonical.com-20080812145326-yx693x2jc4rcovb7
Move the notes on writing tests out of HACKING into a new file, and improve
them.

Many of the testing notes in the HACKING file were in duplicated in two places
in that file!  This change removes that duplication.  It also adds new sections
on “Where should I put a new test?” and “TestCase and its subclasses”, and
others like “Test feature dependencies” have been expanded.  The whole document
has generally been edited to be a bit more coherent. 

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):
28
25
 
29
26
    def test_commandline(self):
30
27
        mutt = mail_client.Mutt(None)
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])
 
28
        commandline = mutt._get_compose_commandline(None, None, 'file%')
 
29
        self.assertEqual(['-a', 'file%'], commandline)
35
30
        commandline = mutt._get_compose_commandline('jrandom@example.org',
36
31
                                                     'Hi there!', None)
37
 
        self.assertEqual(['-s', 'Hi there!', '--', 'jrandom@example.org'],
 
32
        self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
38
33
                         commandline)
39
34
 
40
35
    def test_commandline_is_8bit(self):
42
37
        cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
43
38
            u'Hi there!', u'file%')
44
39
        self.assertEqual(
45
 
            ['-s', 'Hi there!', '-a', 'file%', '--', 'jrandom@example.org'],
 
40
            ['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
46
41
            cmdline)
47
42
        for item in cmdline:
48
43
            self.assertFalse(isinstance(item, unicode),
58
53
        self.assertEqual(['-compose', "attachment='%s'" %
59
54
                          urlutils.local_path_to_url('file%')], commandline)
60
55
        commandline = tbird._get_compose_commandline('jrandom@example.org',
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)
 
56
                                                     'Hi there!', None)
 
57
        self.assertEqual(['-compose', "subject='Hi there!',"
 
58
                                      "to='jrandom@example.org'"], commandline)
67
59
 
68
60
    def test_commandline_is_8bit(self):
69
61
        # test for bug #139318
97
89
        # We won't be able to know the temporary file name at this stage
98
90
        # so we can't raise an assertion with assertEqual
99
91
        cmdline = eclient._get_compose_commandline(None, None, 'file%')
100
 
        if eclient.elisp_tmp_file is not None:
101
 
            self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
102
92
        commandline = ' '.join(cmdline)
103
93
        self.assertContainsRe(commandline, '--eval')
104
94
        self.assertContainsRe(commandline, '(compose-mail nil nil)')
109
99
        eclient = mail_client.EmacsMail(None)
110
100
        commandline = eclient._get_compose_commandline(u'jrandom@example.org',
111
101
            u'Hi there!', u'file%')
112
 
        if eclient.elisp_tmp_file is not None:
113
 
            self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
114
102
        for item in commandline:
115
103
            self.assertFalse(isinstance(item, unicode),
116
104
                'Command-line item %r is unicode!' % item)
128
116
        self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
129
117
                         commandline)
130
118
        commandline = xdg_email._get_compose_commandline(
131
 
            'jrandom@example.org', 'Hi there!', None, "bo'dy")
132
 
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!',
133
 
                          '--body', "bo'dy"], commandline)
 
119
            'jrandom@example.org', 'Hi there!', None)
 
120
        self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
 
121
                         commandline)
134
122
 
135
123
    def test_commandline_is_8bit(self):
136
124
        xdg_email = mail_client.XDGEmail(None)
152
140
        commandline = evo._get_compose_commandline(None, None, 'file%')
153
141
        self.assertEqual(['mailto:?attach=file%25'], commandline)
154
142
        commandline = evo._get_compose_commandline('jrandom@example.org',
155
 
                                                   'Hi there!', None, 'bo&dy')
156
 
        self.assertEqual(['mailto:jrandom@example.org?body=bo%26dy&'
157
 
                          'subject=Hi%20there%21'], commandline)
 
143
                                                   'Hi there!', None)
 
144
        self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
 
145
                         commandline)
158
146
 
159
147
    def test_commandline_is_8bit(self):
160
148
        evo = mail_client.Evolution(None)
192
180
                'Command-line item %r is unicode!' % item)
193
181
 
194
182
 
195
 
class TestClaws(tests.TestCase):
196
 
 
197
 
    def test_commandline(self):
198
 
        claws = mail_client.Claws(None)
199
 
        commandline = claws._get_compose_commandline(
200
 
            'jrandom@example.org', None, 'file%')
201
 
        self.assertEqual(
202
 
            ['--compose', 'mailto:jrandom@example.org?', '--attach', 'file%'],
203
 
            commandline)
204
 
        commandline = claws._get_compose_commandline(
205
 
            'jrandom@example.org', 'Hi there!', None)
206
 
        self.assertEqual(
207
 
            ['--compose',
208
 
             'mailto:jrandom@example.org?subject=Hi%20there%21'],
209
 
            commandline)
210
 
 
211
 
    def test_commandline_is_8bit(self):
212
 
        claws = mail_client.Claws(None)
213
 
        cmdline = claws._get_compose_commandline(
214
 
            u'jrandom@example.org', u'\xb5cosm of fun!', u'file%')
215
 
        subject_string = urllib.quote(
216
 
            u'\xb5cosm of fun!'.encode(osutils.get_user_encoding(), 'replace'))
217
 
        self.assertEqual(
218
 
            ['--compose',
219
 
             'mailto:jrandom@example.org?subject=%s' % subject_string,
220
 
             '--attach',
221
 
             'file%'],
222
 
            cmdline)
223
 
        for item in cmdline:
224
 
            self.assertFalse(isinstance(item, unicode),
225
 
                'Command-line item %r is unicode!' % item)
226
 
 
227
 
    def test_with_from(self):
228
 
        claws = mail_client.Claws(None)
229
 
        cmdline = claws._get_compose_commandline(
230
 
            u'jrandom@example.org', None, None, None, u'qrandom@example.com')
231
 
        self.assertEqual(
232
 
            ['--compose',
233
 
             'mailto:jrandom@example.org?from=qrandom%40example.com'],
234
 
            cmdline)
235
 
 
236
 
    def test_to_required(self):
237
 
        claws = mail_client.Claws(None)
238
 
        self.assertRaises(errors.NoMailAddressSpecified,
239
 
                          claws._get_compose_commandline,
240
 
                          None, None, 'file%')
241
 
 
242
 
    def test_with_body(self):
243
 
        claws = mail_client.Claws(None)
244
 
        cmdline = claws._get_compose_commandline(
245
 
            u'jrandom@example.org', None, None, 'This is some body text')
246
 
        self.assertEqual(
247
 
            ['--compose',
248
 
             'mailto:jrandom@example.org?body=This%20is%20some%20body%20text'],
249
 
            cmdline)
250
 
 
251
 
 
252
183
class TestEditor(tests.TestCase):
253
184
 
254
185
    def test_get_merge_prompt_unicode(self):
291
222
                                     basename=basename)
292
223
        dummy_client = client.client
293
224
        self.assertEqual(dummy_client.args, (to, subject, directive))
294
 
        self.assertEqual(dummy_client.kwargs,
295
 
                         {"basename": basename, 'body': None})
 
225
        self.assertEqual(dummy_client.kwargs, {"basename":basename})