~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_directive.py

  • Committer: Aaron Bentley
  • Date: 2009-05-11 19:11:14 UTC
  • mto: This revision was merged to the branch mainline in revision 4351.
  • Revision ID: aaron@aaronbentley.com-20090511191114-g0u190bdpfou9bbw
Gracefully handle mail clients that don't support bodies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    mail_client,
23
23
    merge_directive,
24
24
    tests,
 
25
    trace,
25
26
    )
26
27
 
27
28
 
726
727
 
727
728
class TestBodyHook(tests.TestCaseWithTransport):
728
729
 
729
 
    def compose_with_hooks(self, test_hooks):
 
730
    def compose_with_hooks(self, test_hooks, supports_body=True):
730
731
        client = HookMailClient({})
 
732
        client.supports_body = supports_body
731
733
        for test_hook in test_hooks:
732
734
            merge_directive.MergeDirective.hooks.install_named_hook(
733
735
                'merge_request_body', test_hook, 'test')
742
744
            None, tree.branch)
743
745
        return client, directive
744
746
 
 
747
    def test_no_supports_body(self):
 
748
        test_hook = TestHook('foo')
 
749
        old_warn = trace.warning
 
750
        warnings = []
 
751
        def warn(*args):
 
752
            warnings.append(args)
 
753
        trace.warning = warn
 
754
        try:
 
755
            client, directive = self.compose_with_hooks([test_hook],
 
756
                supports_body=False)
 
757
        finally:
 
758
            trace.warning = old_warn
 
759
        self.assertEqual(0, len(test_hook.calls))
 
760
        self.assertEqual(('Cannot run merge_request_body hooks because mail'
 
761
                          ' client %s does not support message bodies.',
 
762
                          'HookMailClient'), warnings[0])
 
763
 
745
764
    def test_body_hook(self):
746
765
        test_hook = TestHook('foo')
747
766
        client, directive = self.compose_with_hooks([test_hook])