bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3251.4.2
by Aaron Bentley
Clean up Launchpad directory service code |
1 |
# Copyright (C) 2007, 2008 Canonical Ltd
|
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
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
|
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
16 |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
17 |
"""Tests for directory lookup through Launchpad.net"""
|
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
18 |
|
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
19 |
import xmlrpclib |
20 |
||
|
2245.8.3
by Martin Pool
Start adding indirection transport |
21 |
from bzrlib import ( |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
22 |
errors, |
|
2245.8.3
by Martin Pool
Start adding indirection transport |
23 |
)
|
|
2898.4.17
by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL. |
24 |
from bzrlib.branch import Branch |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
25 |
from bzrlib.directory_service import directories |
|
3777.1.18
by Aaron Bentley
Fix None handling wrt auth upgrades |
26 |
from bzrlib.tests import ( |
27 |
TestCaseInTempDir, |
|
28 |
TestCaseWithMemoryTransport
|
|
29 |
)
|
|
|
2898.4.17
by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL. |
30 |
from bzrlib.transport import get_transport |
|
3251.4.2
by Aaron Bentley
Clean up Launchpad directory service code |
31 |
from bzrlib.plugins.launchpad import _register_directory |
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
32 |
from bzrlib.plugins.launchpad.lp_directory import ( |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
33 |
LaunchpadDirectory) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
34 |
from bzrlib.plugins.launchpad.account import get_lp_login |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
35 |
|
36 |
||
37 |
class FakeResolveFactory(object): |
|
38 |
def __init__(self, test, expected_path, result): |
|
39 |
self._test = test |
|
40 |
self._expected_path = expected_path |
|
41 |
self._result = result |
|
42 |
||
43 |
def __call__(self, path): |
|
44 |
self._test.assertEqual(self._expected_path, path) |
|
45 |
return self |
|
46 |
||
47 |
def submit(self, service): |
|
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
48 |
self._service_url = service.service_url |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
49 |
return self._result |
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
50 |
|
|
2245.8.7
by Martin Pool
small review cleanups |
51 |
|
|
3777.1.18
by Aaron Bentley
Fix None handling wrt auth upgrades |
52 |
class DirectoryUrlTests(TestCaseInTempDir): |
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
53 |
"""Tests for branch urls through Launchpad.net directory""" |
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
54 |
|
|
2245.8.5
by Martin Pool
Add short-form lp:PRODUCT url form |
55 |
def test_short_form(self): |
56 |
"""A launchpad url should map to a http url""" |
|
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
57 |
factory = FakeResolveFactory( |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
58 |
self, 'apt', dict(urls=[ |
59 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
60 |
directory = LaunchpadDirectory() |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
61 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
62 |
directory._resolve('lp:apt', factory)) |
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
63 |
# Make sure that resolve went to the production server.
|
|
3221.1.12
by Martin Pool
Update Launchpad indirection tests to allow for xmlrpcs being sent to edge by default |
64 |
self.assertEquals('https://xmlrpc.edge.launchpad.net/bazaar/', |
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
65 |
factory._service_url) |
66 |
||
67 |
def test_staging(self): |
|
68 |
"""A launchpad url should map to a http url""" |
|
69 |
factory = FakeResolveFactory( |
|
70 |
self, 'apt', dict(urls=[ |
|
71 |
'http://bazaar.staging.launchpad.net/~apt/apt/devel'])) |
|
72 |
url = 'lp://staging/apt' |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
73 |
directory = LaunchpadDirectory() |
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
74 |
self.assertEquals('http://bazaar.staging.launchpad.net/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
75 |
directory._resolve(url, factory)) |
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
76 |
# Make sure that resolve went to the staging server.
|
77 |
self.assertEquals('https://xmlrpc.staging.launchpad.net/bazaar/', |
|
78 |
factory._service_url) |
|
|
2245.8.5
by Martin Pool
Add short-form lp:PRODUCT url form |
79 |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
80 |
def test_url_from_directory(self): |
|
2245.8.3
by Martin Pool
Start adding indirection transport |
81 |
"""A launchpad url should map to a http url""" |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
82 |
factory = FakeResolveFactory( |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
83 |
self, 'apt', dict(urls=[ |
84 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
85 |
directory = LaunchpadDirectory() |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
86 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
87 |
directory._resolve('lp:///apt', factory)) |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
88 |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
89 |
def test_directory_skip_bad_schemes(self): |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
90 |
factory = FakeResolveFactory( |
91 |
self, 'apt', dict(urls=[ |
|
92 |
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel', |
|
93 |
'http://bazaar.launchpad.net/~apt/apt/devel', |
|
94 |
'http://another/location'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
95 |
directory = LaunchpadDirectory() |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
96 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
97 |
directory._resolve('lp:///apt', factory)) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
98 |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
99 |
def test_directory_no_matching_schemes(self): |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
100 |
# If the XMLRPC call does not return any protocols we support,
|
101 |
# invalidURL is raised.
|
|
102 |
factory = FakeResolveFactory( |
|
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
103 |
self, 'apt', dict(urls=[ |
104 |
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
105 |
directory = LaunchpadDirectory() |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
106 |
self.assertRaises(errors.InvalidURL, |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
107 |
directory._resolve, 'lp:///apt', factory) |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
108 |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
109 |
def test_directory_fault(self): |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
110 |
# Test that XMLRPC faults get converted to InvalidURL errors.
|
111 |
factory = FakeResolveFactory(self, 'apt', None) |
|
112 |
def submit(service): |
|
113 |
raise xmlrpclib.Fault(42, 'something went wrong') |
|
114 |
factory.submit = submit |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
115 |
directory = LaunchpadDirectory() |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
116 |
self.assertRaises(errors.InvalidURL, |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
117 |
directory._resolve, 'lp:///apt', factory) |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
118 |
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
119 |
def test_skip_bzr_ssh_launchpad_net_when_anonymous(self): |
120 |
# Test that bzr+ssh://bazaar.launchpad.net gets skipped if
|
|
121 |
# Bazaar does not know the user's Launchpad ID:
|
|
122 |
self.assertEqual(None, get_lp_login()) |
|
123 |
factory = FakeResolveFactory( |
|
124 |
self, 'apt', dict(urls=[ |
|
125 |
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel', |
|
126 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
127 |
directory = LaunchpadDirectory() |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
128 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
129 |
directory._resolve('lp:///apt', factory)) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
130 |
|
|
3031.2.2
by jml at canonical
Failing test for skipping SFTP. |
131 |
def test_skip_sftp_launchpad_net_when_anonymous(self): |
132 |
# Test that sftp://bazaar.launchpad.net gets skipped if
|
|
133 |
# Bazaar does not know the user's Launchpad ID:
|
|
134 |
self.assertEqual(None, get_lp_login()) |
|
135 |
factory = FakeResolveFactory( |
|
136 |
self, 'apt', dict(urls=[ |
|
137 |
'sftp://bazaar.launchpad.net/~apt/apt/devel', |
|
138 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
139 |
directory = LaunchpadDirectory() |
|
3031.2.2
by jml at canonical
Failing test for skipping SFTP. |
140 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
141 |
directory._resolve('lp:///apt', factory)) |
|
3031.2.2
by jml at canonical
Failing test for skipping SFTP. |
142 |
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
143 |
def test_rewrite_bzr_ssh_launchpad_net(self): |
144 |
# Test that bzr+ssh URLs get rewritten to include the user's
|
|
145 |
# Launchpad ID (assuming we know the Launchpad ID).
|
|
146 |
factory = FakeResolveFactory( |
|
147 |
self, 'apt', dict(urls=[ |
|
148 |
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel', |
|
149 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
150 |
directory = LaunchpadDirectory() |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
151 |
self.assertEquals( |
|
3777.1.21
by Aaron Bentley
Stop including usernames in resolved lp: urls |
152 |
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
153 |
directory._resolve('lp:///apt', factory, _lp_login='username')) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
154 |
|
155 |
def test_no_rewrite_of_other_bzr_ssh(self): |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
156 |
# Test that we don't rewrite bzr+ssh URLs for other
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
157 |
self.assertEqual(None, get_lp_login()) |
158 |
factory = FakeResolveFactory( |
|
159 |
self, 'apt', dict(urls=[ |
|
160 |
'bzr+ssh://example.com/~apt/apt/devel', |
|
161 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
162 |
directory = LaunchpadDirectory() |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
163 |
self.assertEquals('bzr+ssh://example.com/~apt/apt/devel', |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
164 |
directory._resolve('lp:///apt', factory)) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
165 |
|
|
2245.8.4
by Martin Pool
lp:/// indirection works |
166 |
# TODO: check we get an error if the url is unreasonable
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
167 |
def test_error_for_bad_url(self): |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
168 |
directory = LaunchpadDirectory() |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
169 |
self.assertRaises(errors.InvalidURL, |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
170 |
directory._resolve, 'lp://ratotehunoahu') |
|
2898.4.12
by James Henstridge
Add tests that redirects get issued by appropriate transport methods. |
171 |
|
|
2898.4.17
by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL. |
172 |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
173 |
class DirectoryOpenBranchTests(TestCaseWithMemoryTransport): |
|
2898.4.17
by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL. |
174 |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
175 |
def test_directory_open_branch(self): |
|
2898.4.17
by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL. |
176 |
# Test that opening an lp: branch redirects to the real location.
|
177 |
target_branch = self.make_branch('target') |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
178 |
class FooService(object): |
179 |
"""A directory service that maps the name to a FILE url""" |
|
180 |
||
181 |
def look_up(self, name, url): |
|
182 |
if 'lp:///apt' == url: |
|
183 |
return target_branch.base.rstrip('/') |
|
|
3251.4.2
by Aaron Bentley
Clean up Launchpad directory service code |
184 |
return '!unexpected look_up value!' |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
185 |
|
186 |
directories.remove('lp:') |
|
187 |
directories.register('lp:', FooService, 'Map lp URLs to local urls') |
|
|
3251.4.2
by Aaron Bentley
Clean up Launchpad directory service code |
188 |
self.addCleanup(_register_directory) |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
189 |
self.addCleanup(lambda: directories.remove('lp:')) |
|
2898.4.17
by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL. |
190 |
transport = get_transport('lp:///apt') |
191 |
branch = Branch.open_from_transport(transport) |
|
192 |
self.assertEqual(target_branch.base, branch.base) |