697
698
self.assertEqual('booga', md.patch)
698
699
self.assertEqual('diff', md.patch_type)
699
700
self.assertEqual('Hi mom!', md.message)
703
class TestHook(object):
704
"""Hook callback for test purposes."""
706
def __init__(self, result=None):
710
def __call__(self, params):
711
self.calls.append(params)
715
class HookMailClient(mail_client.MailClient):
716
"""Mail client for testing hooks."""
718
def __init__(self, config):
722
def compose(self, prompt, to, subject, attachment, mime_subtype,
723
extension, basename=None, body=None):
727
class TestBodyHook(tests.TestCaseWithTransport):
729
def compose_with_hooks(self, test_hooks):
730
client = HookMailClient({})
731
for test_hook in test_hooks:
732
merge_directive.MergeDirective.hooks.install_named_hook(
733
'merge_request_body', test_hook, 'test')
734
tree = self.make_branch_and_tree('foo')
736
directive = merge_directive.MergeDirective2(
737
tree.branch.last_revision(), 'sha', 0, 0, 'sha',
738
source_branch=tree.branch.base,
739
base_revision_id=tree.branch.last_revision(),
740
message='This code rox')
741
directive.compose_merge_request(client, 'jrandom@example.com',
743
return client, directive
745
def test_body_hook(self):
746
test_hook = TestHook('foo')
747
client, directive = self.compose_with_hooks([test_hook])
748
self.assertEqual(1, len(test_hook.calls))
749
self.assertEqual('foo', client.body)
750
params = test_hook.calls[0]
751
self.assertIsInstance(params,
752
merge_directive.MergeRequestBodyParams)
753
self.assertIs(None, params.body)
754
self.assertIs(None, params.orig_body)
755
self.assertEqual('jrandom@example.com', params.to)
756
self.assertEqual('[MERGE] This code rox', params.subject)
757
self.assertEqual(directive, params.directive)
758
self.assertEqual('foo-1', params.basename)
760
def test_body_hook_chaining(self):
761
test_hook1 = TestHook('foo')
762
test_hook2 = TestHook('bar')
763
client = self.compose_with_hooks([test_hook1, test_hook2])[0]
764
self.assertEqual(None, test_hook1.calls[0].body)
765
self.assertEqual(None, test_hook1.calls[0].orig_body)
766
self.assertEqual('foo', test_hook2.calls[0].body)
767
self.assertEqual(None, test_hook2.calls[0].orig_body)
768
self.assertEqual('bar', client.body)