bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
1 |
# Copyright (C) 2006-2012, 2016-2017 Canonical Ltd
|
|
0.4.1
by Martin Pool
Start lp-register command |
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
|
|
0.4.1
by Martin Pool
Start lp-register command |
16 |
|
|
6622.7.2
by Jelmer Vernooij
Merge lp:brz. |
17 |
from io import BytesIO |
|
6973.12.9
by Jelmer Vernooij
More fixes. |
18 |
|
19 |
try: |
|
20 |
from xmlrpc.client import ( |
|
21 |
loads as xmlrpc_loads, |
|
22 |
Transport, |
|
23 |
)
|
|
24 |
except ImportError: # python < 3 |
|
25 |
from xmlrpclib import ( |
|
26 |
loads as xmlrpc_loads, |
|
27 |
Transport, |
|
28 |
)
|
|
|
0.4.5
by Martin Pool
Add structured test for parameters passed through xmlrpc |
29 |
|
|
7078.12.1
by Jelmer Vernooij
Fix registration test on Python 3. |
30 |
from ...sixish import PY3 |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
31 |
from ...tests import TestCaseWithTransport |
|
0.4.1
by Martin Pool
Start lp-register command |
32 |
|
|
0.4.5
by Martin Pool
Add structured test for parameters passed through xmlrpc |
33 |
# local import
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
34 |
from .lp_registration import ( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
35 |
BaseRequest, |
36 |
ResolveLaunchpadPathRequest, |
|
37 |
LaunchpadService, |
|
38 |
)
|
|
|
0.4.5
by Martin Pool
Add structured test for parameters passed through xmlrpc |
39 |
|
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
40 |
|
|
0.4.12
by Martin Pool
doc |
41 |
# TODO: Test that the command-line client, making sure that it'll pass the
|
42 |
# request through to a dummy transport, and that the transport will validate
|
|
43 |
# the results passed in. Not sure how to get the transport object back out to
|
|
44 |
# validate that its OK - may not be necessary.
|
|
45 |
||
|
0.4.8
by Martin Pool
More instrumentation of xmlrpc requests |
46 |
class InstrumentedXMLRPCConnection(object): |
47 |
"""Stands in place of an http connection for the purposes of testing""" |
|
48 |
||
49 |
def __init__(self, testcase): |
|
50 |
self.testcase = testcase |
|
51 |
||
52 |
def getreply(self): |
|
53 |
"""Fake the http reply. |
|
54 |
||
55 |
:returns: (errcode, errmsg, headers)
|
|
56 |
"""
|
|
57 |
return (200, 'OK', []) |
|
58 |
||
|
5582.1.1
by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733 |
59 |
def getresponse(self, buffering=True): |
|
5582.1.2
by Jelmer Vernooij
Add NEWS entry, comment. Remove unnecessary code. |
60 |
"""Fake the http reply. |
61 |
||
62 |
This is used when running on Python 2.7, where xmlrpclib uses
|
|
63 |
httplib.HTTPConnection in a different way than before.
|
|
64 |
"""
|
|
|
5582.1.1
by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733 |
65 |
class FakeHttpResponse(object): |
66 |
||
|
5582.13.1
by Vincent Ladeuil
A bit less dirty and bit more robust so that it also works on FreeBSD8 (and may others). |
67 |
def __init__(self, status, reason, body): |
|
5582.1.1
by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733 |
68 |
self.status = status |
69 |
self.reason = reason |
|
70 |
self.body = body |
|
71 |
||
72 |
def read(self, size=-1): |
|
73 |
return self.body.read(size) |
|
74 |
||
|
5582.13.1
by Vincent Ladeuil
A bit less dirty and bit more robust so that it also works on FreeBSD8 (and may others). |
75 |
def getheader(self, name, default): |
76 |
# We don't have headers
|
|
77 |
return default |
|
78 |
||
79 |
return FakeHttpResponse(200, 'OK', self.getfile()) |
|
|
5582.1.1
by Bazaar Builbot Net
Quick-and-dirty hack to fix bug #654733 |
80 |
|
|
0.4.8
by Martin Pool
More instrumentation of xmlrpc requests |
81 |
def getfile(self): |
82 |
"""Return a fake file containing the response content.""" |
|
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
83 |
return BytesIO(b'''\ |
|
0.4.8
by Martin Pool
More instrumentation of xmlrpc requests |
84 |
<?xml version="1.0" ?>
|
85 |
<methodResponse>
|
|
|
0.4.11
by Martin Pool
Check the correct params are seen by the server |
86 |
<params>
|
87 |
<param>
|
|
88 |
<value>
|
|
89 |
<string>victoria dock</string>
|
|
90 |
</value>
|
|
91 |
</param>
|
|
92 |
</params>
|
|
|
0.4.8
by Martin Pool
More instrumentation of xmlrpc requests |
93 |
</methodResponse>''') |
94 |
||
95 |
||
|
6973.12.9
by Jelmer Vernooij
More fixes. |
96 |
class InstrumentedXMLRPCTransport(Transport): |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
97 |
|
|
2027.2.2
by Marien Zwart
Fixes for python 2.5. |
98 |
# Python 2.5's xmlrpclib looks for this.
|
99 |
_use_datetime = False |
|
|
7078.12.1
by Jelmer Vernooij
Fix registration test on Python 3. |
100 |
_use_builtin_types = False |
|
2027.2.2
by Marien Zwart
Fixes for python 2.5. |
101 |
|
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
102 |
def __init__(self, testcase): |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
103 |
self.testcase = testcase |
|
5582.1.3
by Jelmer Vernooij
Revert _connection change, as it is apparently needed for Python >= 2.7.0 && Python < 2.7.2. |
104 |
self._connection = (None, None) |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
105 |
|
106 |
def make_connection(self, host): |
|
107 |
host, http_headers, x509 = self.get_host_info(host) |
|
108 |
test = self.testcase |
|
|
0.4.10
by Martin Pool
Move test-specific values out of InstrumentedXMLRPCTransport |
109 |
self.connected_host = host |
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
110 |
if http_headers: |
|
3376.2.15
by Martin Pool
Fix assertions in Launchpad registration tests |
111 |
raise AssertionError() |
|
0.4.8
by Martin Pool
More instrumentation of xmlrpc requests |
112 |
return InstrumentedXMLRPCConnection(test) |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
113 |
|
|
7078.12.1
by Jelmer Vernooij
Fix registration test on Python 3. |
114 |
if PY3: |
115 |
def send_request(self, host, handler_path, request_body, |
|
116 |
verbose=None): |
|
117 |
self.connected_host = host |
|
118 |
test = self.testcase |
|
119 |
self.got_request = True |
|
120 |
unpacked, method = xmlrpc_loads(request_body) |
|
121 |
if None in unpacked: |
|
122 |
raise AssertionError( |
|
123 |
"xmlrpc result %r shouldn't contain None" % (unpacked,)) |
|
124 |
self.sent_params = unpacked |
|
125 |
return InstrumentedXMLRPCConnection(test) |
|
126 |
else: |
|
127 |
def send_request(self, connection, handler_path, request_body, |
|
128 |
verbose=None): |
|
129 |
test = self.testcase |
|
130 |
self.got_request = True |
|
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
131 |
|
132 |
def send_host(self, conn, host): |
|
133 |
pass
|
|
134 |
||
135 |
def send_user_agent(self, conn): |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
136 |
# TODO: send special user agent string, including breezy version
|
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
137 |
# number
|
138 |
pass
|
|
139 |
||
140 |
def send_content(self, conn, request_body): |
|
|
6973.12.9
by Jelmer Vernooij
More fixes. |
141 |
unpacked, method = xmlrpc_loads(request_body) |
|
3376.2.15
by Martin Pool
Fix assertions in Launchpad registration tests |
142 |
if None in unpacked: |
143 |
raise AssertionError( |
|
144 |
"xmlrpc result %r shouldn't contain None" % (unpacked,)) |
|
|
0.4.10
by Martin Pool
Move test-specific values out of InstrumentedXMLRPCTransport |
145 |
self.sent_params = unpacked |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
146 |
|
147 |
||
|
0.4.22
by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server. |
148 |
class MockLaunchpadService(LaunchpadService): |
149 |
||
|
6973.12.11
by Jelmer Vernooij
Fix some more tests. |
150 |
def send_request(self, method_name, method_params, verbose=None): |
|
0.4.22
by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server. |
151 |
"""Stash away the method details rather than sending them to a real server""" |
152 |
self.called_method_name = method_name |
|
153 |
self.called_method_params = method_params |
|
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
154 |
|
155 |
||
156 |
class TestResolveLaunchpadPathRequest(TestCaseWithTransport): |
|
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
157 |
|
|
0.4.23
by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test. |
158 |
def setUp(self): |
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
159 |
super(TestResolveLaunchpadPathRequest, self).setUp() |
|
0.4.23
by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test. |
160 |
# make sure we have a reproducible standard environment
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
161 |
self.overrideEnv('BRZ_LP_XMLRPC_URL', None) |
|
0.4.23
by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test. |
162 |
|
163 |
def test_onto_transport(self): |
|
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
164 |
"""A request is transmitted across a mock Transport""" |
165 |
transport = InstrumentedXMLRPCTransport(self) |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
166 |
service = LaunchpadService(transport) |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
167 |
resolve = ResolveLaunchpadPathRequest('bzr') |
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
168 |
resolve.submit(service) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
169 |
self.assertEqual(transport.connected_host, 'xmlrpc.launchpad.net') |
170 |
self.assertEqual(len(transport.sent_params), 1) |
|
171 |
self.assertEqual(transport.sent_params, ('bzr', )) |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
172 |
self.assertTrue(transport.got_request) |
173 |
||
|
0.4.22
by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server. |
174 |
def test_subclass_request(self): |
175 |
"""Define a new type of xmlrpc request""" |
|
176 |
class DummyRequest(BaseRequest): |
|
177 |
_methodname = 'dummy_request' |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
178 |
|
|
0.4.22
by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server. |
179 |
def _request_params(self): |
180 |
return (42,) |
|
181 |
||
182 |
service = MockLaunchpadService() |
|
183 |
service.registrant_email = 'test@launchpad.net' |
|
184 |
service.registrant_password = '' |
|
185 |
request = DummyRequest() |
|
186 |
request.submit(service) |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
187 |
self.assertEqual(service.called_method_name, 'dummy_request') |
188 |
self.assertEqual(service.called_method_params, (42,)) |
|
|
0.4.22
by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server. |
189 |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
190 |
def test_mock_resolve_lp_url(self): |
191 |
test_case = self |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
192 |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
193 |
class MockService(MockLaunchpadService): |
|
6973.12.11
by Jelmer Vernooij
Fix some more tests. |
194 |
def send_request(self, method_name, method_params, |
195 |
verbose=None): |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
196 |
test_case.assertEqual(method_name, "resolve_lp_path") |
197 |
test_case.assertEqual(list(method_params), ['bzr']) |
|
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
198 |
return dict(urls=[ |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
199 |
'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk', |
200 |
'sftp://bazaar.launchpad.net~bzr/bzr/trunk', |
|
201 |
'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk', |
|
202 |
'http://bazaar.launchpad.net~bzr/bzr/trunk']) |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
203 |
service = MockService() |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
204 |
resolve = ResolveLaunchpadPathRequest('bzr') |
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
205 |
result = resolve.submit(service) |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
206 |
self.assertTrue('urls' in result) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
207 |
self.assertEqual(result['urls'], [ |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
208 |
'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk', |
209 |
'sftp://bazaar.launchpad.net~bzr/bzr/trunk', |
|
210 |
'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk', |
|
211 |
'http://bazaar.launchpad.net~bzr/bzr/trunk']) |