~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-23 05:59:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2446.
  • Revision ID: jml@canonical.com-20070423055929-chgdr92da63lhcri
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to
subclass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
from bzrlib import bugtracker
19
 
from bzrlib import errors
 
18
from bzrlib import bugtracker, errors, urlutils
20
19
from bzrlib.tests import TestCaseWithMemoryTransport
21
20
 
22
21
 
155
154
    def setUp(self):
156
155
        TestCaseWithMemoryTransport.setUp(self)
157
156
        self.url = 'http://twistedmatrix.com/trac'
 
157
        self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
 
158
                                                                   'ticket/')
158
159
 
159
160
    def test_get_with_unsupported_tag(self):
160
161
        """If asked for an unrecognized or unconfigured tag, return None."""
161
162
        branch = self.make_branch('some_branch')
162
 
        self.assertEqual(
163
 
            None,
164
 
            bugtracker.URLParametrizedIntegerBugTracker.get('lp', branch))
165
 
        self.assertEqual(
166
 
            None,
167
 
            bugtracker.URLParametrizedIntegerBugTracker.get('twisted', branch))
 
163
        self.assertEqual(None, self.tracker.get('lp', branch))
 
164
        self.assertEqual(None, self.tracker.get('twisted', branch))
168
165
 
169
166
    def test_get_with_supported_tag(self):
170
 
        """If asked for a valid tag, return a matching tracker instance."""
171
 
        class SomeTracker(bugtracker.URLParametrizedIntegerBugTracker):
172
 
            type_name = 'some'
173
 
 
174
 
            def _get_bug_url(self, bug_id):
175
 
                return self._base_url + bug_id
 
167
        """If asked for a valid tag, return a tracker instance that can map bug
 
168
        IDs to <base_url>/<bug_area> + <bug_id>."""
 
169
        bugtracker.tracker_registry.register('some', self.tracker)
 
170
        self.addCleanup(lambda: bugtracker.tracker_registry.remove('some'))
176
171
 
177
172
        branch = self.make_branch('some_branch')
178
173
        config = branch.get_config()
179
174
        config.set_user_option('some_twisted_url', self.url)
180
 
        tracker = SomeTracker.get('twisted', branch)
181
 
        self.assertEqual(tracker.get_bug_url('1234'), self.url + '1234')
 
175
        tracker = self.tracker.get('twisted', branch)
 
176
        self.assertEqual(
 
177
            urlutils.join(self.url, 'ticket/') + '1234',
 
178
            tracker.get_bug_url('1234'))
182
179
 
183
180
    def test_get_bug_url_for_bad_bug(self):
184
181
        """When given a bug identifier that is invalid for Trac, get_bug_url
185
182
        should raise an error.
186
183
        """
187
 
        tracker = bugtracker.URLParametrizedIntegerBugTracker(self.url)
188
184
        self.assertRaises(
189
 
            errors.MalformedBugIdentifier, tracker.get_bug_url, 'bad')
190
 
 
191
 
 
192
 
class TestTracTracker(TestCaseWithMemoryTransport):
193
 
    """Tests for TracTracker."""
194
 
 
195
 
    def test_get_bug_url(self):
196
 
        """A URLParametrizedIntegerBugTracker should map a Trac bug to a URL
197
 
        for that instance.
198
 
        """
199
 
        url = 'http://twistedmatrix.com/trac'
200
 
        tracker = bugtracker.TracTracker(url)
201
 
        self.assertEqual('%s/ticket/1234' % url, tracker.get_bug_url('1234'))
202
 
 
203
 
 
204
 
class TestBugzillaTracker(TestCaseWithMemoryTransport):
205
 
    """Tests for BugzillaTracker."""
206
 
 
207
 
    def setUp(self):
208
 
        TestCaseWithMemoryTransport.setUp(self)
209
 
 
210
 
    def test_get_bug_url(self):
211
 
        """A BugzillaTracker should map a bug id to a URL for that instance."""
212
 
        bugzilla_url = 'http://www.squid-cache.org/bugs'
213
 
        tracker = bugtracker.BugzillaTracker(bugzilla_url)
214
 
        self.assertEqual(
215
 
            '%s/show_bug.cgi?id=1234' % bugzilla_url,
216
 
            tracker.get_bug_url('1234'))
 
185
            errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')