~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_mail_client.py

  • Committer: Aaron Bentley
  • Date: 2009-05-11 18:35:20 UTC
  • mto: This revision was merged to the branch mainline in revision 4351.
  • Revision ID: aaron@aaronbentley.com-20090511183520-xtvepoauy7zjtb7x
Move hook to MergeDirective, implement MergeDirective.compose_merge_request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
262
262
        self.assertEqual(dummy_client.args, (to, subject, directive))
263
263
        self.assertEqual(dummy_client.kwargs,
264
264
                         {"basename": basename, 'body': None})
265
 
 
266
 
 
267
 
class TestHook(object):
268
 
    def __init__(self, result=None):
269
 
        self.calls = []
270
 
        self.result = result
271
 
 
272
 
    def __call__(self, params):
273
 
        self.calls.append(params)
274
 
        return self.result
275
 
 
276
 
 
277
 
class HookMailClient(mail_client.MailClient):
278
 
 
279
 
    def __init__(self, config):
280
 
        self.body = None
281
 
        self.config = config
282
 
 
283
 
    def compose(self, prompt, to, subject, attachment, mime_subtype,
284
 
                extension, basename=None, body=None):
285
 
        self.body = body
286
 
 
287
 
 
288
 
class TestBodyHook(tests.TestCase):
289
 
 
290
 
    def compose_with_hooks(self, test_hooks):
291
 
        for test_hook in test_hooks:
292
 
            mail_client.MailClient.hooks.install_named_hook(
293
 
                'merge_request_body', test_hook, 'test')
294
 
            client = HookMailClient({})
295
 
            client.compose_merge_request('jrandom@example.com',
296
 
                'This code rox', {}, 'basename')
297
 
        return client
298
 
 
299
 
    def test_body_hook(self):
300
 
        test_hook = TestHook('foo')
301
 
        client = self.compose_with_hooks([test_hook])
302
 
        self.assertEqual(1, len(test_hook.calls))
303
 
        self.assertEqual('foo', client.body)
304
 
        params = test_hook.calls[0]
305
 
        self.assertIsInstance(params,
306
 
                              mail_client.MergeRequestBodyParams)
307
 
        self.assertIs(None, params.body)
308
 
        self.assertIs(None, params.orig_body)
309
 
        self.assertEqual('jrandom@example.com', params.to)
310
 
        self.assertEqual('This code rox', params.subject)
311
 
        self.assertEqual({}, params.directive)
312
 
        self.assertEqual('basename', params.basename)
313
 
 
314
 
    def test_body_hook_chaining(self):
315
 
        test_hook1 = TestHook('foo')
316
 
        test_hook2 = TestHook('bar')
317
 
        client = self.compose_with_hooks([test_hook1, test_hook2])
318
 
        self.assertEqual(None, test_hook1.calls[0].body)
319
 
        self.assertEqual(None, test_hook1.calls[0].orig_body)
320
 
        self.assertEqual('foo', test_hook2.calls[0].body)
321
 
        self.assertEqual(None, test_hook2.calls[0].orig_body)
322
 
        self.assertEqual('bar', client.body)