bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
0.4.1
by Martin Pool
 Start lp-register command  | 
1  | 
# Copyright (C) 2006 by 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  | 
||
| 
0.4.8
by Martin Pool
 More instrumentation of xmlrpc requests  | 
17  | 
import base64  | 
| 
0.4.13
by Martin Pool
 Update xmlrpc api to pass product name as a parameter.  | 
18  | 
import os  | 
| 
0.4.8
by Martin Pool
 More instrumentation of xmlrpc requests  | 
19  | 
from StringIO import StringIO  | 
| 
0.4.5
by Martin Pool
 Add structured test for parameters passed through xmlrpc  | 
20  | 
import xmlrpclib  | 
21  | 
||
| 
0.4.13
by Martin Pool
 Update xmlrpc api to pass product name as a parameter.  | 
22  | 
from bzrlib.tests import TestCase, TestSkipped  | 
| 
0.4.1
by Martin Pool
 Start lp-register command  | 
23  | 
|
| 
0.4.5
by Martin Pool
 Add structured test for parameters passed through xmlrpc  | 
24  | 
# local import
 | 
| 
0.4.22
by Martin Pool
 (register-branch) Update tests to be in-process calls to a mock server.  | 
25  | 
from lp_registration import (  | 
| 
0.4.26
by Martin Pool
 (register-branch) Add test for link_branch_to_bug and fix its parameters  | 
26  | 
BaseRequest,  | 
27  | 
BranchBugLinkRequest,  | 
|
28  | 
BranchRegistrationRequest,  | 
|
29  | 
LaunchpadService,  | 
|
30  | 
        )
 | 
|
| 
0.4.5
by Martin Pool
 Add structured test for parameters passed through xmlrpc  | 
31  | 
|
| 
0.4.7
by Martin Pool
 Start making provision to test using a mock xmlrpc transport.  | 
32  | 
|
| 
0.4.12
by Martin Pool
 doc  | 
33  | 
# TODO: Test that the command-line client, making sure that it'll pass the
 | 
34  | 
# request through to a dummy transport, and that the transport will validate
 | 
|
35  | 
# the results passed in.  Not sure how to get the transport object back out to
 | 
|
36  | 
# validate that its OK - may not be necessary.
 | 
|
37  | 
||
38  | 
# TODO: Add test for (and implement) other command-line options to set
 | 
|
| 
0.4.14
by Martin Pool
 Update xmlrpc api  | 
39  | 
# project, author_email, description.
 | 
| 
0.4.12
by Martin Pool
 doc  | 
40  | 
|
41  | 
# TODO: project_id is not properly handled -- must be passed in rpc or path.
 | 
|
42  | 
||
| 
0.4.8
by Martin Pool
 More instrumentation of xmlrpc requests  | 
43  | 
class InstrumentedXMLRPCConnection(object):  | 
44  | 
"""Stands in place of an http connection for the purposes of testing"""  | 
|
45  | 
||
46  | 
def __init__(self, testcase):  | 
|
47  | 
self.testcase = testcase  | 
|
48  | 
||
49  | 
def getreply(self):  | 
|
50  | 
"""Fake the http reply.  | 
|
51  | 
||
52  | 
        :returns: (errcode, errmsg, headers)
 | 
|
53  | 
        """
 | 
|
54  | 
return (200, 'OK', [])  | 
|
55  | 
||
56  | 
def getfile(self):  | 
|
57  | 
"""Return a fake file containing the response content."""  | 
|
58  | 
return StringIO('''\  | 
|
59  | 
<?xml version="1.0" ?>
 | 
|
60  | 
<methodResponse>
 | 
|
| 
0.4.11
by Martin Pool
 Check the correct params are seen by the server  | 
61  | 
    <params>
 | 
62  | 
        <param>
 | 
|
63  | 
            <value>
 | 
|
64  | 
                <string>victoria dock</string>
 | 
|
65  | 
            </value>
 | 
|
66  | 
        </param>
 | 
|
67  | 
    </params>
 | 
|
| 
0.4.8
by Martin Pool
 More instrumentation of xmlrpc requests  | 
68  | 
</methodResponse>''')  | 
69  | 
||
70  | 
||
71  | 
||
| 
0.4.7
by Martin Pool
 Start making provision to test using a mock xmlrpc transport.  | 
