~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bugtracker.py

  • Committer: Robert Collins
  • Date: 2007-07-14 09:35:31 UTC
  • mto: (2592.3.23 repository)
  • mto: This revision was merged to the branch mainline in revision 2634.
  • Revision ID: robertc@robertcollins.net-20070714093531-n1kt1ch73qxhfw8i
Add a new transport decorator unlistable+ for testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
from bzrlib import bugtracker, errors, urlutils
19
 
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
 
19
from bzrlib.tests import TestCaseWithMemoryTransport
20
20
 
21
21
 
22
22
class TestGetBugURL(TestCaseWithMemoryTransport):
81
81
        self.assertEqual('http://bugs.debian.org/1234',
82
82
                         tracker.get_bug_url('1234'))
83
83
 
84
 
    def test_gnome_registered(self):
85
 
        branch = self.make_branch('some_branch')
86
 
        tracker = bugtracker.tracker_registry.get_tracker('gnome', branch)
87
 
        self.assertEqual('http://bugzilla.gnome.org/show_bug.cgi?id=1234',
88
 
                         tracker.get_bug_url('1234'))
89
 
 
90
84
    def test_trac_registered(self):
91
85
        """The Trac bug tracker should be registered by default and generate
92
86
        Trac bug page URLs when the appropriate configuration is present.
110
104
        self.assertEqual('http://bugs.com/show_bug.cgi?id=1234',
111
105
                         tracker.get_bug_url('1234'))
112
106
 
113
 
    def test_generic_registered(self):
114
 
        branch = self.make_branch('some_branch')
115
 
        config = branch.get_config()
116
 
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
117
 
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
118
 
        self.assertEqual('http://bugs.com/1234/view.html',
119
 
                         tracker.get_bug_url('1234'))
120
 
 
121
 
    def test_generic_incorrect_url(self):
122
 
        branch = self.make_branch('some_branch')
123
 
        config = branch.get_config()
124
 
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/view.html')
125
 
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
126
 
        self.assertRaises(errors.InvalidBugTrackerURL, tracker.get_bug_url, '1234')
127
 
 
128
107
 
129
108
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
130
109
 
131
 
    def test_appends_id_to_base_url(self):
 
110
    def test_joins_id_to_base_url(self):
132
111
        """The URL of a bug is the base URL joined to the identifier."""
133
 
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
134
 
                'http://bugs.com/foo')
135
 
        self.assertEqual('http://bugs.com/foo1234', tracker.get_bug_url('1234'))
 
112
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
 
113
        self.assertEqual('http://bugs.com/1234', tracker.get_bug_url('1234'))
136
114
 
137
115
    def test_returns_tracker_if_abbreviation_matches(self):
138
116
        """The get() method should return an instance of the tracker if the
139
117
        given abbreviation matches the tracker's abbreviated name.
140
118
        """
141
 
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
142
 
                'http://bugs.com/')
 
119
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
143
120
        branch = self.make_branch('some_branch')
144
121
        self.assertIs(tracker, tracker.get('xxx', branch))
145
122
 
147
124
        """The get() method should return None if the given abbreviated name
148
125
        doesn't match the tracker's abbreviation.
149
126
        """
150
 
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
151
 
                'http://bugs.com/')
 
127
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
152
128
        branch = self.make_branch('some_branch')
153
129
        self.assertIs(None, tracker.get('yyy', branch))
154
130
 
156
132
        """A UniqueIntegerBugTracker shouldn't consult the branch for tracker
157
133
        information.
158
134
        """
159
 
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
160
 
                'http://bugs.com/')
 
135
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
161
136
        self.assertIs(tracker, tracker.get('xxx', None))
162
137
        self.assertIs(None, tracker.get('yyy', None))
163
138
 
164
139
    def test_check_bug_id_only_accepts_integers(self):
165
140
        """A UniqueIntegerBugTracker accepts integers as bug IDs."""
166
 
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
167
 
                'http://bugs.com/')
 
141
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
168
142
        tracker.check_bug_id('1234')
169
143
 
170
144
    def test_check_bug_id_doesnt_accept_non_integers(self):
171
145
        """A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
172
 
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
173
 
                'http://bugs.com/')
 
146
        tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
174
147
        self.assertRaises(
175
148
            errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')
176
149
 
210
183
        """
211
184
        self.assertRaises(
212
185
            errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
213
 
 
214
 
 
215
 
class TestPropertyEncoding(TestCase):
216
 
    """Tests for how the bug URLs are encoded as revision properties."""
217
 
 
218
 
    def test_encoding_one(self):
219
 
        self.assertEqual(
220
 
            'http://example.com/bugs/1 fixed',
221
 
            bugtracker.encode_fixes_bug_urls(['http://example.com/bugs/1']))
222
 
 
223
 
    def test_encoding_zero(self):
224
 
        self.assertEqual('', bugtracker.encode_fixes_bug_urls([]))
225
 
 
226
 
    def test_encoding_two(self):
227
 
        self.assertEqual(
228
 
            'http://example.com/bugs/1 fixed\n'
229
 
            'http://example.com/bugs/2 fixed',
230
 
            bugtracker.encode_fixes_bug_urls(
231
 
                ['http://example.com/bugs/1', 'http://example.com/bugs/2']))