bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
1 |
# Copyright (C) 2007 Canonical Ltd
|
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 |
||
17 |
"""Tests for indirect branch urls through Launchpad.net"""
|
|
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 |
25 |
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport |
|
26 |
from bzrlib.transport import get_transport |
|
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
27 |
from bzrlib.plugins.launchpad.lp_indirect import ( |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
28 |
LaunchpadTransport) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
29 |
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. |
30 |
|
31 |
||
32 |
class FakeResolveFactory(object): |
|
33 |
def __init__(self, test, expected_path, result): |
|
34 |
self._test = test |
|
35 |
self._expected_path = expected_path |
|
36 |
self._result = result |
|
37 |
||
38 |
def __call__(self, path): |
|
39 |
self._test.assertEqual(self._expected_path, path) |
|
40 |
return self |
|
41 |
||
42 |
def submit(self, service): |
|
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
43 |
self._service_url = service.service_url |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
44 |
return self._result |
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
45 |
|
|
2245.8.7
by Martin Pool
small review cleanups |
46 |
|
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
47 |
class IndirectUrlTests(TestCase): |
|
2245.8.7
by Martin Pool
small review cleanups |
48 |
"""Tests for indirect branch urls through Launchpad.net""" |
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
49 |
|
|
2245.8.5
by Martin Pool
Add short-form lp:PRODUCT url form |
50 |
def test_short_form(self): |
51 |
"""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. |
52 |
factory = FakeResolveFactory( |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
53 |
self, 'apt', dict(urls=[ |
54 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
55 |
transport = LaunchpadTransport('lp:///') |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
56 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
57 |
transport._resolve('lp:apt', factory)) |
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
58 |
# 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 |
59 |
self.assertEquals('https://xmlrpc.edge.launchpad.net/bazaar/', |
|
3193.5.2
by Tim Penhey
Updated the tests to handle unknown launchpad instances. |
60 |
factory._service_url) |
61 |
||
62 |
def test_staging(self): |
|
63 |
"""A launchpad url should map to a http url""" |
|
64 |
factory = FakeResolveFactory( |
|
65 |
self, 'apt', dict(urls=[ |
|
66 |
'http://bazaar.staging.launchpad.net/~apt/apt/devel'])) |
|
67 |
url = 'lp://staging/apt' |
|
68 |
transport = LaunchpadTransport(url) |
|
69 |
self.assertEquals('http://bazaar.staging.launchpad.net/~apt/apt/devel', |
|
70 |
transport._resolve(url, factory)) |
|
71 |
# Make sure that resolve went to the staging server.
|
|
72 |
self.assertEquals('https://xmlrpc.staging.launchpad.net/bazaar/', |
|
73 |
factory._service_url) |
|
|
2245.8.5
by Martin Pool
Add short-form lp:PRODUCT url form |
74 |
|
|
2245.8.3
by Martin Pool
Start adding indirection transport |
75 |
def test_indirect_through_url(self): |
76 |
"""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. |
77 |
factory = FakeResolveFactory( |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
78 |
self, 'apt', dict(urls=[ |
79 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
80 |
transport = LaunchpadTransport('lp:///') |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
81 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
82 |
transport._resolve('lp:///apt', factory)) |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
83 |
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
84 |
def test_indirect_skip_bad_schemes(self): |
85 |
factory = FakeResolveFactory( |
|
86 |
self, 'apt', dict(urls=[ |
|
87 |
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel', |
|
88 |
'http://bazaar.launchpad.net/~apt/apt/devel', |
|
89 |
'http://another/location'])) |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
90 |
transport = LaunchpadTransport('lp:///') |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
91 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
92 |
transport._resolve('lp:///apt', factory)) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
93 |
|
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
94 |
def test_indirect_no_matching_schemes(self): |
95 |
# If the XMLRPC call does not return any protocols we support,
|
|
96 |
# invalidURL is raised.
|
|
97 |
factory = FakeResolveFactory( |
|
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
98 |
self, 'apt', dict(urls=[ |
99 |
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
100 |
transport = LaunchpadTransport('lp:///') |
101 |
self.assertRaises(errors.InvalidURL, |
|
102 |
transport._resolve, 'lp:///apt', factory) |
|
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
103 |
|
104 |
def test_indirect_fault(self): |
|
105 |
# Test that XMLRPC faults get converted to InvalidURL errors.
|
|
106 |
factory = FakeResolveFactory(self, 'apt', None) |
|
107 |
def submit(service): |
|
108 |
raise xmlrpclib.Fault(42, 'something went wrong') |
|
109 |
factory.submit = submit |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
110 |
transport = LaunchpadTransport('lp:///') |
111 |
self.assertRaises(errors.InvalidURL, |
|
112 |
transport._resolve, 'lp:///apt', factory) |
|
|
2245.8.4
by Martin Pool
lp:/// indirection works |
113 |
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
114 |
def test_skip_bzr_ssh_launchpad_net_when_anonymous(self): |
115 |
# Test that bzr+ssh://bazaar.launchpad.net gets skipped if
|
|
116 |
# Bazaar does not know the user's Launchpad ID:
|
|
117 |
self.assertEqual(None, get_lp_login()) |
|
118 |
factory = FakeResolveFactory( |
|
119 |
self, 'apt', dict(urls=[ |
|
120 |
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel', |
|
121 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
122 |
transport = LaunchpadTransport('lp:///') |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
123 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
124 |
transport._resolve('lp:///apt', factory)) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
125 |
|
|
3031.2.2
by jml at canonical
Failing test for skipping SFTP. |
126 |
def test_skip_sftp_launchpad_net_when_anonymous(self): |
127 |
# Test that sftp://bazaar.launchpad.net gets skipped if
|
|
128 |
# Bazaar does not know the user's Launchpad ID:
|
|
129 |
self.assertEqual(None, get_lp_login()) |
|
130 |
factory = FakeResolveFactory( |
|
131 |
self, 'apt', dict(urls=[ |
|
132 |
'sftp://bazaar.launchpad.net/~apt/apt/devel', |
|
133 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
134 |
transport = LaunchpadTransport('lp:///') |
|
135 |
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel', |
|
136 |
transport._resolve('lp:///apt', factory)) |
|
137 |
||
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
138 |
def test_rewrite_bzr_ssh_launchpad_net(self): |
139 |
# Test that bzr+ssh URLs get rewritten to include the user's
|
|
140 |
# Launchpad ID (assuming we know the Launchpad ID).
|
|
141 |
factory = FakeResolveFactory( |
|
142 |
self, 'apt', dict(urls=[ |
|
143 |
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel', |
|
144 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
145 |
transport = LaunchpadTransport('lp:///') |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
146 |
self.assertEquals( |
147 |
'bzr+ssh://username@bazaar.launchpad.net/~apt/apt/devel', |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
148 |
transport._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 |
149 |
|
150 |
def test_no_rewrite_of_other_bzr_ssh(self): |
|
151 |
# Test that we don't rewrite bzr+ssh URLs for other
|
|
152 |
self.assertEqual(None, get_lp_login()) |
|
153 |
factory = FakeResolveFactory( |
|
154 |
self, 'apt', dict(urls=[ |
|
155 |
'bzr+ssh://example.com/~apt/apt/devel', |
|
156 |
'http://bazaar.launchpad.net/~apt/apt/devel'])) |
|
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
157 |
transport = LaunchpadTransport('lp:///') |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
158 |
self.assertEquals('bzr+ssh://example.com/~apt/apt/devel', |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
159 |
transport._resolve('lp:///apt', factory)) |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
160 |
|
|
2245.8.4
by Martin Pool
lp:/// indirection works |
161 |
# TODO: check we get an error if the url is unreasonable
|
162 |
def test_error_for_bad_indirection(self): |
|
163 |
self.assertRaises(errors.InvalidURL, |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
164 |
LaunchpadTransport, 'lp://ratotehunoahu') |
|
2898.4.12
by James Henstridge
Add tests that redirects get issued by appropriate transport methods. |
165 |
|
166 |
def catch_redirect(self, methodname, *args): |
|
167 |
transport = LaunchpadTransport('lp:///apt') |
|
168 |
def _resolve(abspath): |
|
169 |
self.assertEqual('lp:///apt', abspath) |
|
170 |
return 'http://example.com/~apt/apt/devel' |
|
171 |
transport._resolve = _resolve |
|
172 |
try: |
|
173 |
getattr(transport, methodname)(*args) |
|
174 |
except errors.RedirectRequested, exc: |
|
175 |
return exc |
|
176 |
else: |
|
177 |
raise self.failException('RedirectRequested not raised') |
|
178 |
||
179 |
def test_redirect_on_get(self): |
|
180 |
exc = self.catch_redirect('get', '.bzr/branch-format') |
|
181 |
self.assertEqual('lp:///apt/.bzr/branch-format', exc.source) |
|
182 |
self.assertEqual( |
|
183 |
'http://example.com/~apt/apt/devel/.bzr/branch-format', exc.target) |
|
184 |
||
185 |
def test_redirect_on_mkdir(self): |
|
186 |
exc = self.catch_redirect('mkdir', '.') |
|
187 |
self.assertEqual('lp:///apt', exc.source) |
|
188 |
self.assertEqual( |
|
189 |
'http://example.com/~apt/apt/devel', exc.target) |
|
190 |
||
|
2898.4.17
by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL. |
191 |
|
192 |
class IndirectOpenBranchTests(TestCaseWithMemoryTransport): |
|
193 |
||
194 |
def test_indirect_open_branch(self): |
|
195 |
# Test that opening an lp: branch redirects to the real location.
|
|
196 |
target_branch = self.make_branch('target') |
|
197 |
transport = get_transport('lp:///apt') |
|
198 |
def _resolve(abspath): |
|
199 |
self.assertEqual('lp:///apt', abspath) |
|
200 |
return target_branch.base.rstrip('/') |
|
201 |
transport._resolve = _resolve |
|
202 |
branch = Branch.open_from_transport(transport) |
|
203 |
self.assertEqual(target_branch.base, branch.base) |