72  | 
class InstrumentedXMLRPCTransport(xmlrpclib.Transport):  | 
73  | 
||
74  | 
def __init__(self, testcase):  | 
|
75  | 
self.testcase = testcase  | 
|
76  | 
||
77  | 
def make_connection(self, host):  | 
|
78  | 
host, http_headers, x509 = self.get_host_info(host)  | 
|
79  | 
test = self.testcase  | 
|
| 
0.4.10
by Martin Pool
 Move test-specific values out of InstrumentedXMLRPCTransport  | 
80  | 
self.connected_host = host  | 
| 
0.4.7
by Martin Pool
 Start making provision to test using a mock xmlrpc transport.  | 
81  | 
auth_hdrs = [v for k,v in http_headers if k == 'Authorization']  | 
82  | 
assert len(auth_hdrs) == 1  | 
|
83  | 
authinfo = auth_hdrs[0]  | 
|
84  | 
expected_auth = 'testuser@launchpad.net:testpassword'  | 
|
85  | 
test.assertEquals(authinfo,  | 
|
86  | 
'Basic ' + base64.encodestring(expected_auth).strip())  | 
|
| 
0.4.8
by Martin Pool
 More instrumentation of xmlrpc requests  | 
87  | 
return InstrumentedXMLRPCConnection(test)  | 
| 
0.4.7
by Martin Pool
 Start making provision to test using a mock xmlrpc transport.  | 
88  | 
|
89  | 
def send_request(self, connection, handler_path, request_body):  | 
|
90  | 
test = self.testcase  | 
|
91  | 
self.got_request = True  | 
|
92  | 
||
93  | 
def send_host(self, conn, host):  | 
|
94  | 
        pass
 | 
|
95  | 
||
96  | 
def send_user_agent(self, conn):  | 
|
97  | 
        # TODO: send special user agent string, including bzrlib version
 | 
|
98  | 
        # number
 | 
|
99  | 
        pass
 | 
|
100  | 
||
101  | 
def send_content(self, conn, request_body):  | 
|
102  | 
unpacked, method = xmlrpclib.loads(request_body)  | 
|
| 
0.4.10
by Martin Pool
 Move test-specific values out of InstrumentedXMLRPCTransport  | 
103  | 
assert None not in unpacked, \  | 
104  | 
"xmlrpc result %r shouldn't contain None" % (unpacked,)  | 
|
105  | 
self.sent_params = unpacked  | 
|
| 
0.4.7
by Martin Pool
 Start making provision to test using a mock xmlrpc transport.  | 
106  | 
|
107  | 
||
| 
0.4.22
by Martin Pool
 (register-branch) Update tests to be in-process calls to a mock server.  | 
108  | 
class MockLaunchpadService(LaunchpadService):  | 
109  | 
||
110  | 
def send_request(self, method_name, method_params):  | 
|
111  | 
"""Stash away the method details rather than sending them to a real server"""  | 
|
112  | 
self.called_method_name = method_name  | 
|
113  | 
self.called_method_params = method_params  | 
|
114  | 
||
115  | 
||
| 
0.4.1
by Martin Pool
 Start lp-register command  | 
116  | 
class TestBranchRegistration(TestCase):  | 
| 
0.4.4
by Martin Pool
 Start forming xmlrpc requests  | 
117  | 
SAMPLE_URL = 'http://bazaar-vcs.org/bzr/bzr.dev/'  | 
| 
0.4.6
by Martin Pool
 Put the rest of the parameters into the registration request.  | 
118  | 
SAMPLE_OWNER = 'jhacker@foo.com'  | 
119  | 
SAMPLE_BRANCH_ID = 'bzr.dev'  | 
|
| 
0.4.4
by Martin Pool
 Start forming xmlrpc requests  | 
120  | 
|
| 
0.4.23
by Martin Pool
 (register-branch) fix ordering of parameters and restore transport-level test.  | 
121  | 
def setUp(self):  | 
122  | 
super(TestBranchRegistration, self).setUp()  | 
|
123  | 
        # make sure we have a reproducible standard environment
 | 
