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