1
# -*- coding: utf-8 -*-
3
# QBzr - Qt frontend to Bazaar commands
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
from bzrlib import config
20
from bzrlib.tests import TestCase, TestCaseWithTransport
22
from bzrlib.plugins.qbzr.lib.bugs import (
28
get_user_bug_trackers_tags,
32
class TestGetBugId(TestCase):
34
def test_launchpad(self):
35
self.assertEquals('261234', get_bug_id('https://launchpad.net/bugs/261234'))
38
self.assertEquals('3852', get_bug_id('http://bugs.musicbrainz.org/ticket/3852'))
40
def test_bugzilla(self):
41
self.assertEquals('169104', get_bug_id('http://bugs.kde.org/show_bug.cgi?id=169104'))
43
def test_redmine(self):
44
self.assertEquals('1832', get_bug_id('http://www.redmine.org/issues/show/1832'))
46
def test_fogbugz(self):
47
self.assertEquals('1234', get_bug_id('http://test.fogbugz.com/default.asp?1234'))
49
def test_roundup(self):
50
self.assertEquals('5243', get_bug_id('http://bugs.python.org/issue5243'))
52
def test_mantis(self):
53
self.assertEquals('7721', get_bug_id('http://www.mantisbt.org/bugs/view.php?id=7721'))
54
self.assertEquals('123', get_bug_id('http://localhost/view.php?id=123'))
57
class TestGetBugTags(TestCase):
59
def test_get_user_bug_trackers_tags(self):
60
self.assertEqual({}, get_user_bug_trackers_tags([]))
61
self.assertEquals({'foo': 'bugtracker',
64
get_user_bug_trackers_tags([
72
def test_get_unique_bug_tags(self):
73
self.assertEqual({'lp': 'unique',
76
}, get_unique_bug_tags())
79
class TestGetBugTagsFromConfig(TestCaseWithTransport):
81
def test_get_global_bug_tags(self):
82
# check empty bazaar.conf
83
self.assertEqual({}, get_global_bug_tags())
85
cfg = config.GlobalConfig()
86
cfg.set_user_option('bugtracker_py_url',
87
'http://bugs.python.org/issue{id}')
88
cfg.set_user_option('bugzilla_kde_url',
89
'http://bugs.kde.org/')
90
cfg.set_user_option('trac_mbz_url',
91
'http://bugs.musicbrainz.org/ticket/')
96
get_global_bug_tags())
98
def test_get_branch_bug_tags(self):
99
wt = self.make_branch_and_tree('.')
101
# check empty branch.conf
102
self.assertEqual({}, get_branch_bug_tags(branch))
104
cfg = branch.get_config()
105
cfg.set_user_option('bugtracker_py_url',
106
'http://bugs.python.org/issue{id}')
107
cfg.set_user_option('bugzilla_kde_url',
108
'http://bugs.kde.org/')
109
cfg.set_user_option('trac_mbz_url',
110
'http://bugs.musicbrainz.org/ticket/')
115
get_branch_bug_tags(branch))
118
class TestBugUrlsToIds(TestCaseWithTransport):
120
def test_wo_branch(self):
122
'https://launchpad.net/bugs/261234 fixed',
123
'http://bugs.python.org/issue5243 fixed',
125
# w/o global options we can match only unique lp url
126
self.assertEqual(['lp:261234'], bug_urls_to_ids(bug_urls))
128
cfg = config.GlobalConfig()
129
cfg.set_user_option('bugtracker_py_url',
130
'http://bugs.python.org/issue{id}')
131
cfg.set_user_option('bugzilla_kde_url',
132
'http://bugs.kde.org/')
133
cfg.set_user_option('trac_mbz_url',
134
'http://bugs.musicbrainz.org/')
135
self.assertEqual(['lp:261234', 'py:5243'], bug_urls_to_ids(bug_urls))
137
def test_w_branch(self):
139
'https://launchpad.net/bugs/261234 fixed',
140
'http://bugs.python.org/issue5243 fixed',
141
'http://bugs.kde.org/show_bug.cgi?id=169104 fixed',
143
wt = self.make_branch_and_tree('.')
145
# w/o user settings we can match only unique lp url
146
self.assertEqual(['lp:261234'], bug_urls_to_ids(bug_urls, branch))
147
# set some bugtrackers
148
g_cfg = config.GlobalConfig()
149
g_cfg.set_user_option('bugtracker_py_url',
150
'http://bugs.python.org/issue{id}')
151
b_cfg = branch.get_config()
152
b_cfg.set_user_option('bugzilla_kde_url',
153
'http://bugs.kde.org/')
154
self.assertEqual(['kde:169104', 'lp:261234', 'py:5243'],
155
bug_urls_to_ids(bug_urls, branch))