~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bugtracker.py

  • Committer: Jonathan Lange
  • Date: 2007-04-20 03:10:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2446.
  • Revision ID: jml@canonical.com-20070420031049-kwt6hkq8qdlgtm3z
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
class TestGetBugURL(TestCaseWithMemoryTransport):
24
24
    """Tests for bugtracker.get_bug_url"""
25
25
 
26
 
    def test_get_launchpad_url(self):
27
 
        """No matter the branch, lp:1234 should map to a Launchpad URL."""
 
26
    class TransientTracker(object):
 
27
        """An transient tracker used for testing."""
 
28
 
 
29
        @classmethod
 
30
        def get(klass, abbreviation, branch):
 
31
            klass.log.append(('get', abbreviation, branch))
 
32
            if abbreviation != 'transient':
 
33
                return None
 
34
            return klass()
 
35
 
 
36
        def get_bug_url(self, bug_id):
 
37
            self.log.append(('get_bug_url', bug_id))
 
38
            return "http://bugs.com/%s" % bug_id
 
39
 
 
40
    def setUp(self):
 
41
        TestCaseWithMemoryTransport.setUp(self)
 
42
        self.tracker_type = TestGetBugURL.TransientTracker
 
43
        self.tracker_type.log = []
 
44
        bugtracker.tracker_registry.register('transient', self.tracker_type)
 
45
        self.addCleanup(lambda:
 
46
                        bugtracker.tracker_registry.remove('transient'))
 
47
 
 
48
    def test_get_bug_url_for_transient_tracker(self):
28
49
        branch = self.make_branch('some_branch')
 
50
        self.assertEqual('http://bugs.com/1234',
 
51
                         bugtracker.get_bug_url('transient', branch, '1234'))
29
52
        self.assertEqual(
30
 
            'https://launchpad.net/bugs/1234',
31
 
            bugtracker.get_bug_url('lp', branch, '1234'))
32
 
 
33
 
    def test_get_trac_url(self):
34
 
        trac_url = 'http://twistedmatrix.com/trac'
35
 
        branch = self.make_branch('some_branch')
36
 
        config = branch.get_config()
37
 
        config.set_user_option('trac_twisted_url', trac_url)
38
 
        self.assertEqual('%s/ticket/1234' % trac_url,
39
 
                         bugtracker.get_bug_url('twisted', branch, '1234'))
40
 
 
41
 
    def test_unrecognized_abbreviation(self):
42
 
        """If the abbreviation is unrecognized, then raise a KeyError."""
 
53
            [('get', 'transient', branch), ('get_bug_url', '1234')],
 
54
            self.tracker_type.log)
 
55
 
 
56
    def test_unrecognized_abbreviation_raises_error(self):
 
57
        """If the abbreviation is unrecognized, then raise an error."""
43
58
        branch = self.make_branch('some_branch')
44
59
        self.assertRaises(errors.UnknownBugTrackerAbbreviation,
45
60
                          bugtracker.get_bug_url, 'xxx', branch, '1234')
 
61
        self.assertEqual([('get', 'xxx', branch)], self.tracker_type.log)
46
62
 
47
63
 
48
64
class TestUniqueBugTracker(TestCaseWithMemoryTransport):
60
76
        self.assertEqual('http://bugs.com/red', tracker.get_bug_url('red'))
61
77
 
62
78
    def test_returns_tracker_if_abbreviation_matches(self):
63
 
        """The get() classmethod should return an instance of the tracker if
64
 
        the given abbreviation matches the tracker's abbreviated name.
 
79
        """The get() method should return an instance of the tracker if the
 
80
        given abbreviation matches the tracker's abbreviated name.
65
81
        """
66
82
        tracker = bugtracker.UniqueBugTracker('xxx', 'http://bugs.com')
67
83
        branch = self.make_branch('some_branch')
68
84
        self.assertIs(tracker, tracker.get('xxx', branch))
69
85
 
70
86
    def test_returns_none_if_abbreviation_doesnt_match(self):
71
 
        """The get() classmethod should return None if the given abbreviated
72
 
        name doesn't match the tracker's abbreviation.
 
87
        """The get() method should return None if the given abbreviated name
 
88
        doesn't match the tracker's abbreviation.
73
89
        """
74
90
        tracker = bugtracker.UniqueBugTracker('xxx', 'http://bugs.com')
75
91
        branch = self.make_branch('some_branch')
76
 
        self.assertEqual(None, tracker.get('yyy', branch))
 
92
        self.assertIs(None, tracker.get('yyy', branch))
 
93
 
 
94
    def test_doesnt_consult_branch(self):
 
95
        """A UniqueBugTracker shouldn't consult the branch for tracker
 
96
        information.
 
97
        """
 
98
        tracker = bugtracker.UniqueBugTracker('xxx', 'http://bugs.com')
 
99
        self.assertIs(tracker, tracker.get('xxx', None))
 
100
        self.assertIs(None, tracker.get('yyy', None))
77
101
 
78
102
 
79
103
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
80
104
 
81
105
    def test_check_bug_id_only_accepts_integers(self):
82
 
        """An UniqueIntegerBugTracker only accepts integers as bug IDs."""
83
 
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
84
 
        self.assertEqual(None, tracker.check_bug_id('1234'))
 
106
        """A UniqueIntegerBugTracker accepts integers as bug IDs."""
 
107
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
 
108
        tracker.check_bug_id('1234')
 
109
 
 
110
    def test_check_bug_id_doesnt_accept_non_integers(self):
 
111
        """A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
 
112
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
85
113
        self.assertRaises(
86
114
            errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')
87
115