~ubuntu-branches/debian/sid/qbzr/sid

« back to all changes in this revision

Viewing changes to lib/tests/test_bugs.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-12-05 01:20:38 UTC
  • Revision ID: james.westby@ubuntu.com-20091205012038-41f57s3ecv2r34lz
Tags: upstream-0.16
ImportĀ upstreamĀ versionĀ 0.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# QBzr - Qt frontend to Bazaar commands
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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.
 
18
 
 
19
from bzrlib import config
 
20
from bzrlib.tests import TestCase, TestCaseWithTransport
 
21
 
 
22
from bzrlib.plugins.qbzr.lib.bugs import (
 
23
    bug_urls_to_ids,
 
24
    get_branch_bug_tags,
 
25
    get_bug_id,
 
26
    get_global_bug_tags,
 
27
    get_unique_bug_tags,
 
28
    get_user_bug_trackers_tags,
 
29
    )
 
30
 
 
31
 
 
32
class TestGetBugId(TestCase):
 
33
 
 
34
    def test_launchpad(self):
 
35
        self.assertEquals('261234', get_bug_id('https://launchpad.net/bugs/261234'))
 
36
 
 
37
    def test_trac(self):
 
38
        self.assertEquals('3852', get_bug_id('http://bugs.musicbrainz.org/ticket/3852'))
 
39
 
 
40
    def test_bugzilla(self):
 
41
        self.assertEquals('169104', get_bug_id('http://bugs.kde.org/show_bug.cgi?id=169104'))
 
42
 
 
43
    def test_redmine(self):
 
44
        self.assertEquals('1832', get_bug_id('http://www.redmine.org/issues/show/1832'))
 
45
 
 
46
    def test_fogbugz(self):
 
47
        self.assertEquals('1234', get_bug_id('http://test.fogbugz.com/default.asp?1234'))
 
48
 
 
49
    def test_roundup(self):
 
50
        self.assertEquals('5243', get_bug_id('http://bugs.python.org/issue5243'))
 
51
 
 
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'))
 
55
 
 
56
 
 
57
class TestGetBugTags(TestCase):
 
58
 
 
59
    def test_get_user_bug_trackers_tags(self):
 
60
        self.assertEqual({}, get_user_bug_trackers_tags([]))
 
61
        self.assertEquals({'foo': 'bugtracker',
 
62
                           'bar': 'trac',
 
63
                           'spam': 'bugzilla'},
 
64
                           get_user_bug_trackers_tags([
 
65
                                'bugtracker_foo_url',
 
66
                                'trac_bar_url',
 
67
                                'bugzilla_spam_url',
 
68
                                'email',
 
69
                                'editor',
 
70
                                ]))
 
71
 
 
72
    def test_get_unique_bug_tags(self):
 
73
        self.assertEqual({'lp': 'unique',
 
74
                          'deb': 'unique',
 
75
                          'gnome': 'unique',
 
76
                          }, get_unique_bug_tags())
 
77
 
 
78
 
 
79
class TestGetBugTagsFromConfig(TestCaseWithTransport):
 
80
 
 
81
    def test_get_global_bug_tags(self):
 
82
        # check empty bazaar.conf
 
83
        self.assertEqual({}, get_global_bug_tags())
 
84
        # set some options
 
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/')
 
92
        self.assertEquals({
 
93
            'py': 'bugtracker',
 
94
            'kde': "bugzilla",
 
95
            'mbz': 'trac'},
 
96
            get_global_bug_tags())
 
97
 
 
98
    def test_get_branch_bug_tags(self):
 
99
        wt = self.make_branch_and_tree('.')
 
100
        branch = wt.branch
 
101
        # check empty branch.conf
 
102
        self.assertEqual({}, get_branch_bug_tags(branch))
 
103
        # set some options
 
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/')
 
111
        self.assertEquals({
 
112
            'py': 'bugtracker',
 
113
            'kde': "bugzilla",
 
114
            'mbz': 'trac'},
 
115
            get_branch_bug_tags(branch))
 
116
 
 
117
 
 
118
class TestBugUrlsToIds(TestCaseWithTransport):
 
119
 
 
120
    def test_wo_branch(self):
 
121
        bug_urls = [
 
122
            'https://launchpad.net/bugs/261234 fixed',
 
123
            'http://bugs.python.org/issue5243 fixed',
 
124
            ]
 
125
        # w/o global options we can match only unique lp url
 
126
        self.assertEqual(['lp:261234'], bug_urls_to_ids(bug_urls))
 
127
        # set some options
 
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))
 
136
 
 
137
    def test_w_branch(self):
 
138
        bug_urls = [
 
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',
 
142
            ]
 
143
        wt = self.make_branch_and_tree('.')
 
144
        branch = wt.branch
 
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))