bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7
by John Arbash Meinel
Merge in the bzr.dev 5582 |
1 |
# Copyright (C) 2008-2011 Canonical Ltd
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
16 |
|
17 |
"""Tests for selection of the right Launchpad service by environment"""
|
|
18 |
||
19 |
import os |
|
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
20 |
from xmlrpc.client import Fault |
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
21 |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
22 |
from .lp_registration import ( |
6729.6.1
by Jelmer Vernooij
Move urlutils errors. |
23 |
InvalidURL, |
24 |
InvalidLaunchpadInstance, |
|
25 |
LaunchpadService, |
|
26 |
NotLaunchpadBranch, |
|
27 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
28 |
from .test_lp_directory import FakeResolveFactory |
29 |
from ...tests import TestCase |
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
30 |
|
31 |
||
32 |
class LaunchpadServiceTests(TestCase): |
|
33 |
"""Test that the correct Launchpad instance is chosen.""" |
|
34 |
||
35 |
def setUp(self): |
|
36 |
super(LaunchpadServiceTests, self).setUp() |
|
37 |
# make sure we have a reproducible standard environment
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
38 |
self.overrideEnv('BRZ_LP_XMLRPC_URL', None) |
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
39 |
|
40 |
def test_default_service(self): |
|
41 |
service = LaunchpadService() |
|
42 |
self.assertEqual('https://xmlrpc.launchpad.net/bazaar/', |
|
43 |
service.service_url) |
|
44 |
||
45 |
def test_alter_default_service_url(self): |
|
46 |
LaunchpadService.DEFAULT_SERVICE_URL = 'http://example.com/' |
|
47 |
try: |
|
48 |
service = LaunchpadService() |
|
49 |
self.assertEqual('http://example.com/', |
|
50 |
service.service_url) |
|
51 |
finally: |
|
52 |
LaunchpadService.DEFAULT_SERVICE_URL = \ |
|
53 |
LaunchpadService.LAUNCHPAD_INSTANCE['production'] |
|
54 |
||
55 |
def test_staging_service(self): |
|
56 |
service = LaunchpadService(lp_instance='staging') |
|
57 |
self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/', |
|
58 |
service.service_url) |
|
59 |
||
7521.3.1
by Colin Watson
Define a Launchpad 'test' domain rather than 'dev'. |
60 |
def test_test_service(self): |
61 |
service = LaunchpadService(lp_instance='test') |
|
62 |
self.assertEqual('https://xmlrpc.launchpad.test/bazaar/', |
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
63 |
service.service_url) |
64 |
||
65 |
def test_demo_service(self): |
|
66 |
service = LaunchpadService(lp_instance='demo') |
|
67 |
self.assertEqual('https://xmlrpc.demo.launchpad.net/bazaar/', |
|
68 |
service.service_url) |
|
69 |
||
70 |
def test_unknown_service(self): |
|
71 |
error = self.assertRaises(InvalidLaunchpadInstance, |
|
72 |
LaunchpadService, |
|
73 |
lp_instance='fubar') |
|
74 |
self.assertEqual('fubar is not a valid Launchpad instance.', |
|
75 |
str(error)) |
|
76 |
||
77 |
def test_environment_overrides_default(self): |
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
78 |
os.environ['BRZ_LP_XMLRPC_URL'] = 'http://example.com/' |
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
79 |
service = LaunchpadService() |
80 |
self.assertEqual('http://example.com/', |
|
81 |
service.service_url) |
|
82 |
||
83 |
def test_environment_overrides_specified_service(self): |
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
84 |
os.environ['BRZ_LP_XMLRPC_URL'] = 'http://example.com/' |
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
85 |
service = LaunchpadService(lp_instance='staging') |
86 |
self.assertEqual('http://example.com/', |
|
87 |
service.service_url) |
|
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
88 |
|
89 |
||
90 |
class TestURLInference(TestCase): |
|
91 |
"""Test the way we infer Launchpad web pages from branch URLs.""" |
|
92 |
||
93 |
def test_default_bzr_ssh_url(self): |
|
94 |
service = LaunchpadService() |
|
95 |
web_url = service.get_web_url_from_branch_url( |
|
96 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
97 |
self.assertEqual( |
|
5243.1.1
by Martin
Use the production server in the launchpad plugin rather than edge |
98 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
99 |
|
100 |
def test_product_bzr_ssh_url(self): |
|
101 |
service = LaunchpadService(lp_instance='production') |
|
102 |
web_url = service.get_web_url_from_branch_url( |
|
103 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
104 |
self.assertEqual( |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
105 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
106 |
|
3955.3.3
by Jonathan Lange
Test a couple more cases. |
107 |
def test_sftp_branch_url(self): |
108 |
service = LaunchpadService(lp_instance='production') |
|
109 |
web_url = service.get_web_url_from_branch_url( |
|
110 |
'sftp://bazaar.launchpad.net/~foo/bar/baz') |
|
111 |
self.assertEqual( |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
112 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
3955.3.3
by Jonathan Lange
Test a couple more cases. |
113 |
|
114 |
def test_staging_branch_url(self): |
|
115 |
service = LaunchpadService(lp_instance='production') |
|
116 |
web_url = service.get_web_url_from_branch_url( |
|
117 |
'bzr+ssh://bazaar.staging.launchpad.net/~foo/bar/baz') |
|
118 |
self.assertEqual( |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
119 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
3955.3.3
by Jonathan Lange
Test a couple more cases. |
120 |
|
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
121 |
def test_non_launchpad_url(self): |
122 |
service = LaunchpadService() |
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
123 |
error = self.assertRaises( |
124 |
NotLaunchpadBranch, service.get_web_url_from_branch_url, |
|
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
125 |
'bzr+ssh://example.com/~foo/bar/baz') |
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
126 |
self.assertEqual( |
4031.2.11
by John Arbash Meinel
Turn a bunch of imports into lazy imports. |
127 |
'bzr+ssh://example.com/~foo/bar/baz is not registered on Launchpad.', |
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
128 |
str(error)) |
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
129 |
|
130 |
def test_dodgy_launchpad_url(self): |
|
131 |
service = LaunchpadService() |
|
132 |
self.assertRaises( |
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
133 |
NotLaunchpadBranch, service.get_web_url_from_branch_url, |
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
134 |
'bzr+ssh://launchpad.net/~foo/bar/baz') |
135 |
||
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
136 |
def test_lp_branch_url(self): |
137 |
service = LaunchpadService(lp_instance='production') |
|
3955.3.8
by Jonathan Lange
Support lp URL shortcuts. |
138 |
factory = FakeResolveFactory( |
139 |
self, '~foo/bar/baz', |
|
140 |
dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) |
|
141 |
web_url = service.get_web_url_from_branch_url( |
|
142 |
'lp:~foo/bar/baz', factory) |
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
143 |
self.assertEqual( |
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
144 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
145 |
|
3955.3.8
by Jonathan Lange
Support lp URL shortcuts. |
146 |
def test_lp_branch_shortcut(self): |
147 |
service = LaunchpadService() |
|
148 |
factory = FakeResolveFactory( |
|
149 |
self, 'foo', |
|
150 |
dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) |
|
151 |
web_url = service.get_web_url_from_branch_url('lp:foo', factory) |
|
152 |
self.assertEqual( |
|
5243.1.1
by Martin
Use the production server in the launchpad plugin rather than edge |
153 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
3955.3.8
by Jonathan Lange
Support lp URL shortcuts. |
154 |
|
3955.3.9
by Jonathan Lange
Catch errors. |
155 |
def test_lp_branch_fault(self): |
156 |
service = LaunchpadService() |
|
157 |
factory = FakeResolveFactory(self, 'foo', None) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
158 |
|
3955.3.9
by Jonathan Lange
Catch errors. |
159 |
def submit(service): |
6973.12.9
by Jelmer Vernooij
More fixes. |
160 |
raise Fault(42, 'something went wrong') |
3955.3.9
by Jonathan Lange
Catch errors. |
161 |
factory.submit = submit |
162 |
self.assertRaises( |
|
6729.6.1
by Jelmer Vernooij
Move urlutils errors. |
163 |
InvalidURL, service.get_web_url_from_branch_url, 'lp:foo', |
3955.3.9
by Jonathan Lange
Catch errors. |
164 |
factory) |
165 |
||
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
166 |
def test_staging_url(self): |
167 |
service = LaunchpadService(lp_instance='staging') |
|
168 |
web_url = service.get_web_url_from_branch_url( |
|
169 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
170 |
self.assertEqual( |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
171 |
'https://code.staging.launchpad.net/~foo/bar/baz', web_url) |
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
172 |
|
7521.3.1
by Colin Watson
Define a Launchpad 'test' domain rather than 'dev'. |
173 |
def test_test_url(self): |
174 |
service = LaunchpadService(lp_instance='test') |
|
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
175 |
web_url = service.get_web_url_from_branch_url( |
176 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
177 |
self.assertEqual( |
|
7521.3.1
by Colin Watson
Define a Launchpad 'test' domain rather than 'dev'. |
178 |
'https://code.launchpad.test/~foo/bar/baz', web_url) |
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
179 |
|
180 |
def test_demo_url(self): |
|
181 |
service = LaunchpadService(lp_instance='demo') |
|
182 |
web_url = service.get_web_url_from_branch_url( |
|
183 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
184 |
self.assertEqual( |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
185 |
'https://code.demo.launchpad.net/~foo/bar/baz', web_url) |