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 |
|
|
6973.12.9
by Jelmer Vernooij
More fixes. |
20 |
try: |
21 |
from xmlrpc.client import Fault |
|
22 |
except ImportError: # python < 3 |
|
23 |
from xmlrpclib import Fault |
|
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
24 |
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
25 |
from .lp_registration import ( |
|
6729.6.1
by Jelmer Vernooij
Move urlutils errors. |
26 |
InvalidURL, |
27 |
InvalidLaunchpadInstance, |
|
28 |
LaunchpadService, |
|
29 |
NotLaunchpadBranch, |
|
30 |
)
|
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
31 |
from .test_lp_directory import FakeResolveFactory |
32 |
from ...tests import TestCase |
|
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
33 |
|
34 |
||
35 |
class LaunchpadServiceTests(TestCase): |
|
36 |
"""Test that the correct Launchpad instance is chosen.""" |
|
37 |
||
38 |
def setUp(self): |
|
39 |
super(LaunchpadServiceTests, self).setUp() |
|
40 |
# make sure we have a reproducible standard environment
|
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
41 |
self.overrideEnv('BRZ_LP_XMLRPC_URL', None) |
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
42 |
|
43 |
def test_default_service(self): |
|
44 |
service = LaunchpadService() |
|
45 |
self.assertEqual('https://xmlrpc.launchpad.net/bazaar/', |
|
46 |
service.service_url) |
|
47 |
||
48 |
def test_alter_default_service_url(self): |
|
49 |
LaunchpadService.DEFAULT_SERVICE_URL = 'http://example.com/' |
|
50 |
try: |
|
51 |
service = LaunchpadService() |
|
52 |
self.assertEqual('http://example.com/', |
|
53 |
service.service_url) |
|
54 |
finally: |
|
55 |
LaunchpadService.DEFAULT_SERVICE_URL = \ |
|
56 |
LaunchpadService.LAUNCHPAD_INSTANCE['production'] |
|
57 |
||
58 |
def test_staging_service(self): |
|
59 |
service = LaunchpadService(lp_instance='staging') |
|
60 |
self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/', |
|
61 |
service.service_url) |
|
62 |
||
63 |
def test_dev_service(self): |
|
64 |
service = LaunchpadService(lp_instance='dev') |
|
|
7413.1.2
by Vincent Ladeuil
Fix test failures caused by divergence between lp:brz and lp:brz/3.0 |
65 |
self.assertEqual('https://xmlrpc.launchpad.dev/bazaar/', |
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
66 |
service.service_url) |
67 |
||
68 |
def test_demo_service(self): |
|
69 |
service = LaunchpadService(lp_instance='demo') |
|
70 |
self.assertEqual('https://xmlrpc.demo.launchpad.net/bazaar/', |
|
71 |
service.service_url) |
|
72 |
||
73 |
def test_unknown_service(self): |
|
74 |
error = self.assertRaises(InvalidLaunchpadInstance, |
|
75 |
LaunchpadService, |
|
76 |
lp_instance='fubar') |
|
77 |
self.assertEqual('fubar is not a valid Launchpad instance.', |
|
78 |
str(error)) |
|
79 |
||
80 |
def test_environment_overrides_default(self): |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
81 |
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 |
82 |
service = LaunchpadService() |
83 |
self.assertEqual('http://example.com/', |
|
84 |
service.service_url) |
|
85 |
||
86 |
def test_environment_overrides_specified_service(self): |
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
87 |
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 |
88 |
service = LaunchpadService(lp_instance='staging') |
89 |
self.assertEqual('http://example.com/', |
|
90 |
service.service_url) |
|
|
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
91 |
|
92 |
||
93 |
class TestURLInference(TestCase): |
|
94 |
"""Test the way we infer Launchpad web pages from branch URLs.""" |
|
95 |
||
96 |
def test_default_bzr_ssh_url(self): |
|
97 |
service = LaunchpadService() |
|
98 |
web_url = service.get_web_url_from_branch_url( |
|
99 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
100 |
self.assertEqual( |
|
|
5243.1.1
by Martin
Use the production server in the launchpad plugin rather than edge |
101 |
'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, |
102 |
|
103 |
def test_product_bzr_ssh_url(self): |
|
104 |
service = LaunchpadService(lp_instance='production') |
|
105 |
web_url = service.get_web_url_from_branch_url( |
|
106 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
107 |
self.assertEqual( |
|
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
108 |
'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, |
109 |
|
|
3955.3.3
by Jonathan Lange
Test a couple more cases. |
110 |
def test_sftp_branch_url(self): |
111 |
service = LaunchpadService(lp_instance='production') |
|
112 |
web_url = service.get_web_url_from_branch_url( |
|
113 |
'sftp://bazaar.launchpad.net/~foo/bar/baz') |
|
114 |
self.assertEqual( |
|
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
115 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
|
3955.3.3
by Jonathan Lange
Test a couple more cases. |
116 |
|
117 |
def test_staging_branch_url(self): |
|
118 |
service = LaunchpadService(lp_instance='production') |
|
119 |
web_url = service.get_web_url_from_branch_url( |
|
120 |
'bzr+ssh://bazaar.staging.launchpad.net/~foo/bar/baz') |
|
121 |
self.assertEqual( |
|
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
122 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
|
3955.3.3
by Jonathan Lange
Test a couple more cases. |
123 |
|
|
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
124 |
def test_non_launchpad_url(self): |
125 |
service = LaunchpadService() |
|
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
126 |
error = self.assertRaises( |
127 |
NotLaunchpadBranch, service.get_web_url_from_branch_url, |
|
|
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
128 |
'bzr+ssh://example.com/~foo/bar/baz') |
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
129 |
self.assertEqual( |
|
4031.2.11
by John Arbash Meinel
Turn a bunch of imports into lazy imports. |
130 |
'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. |
131 |
str(error)) |
|
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
132 |
|
133 |
def test_dodgy_launchpad_url(self): |
|
134 |
service = LaunchpadService() |
|
135 |
self.assertRaises( |
|
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
136 |
NotLaunchpadBranch, service.get_web_url_from_branch_url, |
|
3955.3.4
by Jonathan Lange
Some error cases, plus a docstring. |
137 |
'bzr+ssh://launchpad.net/~foo/bar/baz') |
138 |
||
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
139 |
def test_lp_branch_url(self): |
140 |
service = LaunchpadService(lp_instance='production') |
|
|
3955.3.8
by Jonathan Lange
Support lp URL shortcuts. |
141 |
factory = FakeResolveFactory( |
142 |
self, '~foo/bar/baz', |
|
143 |
dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) |
|
144 |
web_url = service.get_web_url_from_branch_url( |
|
145 |
'lp:~foo/bar/baz', factory) |
|
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
146 |
self.assertEqual( |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
147 |
'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. |
148 |
|
|
3955.3.8
by Jonathan Lange
Support lp URL shortcuts. |
149 |
def test_lp_branch_shortcut(self): |
150 |
service = LaunchpadService() |
|
151 |
factory = FakeResolveFactory( |
|
152 |
self, 'foo', |
|
153 |
dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz'])) |
|
154 |
web_url = service.get_web_url_from_branch_url('lp:foo', factory) |
|
155 |
self.assertEqual( |
|
|
5243.1.1
by Martin
Use the production server in the launchpad plugin rather than edge |
156 |
'https://code.launchpad.net/~foo/bar/baz', web_url) |
|
3955.3.8
by Jonathan Lange
Support lp URL shortcuts. |
157 |
|
|
3955.3.9
by Jonathan Lange
Catch errors. |
158 |
def test_lp_branch_fault(self): |
159 |
service = LaunchpadService() |
|
160 |
factory = FakeResolveFactory(self, 'foo', None) |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
161 |
|
|
3955.3.9
by Jonathan Lange
Catch errors. |
162 |
def submit(service): |
|
6973.12.9
by Jelmer Vernooij
More fixes. |
163 |
raise Fault(42, 'something went wrong') |
|
3955.3.9
by Jonathan Lange
Catch errors. |
164 |
factory.submit = submit |
165 |
self.assertRaises( |
|
|
6729.6.1
by Jelmer Vernooij
Move urlutils errors. |
166 |
InvalidURL, service.get_web_url_from_branch_url, 'lp:foo', |
|
3955.3.9
by Jonathan Lange
Catch errors. |
167 |
factory) |
168 |
||
|
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
169 |
def test_staging_url(self): |
170 |
service = LaunchpadService(lp_instance='staging') |
|
171 |
web_url = service.get_web_url_from_branch_url( |
|
172 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
173 |
self.assertEqual( |
|
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
174 |
'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, |
175 |
|
176 |
def test_dev_url(self): |
|
177 |
service = LaunchpadService(lp_instance='dev') |
|
178 |
web_url = service.get_web_url_from_branch_url( |
|
179 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
180 |
self.assertEqual( |
|
|
7413.1.2
by Vincent Ladeuil
Fix test failures caused by divergence between lp:brz and lp:brz/3.0 |
181 |
'https://code.launchpad.dev/~foo/bar/baz', web_url) |
|
3955.3.1
by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService, |
182 |
|
183 |
def test_demo_url(self): |
|
184 |
service = LaunchpadService(lp_instance='demo') |
|
185 |
web_url = service.get_web_url_from_branch_url( |
|
186 |
'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz') |
|
187 |
self.assertEqual( |
|
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
188 |
'https://code.demo.launchpad.net/~foo/bar/baz', web_url) |