262
262
self.assertEqual(dummy_client.args, (to, subject, directive))
263
263
self.assertEqual(dummy_client.kwargs,
264
264
{"basename": basename, 'body': None})
267
class TestHook(object):
268
def __init__(self, result=None):
272
def __call__(self, params):
273
self.calls.append(params)
277
class HookMailClient(mail_client.MailClient):
279
def __init__(self, config):
283
def compose(self, prompt, to, subject, attachment, mime_subtype,
284
extension, basename=None, body=None):
288
class TestBodyHook(tests.TestCase):
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')
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)
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)