|
124  | 
if 'BZR_LP_XMLRPC_URL' in os.environ:  | 
|
125  | 
del os.environ['BZR_LP_XMLRPC_URL']  | 
|
126  | 
||
| 
0.4.22
by Martin Pool
 (register-branch) Update tests to be in-process calls to a mock server.  | 
127  | 
def test_register_help(self):  | 
128  | 
"""register-branch accepts --help"""  | 
|
| 
0.4.2
by Martin Pool
 Rename command to 'register-branch'  | 
129  | 
out, err = self.run_bzr('register-branch', '--help')  | 
130  | 
self.assertContainsRe(out, r'Register a branch')  | 
|
131  | 
||
| 
0.4.22
by Martin Pool
 (register-branch) Update tests to be in-process calls to a mock server.  | 
132  | 
def test_register_no_url(self):  | 
133  | 
"""register-branch command requires parameters"""  | 
|
| 
0.4.3
by Martin Pool
 More command line processing  | 
134  | 
self.run_bzr('register-branch', retcode=3)  | 
135  | 
||
| 
1668.1.12
by Martin Pool
 (launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.  | 
136  | 
def test_register_dry_run(self):  | 
137  | 
out, err = self.run_bzr('register-branch',  | 
|
138  | 
'http://test-server.com/bzr/branch',  | 
|
139  | 
'--dry-run')  | 
|
140  | 
self.assertEquals(out, 'Branch registered.\n')  | 
|
| 
0.4.4
by Martin Pool
 Start forming xmlrpc requests  | 
141  | 
|
| 
0.4.23
by Martin Pool
 (register-branch) fix ordering of parameters and restore transport-level test.  | 
142  | 
def test_onto_transport(self):  | 
| 
0.4.7
by Martin Pool
 Start making provision to test using a mock xmlrpc transport.  | 
143  | 
"""Test how the request is sent by transmitting across a mock Transport"""  | 
| 
0.4.23
by Martin Pool
 (register-branch) fix ordering of parameters and restore transport-level test.  | 
144  | 
        # use a real transport, but intercept at the http/xml layer
 | 
| 
0.4.30
by Martin Pool
 Fix wierd syntax errors in test  | 
145  | 
transport = InstrumentedXMLRPCTransport(self)  | 
146  | 
service = LaunchpadService(transport)  | 
|
| 
0.4.23
by Martin Pool
 (register-branch) fix ordering of parameters and restore transport-level test.  | 
147  | 
service.registrant_email = 'testuser@launchpad.net'  | 
148  | 
service.registrant_password = 'testpassword'  | 
|
| 
0.4.7
by Martin Pool
 Start making provision to test using a mock xmlrpc transport.  | 
149  | 
rego = BranchRegistrationRequest('http://test-server.com/bzr/branch',  | 
| 
0.4.23
by Martin Pool
 (register-branch) fix ordering of parameters and restore transport-level test.  | 
150  | 
'branch-id',  | 
151  | 
'my test branch',  | 
|
152  | 
'description',  | 
|
153  | 
'author@launchpad.net',  | 
|
154  | 
'product')  | 
|
| 
0.4.20
by Bjorn Tillenius
 try to fix the tests.  | 
155  | 
rego.submit(service)  | 
| 
0.4.10
by Martin Pool
 Move test-specific values out of InstrumentedXMLRPCTransport  | 
156  | 
self.assertEquals(transport.connected_host, 'xmlrpc.launchpad.net')  | 
| 
0.4.14
by Martin Pool
 Update xmlrpc api  | 
157  | 
self.assertEquals(len(transport.sent_params), 6)  | 
| 
0.4.11
by Martin Pool
 Check the correct params are seen by the server  | 
158  | 
self.assertEquals(transport.sent_params,  | 
| 
0.4.23
by Martin Pool
 (register-branch) fix ordering of parameters and restore transport-level test.  | 
159  | 
('http://test-server.com/bzr/branch', # branch_url  | 
160  | 
'branch-id', # branch_name  | 
|
161  | 
'my test branch', # branch_title  | 
|
162  | 
'description',  | 
|
163  | 
'author@launchpad.net',  | 
|
164  | 
'product'))  | 
|
| 
0.4.8
by Martin Pool
 More instrumentation of xmlrpc requests  | 
165  | 
self.assertTrue(transport.got_request)  | 
| 
0.4.13
by Martin Pool
 Update xmlrpc api to pass product name as a parameter.  | 
166  | 
|
| 
0.4.22
by Martin Pool
 (register-branch) Update tests to be in-process calls to a mock server.  | 
167  | 
def test_subclass_request(self):  | 
168  | 
"""Define a new type of xmlrpc request"""  | 
|
169  | 
class DummyRequest(BaseRequest):  | 
|
170  | 
_methodname = 'dummy_request'  | 
|
171  | 
def _request_params(self):  | 
|
172  | 
return (42,)  | 
|
173  | 
||
174  | 
service = MockLaunchpadService()  | 
|
175  | 
service.registrant_email = 'test@launchpad.net'  | 
|
176  | 
service.registrant_password = ''  | 
|
177  | 
request = DummyRequest()  | 
|
178  | 
request.submit(service)  | 
|
179  | 
self.assertEquals(service.called_method_name, 'dummy_request')  | 
|
180  | 
self.assertEquals(service.called_method_params, (42,))  | 
|
181  | 
||
| 
0.4.24
by Martin Pool
 (register-branch) additional test case against mock server  | 
182  | 
def test_mock_server_registration(self):  | 
183  | 
"""Send registration to mock server"""  | 
|
184  | 
test_case = self  | 
|
185  | 
class MockRegistrationService(MockLaunchpadService):  | 
|
186  | 
def send_request(self, method_name, method_params):  | 
|
187  | 
test_case.assertEquals(method_name, "register_branch")  | 
|
188  | 
test_case.assertEquals(list(method_params),  | 
|
189  | 
['url', 'name', 'title', 'description', 'email', 'name'])  | 
|
190  | 
return 'result'  | 
|
191  | 
service = MockRegistrationService()  | 
|
192  | 
rego = BranchRegistrationRequest('url', 'name', 'title',  | 
|
193  | 
'description', 'email', 'name')  | 
|
194  | 
result = rego.submit(service)  | 
|
195  | 
self.assertEquals(result, 'result')  | 
|
| 
0.4.25
by Martin Pool
 (register-branch) additional test for registration with defaults  | 
196  | 
|
197  | 
def test_mock_server_registration_with_defaults(self):  | 
|
198  | 
"""Send registration to mock server"""  | 
|
199  | 
test_case = self  | 
|
200  | 
class MockRegistrationService(MockLaunchpadService):  | 
|
201  | 
def send_request(self, method_name, method_params):  | 
|
202  | 
test_case.assertEquals(method_name, "register_branch")  | 
|
203  | 
test_case.assertEquals(list(method_params),  | 
|
204  | 
['http://server/branch', 'branch', '', '', '', ''])  | 
|
205  | 
return 'result'  | 
|
206  | 
service = MockRegistrationService()  | 
|
207  | 
rego = BranchRegistrationRequest('http://server/branch')  | 
|
208  | 
result = rego.submit(service)  | 
|
209  | 
self.assertEquals(result, 'result')  | 
|
| 
0.4.26
by Martin Pool
 (register-branch) Add test for link_branch_to_bug and fix its parameters  | 
210  | 
|
211  | 
def test_mock_bug_branch_link(self):  | 
|
212  | 
"""Send bug-branch link to mock server"""  | 
|
213  | 
test_case = self  | 
|
214  | 
class MockService(MockLaunchpadService):  | 
|
215  | 
def send_request(self, method_name, method_params):  | 
|
216  | 
test_case.assertEquals(method_name, "link_branch_to_bug")  | 
|
217  | 
test_case.assertEquals(list(method_params),  | 
|
218  | 
['http://server/branch', 1234, ''])  | 
|
219  | 
return 'http://launchpad.net/bug/1234'  | 
|
220  | 
service = MockService()  | 
|
221  | 
rego = BranchBugLinkRequest('http://server/branch', 1234)  | 
|
222  | 
result = rego.submit(service)  | 
|
223  | 
self.assertEquals(result, 'http://launchpad.net/bug/1234')  |