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 ( |
|
0.4.26
by Martin Pool
(register-branch) Add test for link_branch_to_bug and fix its parameters |
35 |
BaseRequest, |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
36 |
ResolveLaunchpadPathRequest, |
|
0.4.26
by Martin Pool
(register-branch) Add test for link_branch_to_bug and fix its parameters |
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 |
||
96 |
||
|
6973.12.9
by Jelmer Vernooij
More fixes. |
97 |
class InstrumentedXMLRPCTransport(Transport): |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
98 |
|
|
2027.2.2
by Marien Zwart
Fixes for python 2.5. |
99 |
# Python 2.5's xmlrpclib looks for this.
|
100 |
_use_datetime = False |
|
|
7078.12.1
by Jelmer Vernooij
Fix registration test on Python 3. |
101 |
_use_builtin_types = False |
|
2027.2.2
by Marien Zwart
Fixes for python 2.5. |
102 |
|
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
103 |
def __init__(self, testcase): |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
104 |
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. |
105 |
self._connection = (None, None) |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
106 |
|
107 |
def make_connection(self, host): |
|
108 |
host, http_headers, x509 = self.get_host_info(host) |
|
109 |
test = self.testcase |
|
|
0.4.10
by Martin Pool
Move test-specific values out of InstrumentedXMLRPCTransport |
110 |
self.connected_host = host |
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
111 |
if http_headers: |
|
3376.2.15
by Martin Pool
Fix assertions in Launchpad registration tests |
112 |
raise AssertionError() |
|
0.4.8
by Martin Pool
More instrumentation of xmlrpc requests |
113 |
return InstrumentedXMLRPCConnection(test) |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
114 |
|
|
7078.12.1
by Jelmer Vernooij
Fix registration test on Python 3. |
115 |
if PY3: |
116 |
def send_request(self, host, handler_path, request_body, |
|
117 |
verbose=None): |
|
118 |
self.connected_host = host |
|
119 |
test = self.testcase |
|
120 |
self.got_request = True |
|
121 |
unpacked, method = xmlrpc_loads(request_body) |
|
122 |
if None in unpacked: |
|
123 |
raise AssertionError( |
|
124 |
"xmlrpc result %r shouldn't contain None" % (unpacked,)) |
|
125 |
self.sent_params = unpacked |
|
126 |
return InstrumentedXMLRPCConnection(test) |
|
127 |
else: |
|
128 |
def send_request(self, connection, handler_path, request_body, |
|
129 |
verbose=None): |
|
130 |
test = self.testcase |
|
131 |
self.got_request = True |
|
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
132 |
|
133 |
def send_host(self, conn, host): |
|
134 |
pass
|
|
135 |
||
136 |
def send_user_agent(self, conn): |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
137 |
# 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. |
138 |
# number
|
139 |
pass
|
|
140 |
||
141 |
def send_content(self, conn, request_body): |
|
|
6973.12.9
by Jelmer Vernooij
More fixes. |
142 |
unpacked, method = xmlrpc_loads(request_body) |
|
3376.2.15
by Martin Pool
Fix assertions in Launchpad registration tests |
143 |
if None in unpacked: |
144 |
raise AssertionError( |
|
145 |
"xmlrpc result %r shouldn't contain None" % (unpacked,)) |
|
|
0.4.10
by Martin Pool
Move test-specific values out of InstrumentedXMLRPCTransport |
146 |
self.sent_params = unpacked |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
147 |
|
148 |
||
|
0.4.22
by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server. |
149 |
class MockLaunchpadService(LaunchpadService): |
150 |
||
|
6973.12.11
by Jelmer Vernooij
Fix some more tests. |
151 |
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. |
152 |
"""Stash away the method details rather than sending them to a real server""" |
153 |
self.called_method_name = method_name |
|
154 |
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. |
155 |
|
156 |
||
157 |
class TestResolveLaunchpadPathRequest(TestCaseWithTransport): |
|
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
158 |
|
|
0.4.23
by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test. |
159 |
def setUp(self): |
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
160 |
super(TestResolveLaunchpadPathRequest, self).setUp() |
|
0.4.23
by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test. |
161 |
# make sure we have a reproducible standard environment
|
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
162 |
self.overrideEnv('BRZ_LP_XMLRPC_URL', None) |
|
0.4.23
by Martin Pool
(register-branch) fix ordering of parameters and restore transport-level test. |
163 |
|
164 |
def test_onto_transport(self): |
|
|
6622.7.1
by Colin Watson
Remove `bzr register-branch`, since it has not worked for a long time. |
165 |
"""A request is transmitted across a mock Transport""" |
166 |
transport = InstrumentedXMLRPCTransport(self) |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
167 |
service = LaunchpadService(transport) |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
168 |
resolve = ResolveLaunchpadPathRequest('bzr') |
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
169 |
resolve.submit(service) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
170 |
self.assertEqual(transport.connected_host, 'xmlrpc.launchpad.net') |
171 |
self.assertEqual(len(transport.sent_params), 1) |
|
172 |
self.assertEqual(transport.sent_params, ('bzr', )) |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
173 |
self.assertTrue(transport.got_request) |
174 |
||
|
0.4.22
by Martin Pool
(register-branch) Update tests to be in-process calls to a mock server. |
175 |
def test_subclass_request(self): |
176 |
"""Define a new type of xmlrpc request""" |
|
177 |
class DummyRequest(BaseRequest): |
|
178 |
_methodname = 'dummy_request' |
|
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 |
|
192 |
class MockService(MockLaunchpadService): |
|
|
6973.12.11
by Jelmer Vernooij
Fix some more tests. |
193 |
def send_request(self, method_name, method_params, |
194 |
verbose=None): |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
195 |
test_case.assertEqual(method_name, "resolve_lp_path") |
196 |
test_case.assertEqual(list(method_params), ['bzr']) |
|
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
197 |
return dict(urls=[ |
198 |
'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk', |
|
199 |
'sftp://bazaar.launchpad.net~bzr/bzr/trunk', |
|
200 |
'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk', |
|
201 |
'http://bazaar.launchpad.net~bzr/bzr/trunk']) |
|
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
202 |
service = MockService() |
|
2898.4.3
by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL. |
203 |
resolve = ResolveLaunchpadPathRequest('bzr') |
|
2898.4.2
by James Henstridge
Add ResolveLaunchpadURLRequest() class to handle lp: URL resolution. |
204 |
result = resolve.submit(service) |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
205 |
self.assertTrue('urls' in result) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
206 |
self.assertEqual(result['urls'], [ |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
207 |
'bzr+ssh://bazaar.launchpad.net~bzr/bzr/trunk', |
208 |
'sftp://bazaar.launchpad.net~bzr/bzr/trunk', |
|
209 |
'bzr+http://bazaar.launchpad.net~bzr/bzr/trunk', |
|
210 |
'http://bazaar.launchpad.net~bzr/bzr/trunk']) |