/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2007-2011 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
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
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
19
import os
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
20
import xmlrpclib
21
2245.8.3 by Martin Pool
Start adding indirection transport
22
from bzrlib import (
5609.24.11 by John Arbash Meinel
If someone uses -Dlaunchpad, use the 'official' URL instead of the local one.
23
    debug,
2245.8.4 by Martin Pool
lp:/// indirection works
24
    errors,
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
25
    tests,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
26
    transport,
2245.8.3 by Martin Pool
Start adding indirection transport
27
    )
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
28
from bzrlib.branch import Branch
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
29
from bzrlib.directory_service import directories
3777.1.18 by Aaron Bentley
Fix None handling wrt auth upgrades
30
from bzrlib.tests import (
5967.12.5 by Martin Pool
Update launchpad plugin for features under tests.features
31
    features,
3777.1.18 by Aaron Bentley
Fix None handling wrt auth upgrades
32
    TestCaseInTempDir,
33
    TestCaseWithMemoryTransport
34
)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
35
from bzrlib.plugins.launchpad import (
36
    _register_directory,
37
    lp_registration,
38
    )
3251.4.3 by Aaron Bentley
More renames and cleanups
39
from bzrlib.plugins.launchpad.lp_directory import (
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
40
    LaunchpadDirectory)
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
41
from bzrlib.plugins.launchpad.account import get_lp_login, set_lp_login
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
42
from bzrlib.tests import http_server
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
43
44
45
def load_tests(standard_tests, module, loader):
46
    result = loader.suiteClass()
47
    t_tests, remaining_tests = tests.split_suite_by_condition(
48
        standard_tests, tests.condition_isinstance((
4776.2.6 by Vincent Ladeuil
Fixed as per review comments.
49
                TestXMLRPCTransport,
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
50
                )))
51
    transport_scenarios = [
52
        ('http', dict(server_class=PreCannedHTTPServer,)),
53
        ]
5967.12.5 by Martin Pool
Update launchpad plugin for features under tests.features
54
    if features.HTTPSServerFeature.available():
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
55
        transport_scenarios.append(
56
            ('https', dict(server_class=PreCannedHTTPSServer,)),
57
            )
58
    tests.multiply_tests(t_tests, transport_scenarios, result)
59
60
    # No parametrization for the remaining tests
61
    result.addTests(remaining_tests)
62
63
    return result
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
64
65
66
class FakeResolveFactory(object):
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
67
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
68
    def __init__(self, test, expected_path, result):
69
        self._test = test
70
        self._expected_path = expected_path
71
        self._result = result
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
72
        self._submitted = False
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
73
74
    def __call__(self, path):
75
        self._test.assertEqual(self._expected_path, path)
76
        return self
77
78
    def submit(self, service):
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
79
        self._service_url = service.service_url
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
80
        self._submitted = True
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
81
        return self._result
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
82
2245.8.7 by Martin Pool
small review cleanups
83
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
84
class LocalDirectoryURLTests(TestCaseInTempDir):
85
    """Tests for branch urls that we try to pass through local resolution."""
86
87
    def assertResolve(self, expected, url, submitted=False):
88
        path = url[url.index(':')+1:].lstrip('/')
89
        factory = FakeResolveFactory(self, path,
90
                    dict(urls=['bzr+ssh://fake-resolved']))
91
        directory = LaunchpadDirectory()
92
        self.assertEqual(expected,
93
            directory._resolve(url, factory, _lp_login='user'))
94
        # We are testing local resolution, and the fallback when necessary.
95
        self.assertEqual(submitted, factory._submitted)
96
97
    def test_short_form(self):
98
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
99
                           'lp:apt')
100
101
    def test_two_part_form(self):
102
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt/2.2',
103
                           'lp:apt/2.2')
104
105
    def test_two_part_plus_subdir(self):
106
        # We allow you to pass more than just what resolves. That way you can
107
        # do things like "bzr log lp:apt/2.2/BUGS"
108
        # Though the virtual FS implementation currently aborts when given a
109
        # URL like this, rather than letting you recurse upwards to find the
110
        # real branch at lp:apt/2.2
111
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt/2.2/BUGS',
112
                           'lp:apt/2.2/BUGS')
113
114
    def test_user_expansion(self):
115
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/~user/apt/foo',
116
                           'lp:~/apt/foo')
117
118
    def test_ubuntu(self):
119
        # Confirmed against xmlrpc. If you don't have a ~user, xmlrpc doesn't
120
        # care that you are asking for 'ubuntu'
121
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/ubuntu',
122
                           'lp:ubuntu')
123
6191.2.1 by Martin Pool
Avoid NameError when given an invalid ubuntu: launchpad url
124
    def test_ubuntu_invalid(self):
125
        """Invalid ubuntu urls don't crash.
126
127
        :seealso: http://pad.lv/843900
128
        """
129
        # This ought to be natty-updates.
130
        self.assertRaises(errors.InvalidURL,
131
            self.assertResolve,
132
            '',
133
            'ubuntu:natty/updates/smartpm')
134
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
135
    def test_ubuntu_apt(self):
136
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/apt',
137
                           'lp:ubuntu/apt')
138
139
    def test_ubuntu_natty_apt(self):
140
        self.assertResolve(
141
            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/apt',
142
            'lp:ubuntu/natty/apt')
143
144
    def test_ubuntu_natty_apt_filename(self):
145
        self.assertResolve(
146
            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/apt/filename',
147
            'lp:ubuntu/natty/apt/filename')
148
149
    def test_user_two_part(self):
150
        # We fall back to the ResolveFactory. The real Launchpad one will raise
151
        # InvalidURL for this case.
152
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/apt',
153
                           submitted=True)
154
155
    def test_user_three_part(self):
156
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/~jameinel/apt/foo',
157
                           'lp:~jameinel/apt/foo')
158
159
    def test_user_three_part_plus_filename(self):
160
        self.assertResolve(
161
            'bzr+ssh://bazaar.launchpad.net/~jameinel/apt/foo/fname',
162
            'lp:~jameinel/apt/foo/fname')
163
164
    def test_user_ubuntu_two_part(self):
165
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/ubuntu',
166
                           submitted=True)
167
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/debian',
168
                           submitted=True)
169
170
    def test_user_ubuntu_three_part(self):
171
        self.assertResolve('bzr+ssh://fake-resolved',
172
                           'lp:~jameinel/ubuntu/natty', submitted=True)
173
        self.assertResolve('bzr+ssh://fake-resolved',
174
                           'lp:~jameinel/debian/sid', submitted=True)
175
176
    def test_user_ubuntu_four_part(self):
177
        self.assertResolve('bzr+ssh://fake-resolved',
178
                           'lp:~jameinel/ubuntu/natty/project', submitted=True)
179
        self.assertResolve('bzr+ssh://fake-resolved',
180
                           'lp:~jameinel/debian/sid/project', submitted=True)
181
182
    def test_user_ubuntu_five_part(self):
183
        self.assertResolve(
184
            'bzr+ssh://bazaar.launchpad.net/~jameinel/ubuntu/natty/apt/branch',
185
            'lp:~jameinel/ubuntu/natty/apt/branch')
186
        self.assertResolve(
187
            'bzr+ssh://bazaar.launchpad.net/~jameinel/debian/sid/apt/branch',
188
            'lp:~jameinel/debian/sid/apt/branch')
189
190
    def test_user_ubuntu_five_part_plus_subdir(self):
191
        self.assertResolve(
192
            'bzr+ssh://bazaar.launchpad.net/~jameinel/ubuntu/natty/apt/branch/f',
193
            'lp:~jameinel/ubuntu/natty/apt/branch/f')
194
        self.assertResolve(
195
            'bzr+ssh://bazaar.launchpad.net/~jameinel/debian/sid/apt/branch/f',
196
            'lp:~jameinel/debian/sid/apt/branch/f')
197
198
    def test_handles_special_lp(self):
199
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt', 'lp:apt')
200
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
201
                           'lp:///apt')
202
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
203
                           'lp://production/apt')
204
        self.assertResolve('bzr+ssh://bazaar.launchpad.dev/+branch/apt',
205
                           'lp://dev/apt')
206
        self.assertResolve('bzr+ssh://bazaar.staging.launchpad.net/+branch/apt',
207
                           'lp://staging/apt')
208
        self.assertResolve('bzr+ssh://bazaar.qastaging.launchpad.net/+branch/apt',
209
                           'lp://qastaging/apt')
210
        self.assertResolve('bzr+ssh://bazaar.demo.launchpad.net/+branch/apt',
211
                           'lp://demo/apt')
212
5609.24.11 by John Arbash Meinel
If someone uses -Dlaunchpad, use the 'official' URL instead of the local one.
213
    def test_debug_launchpad_uses_resolver(self):
214
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/bzr',
215
                           'lp:bzr', submitted=False)
216
        debug.debug_flags.add('launchpad')
217
        self.addCleanup(debug.debug_flags.discard, 'launchpad')
218
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:bzr', submitted=True)
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
219
220
3777.1.18 by Aaron Bentley
Fix None handling wrt auth upgrades
221
class DirectoryUrlTests(TestCaseInTempDir):
3251.4.3 by Aaron Bentley
More renames and cleanups
222
    """Tests for branch urls through Launchpad.net directory"""
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
223
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
224
    def test_short_form(self):
225
        """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.
226
        factory = FakeResolveFactory(
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
227
            self, 'apt', dict(urls=[
228
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
229
        directory = LaunchpadDirectory()
2898.4.8 by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets
230
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
231
                          directory._resolve('lp:apt', factory))
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
232
        # Make sure that resolve went to the production server.
5243.1.1 by Martin
Use the production server in the launchpad plugin rather than edge
233
        self.assertEquals('https://xmlrpc.launchpad.net/bazaar/',
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
234
                          factory._service_url)
235
5615.2.1 by Jelmer Vernooij
Support the 'qastaging' instance of Launchpad.
236
    def test_qastaging(self):
237
        """A launchpad url should map to a http url"""
238
        factory = FakeResolveFactory(
239
            self, 'apt', dict(urls=[
240
                    'http://bazaar.qastaging.launchpad.net/~apt/apt/devel']))
241
        url = 'lp://qastaging/apt'
242
        directory = LaunchpadDirectory()
243
        self.assertEquals('http://bazaar.qastaging.launchpad.net/~apt/apt/devel',
244
                          directory._resolve(url, factory))
245
        # Make sure that resolve went to the qastaging server.
246
        self.assertEquals('https://xmlrpc.qastaging.launchpad.net/bazaar/',
247
                          factory._service_url)
248
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
249
    def test_staging(self):
250
        """A launchpad url should map to a http url"""
251
        factory = FakeResolveFactory(
252
            self, 'apt', dict(urls=[
253
                    'http://bazaar.staging.launchpad.net/~apt/apt/devel']))
254
        url = 'lp://staging/apt'
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
255
        directory = LaunchpadDirectory()
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
256
        self.assertEquals('http://bazaar.staging.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
257
                          directory._resolve(url, factory))
3193.5.2 by Tim Penhey
Updated the tests to handle unknown launchpad instances.
258
        # Make sure that resolve went to the staging server.
259
        self.assertEquals('https://xmlrpc.staging.launchpad.net/bazaar/',
260
                          factory._service_url)
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
261
3251.4.3 by Aaron Bentley
More renames and cleanups
262
    def test_url_from_directory(self):
2245.8.3 by Martin Pool
Start adding indirection transport
263
        """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.
264
        factory = FakeResolveFactory(
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
265
            self, 'apt', dict(urls=[
266
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
267
        directory = LaunchpadDirectory()
2898.4.8 by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets
268
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
269
                          directory._resolve('lp:///apt', factory))
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
270
3251.4.3 by Aaron Bentley
More renames and cleanups
271
    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
272
        factory = FakeResolveFactory(
273
            self, 'apt', dict(urls=[
274
                    'bad-scheme://bazaar.launchpad.net/~apt/apt/devel',
275
                    'http://bazaar.launchpad.net/~apt/apt/devel',
276
                    'http://another/location']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
277
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
278
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
279
                          directory._resolve('lp:///apt', factory))
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
280
3251.4.3 by Aaron Bentley
More renames and cleanups
281
    def test_directory_no_matching_schemes(self):
2898.4.3 by James Henstridge
Make launchpad_transport_indirect() use XMLRPC to resolve the lp: URL.
282
        # If the XMLRPC call does not return any protocols we support,
283
        # invalidURL is raised.
284
        factory = FakeResolveFactory(
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
285
            self, 'apt', dict(urls=[
286
                    'bad-scheme://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
287
        directory = LaunchpadDirectory()
2898.4.11 by James Henstridge
Switch back to RedirectRequested based implementation.
288
        self.assertRaises(errors.InvalidURL,
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
289
                          directory._resolve, 'lp:///apt', factory)
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
290
3251.4.3 by Aaron Bentley
More renames and cleanups
291
    def test_directory_fault(self):
2898.4.4 by James Henstridge
Changes to account for modifications to the XMLRPC API.
292
        # Test that XMLRPC faults get converted to InvalidURL errors.
293
        factory = FakeResolveFactory(self, 'apt', None)
294
        def submit(service):
295
            raise xmlrpclib.Fault(42, 'something went wrong')
296
        factory.submit = submit
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
297
        directory = LaunchpadDirectory()
2898.4.11 by James Henstridge
Switch back to RedirectRequested based implementation.
298
        self.assertRaises(errors.InvalidURL,
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
299
                          directory._resolve, 'lp:///apt', factory)
2245.8.4 by Martin Pool
lp:/// indirection works
300
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
301
    def test_skip_bzr_ssh_launchpad_net_when_anonymous(self):
302
        # Test that bzr+ssh://bazaar.launchpad.net gets skipped if
303
        # Bazaar does not know the user's Launchpad ID:
304
        self.assertEqual(None, get_lp_login())
305
        factory = FakeResolveFactory(
306
            self, 'apt', dict(urls=[
307
                    'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
308
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
309
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
310
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
311
                          directory._resolve('lp:///apt', factory))
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
312
3031.2.2 by jml at canonical
Failing test for skipping SFTP.
313
    def test_skip_sftp_launchpad_net_when_anonymous(self):
314
        # Test that sftp://bazaar.launchpad.net gets skipped if
315
        # Bazaar does not know the user's Launchpad ID:
316
        self.assertEqual(None, get_lp_login())
317
        factory = FakeResolveFactory(
318
            self, 'apt', dict(urls=[
319
                    'sftp://bazaar.launchpad.net/~apt/apt/devel',
320
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
321
        directory = LaunchpadDirectory()
3031.2.2 by jml at canonical
Failing test for skipping SFTP.
322
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
323
                          directory._resolve('lp:///apt', factory))
3031.2.2 by jml at canonical
Failing test for skipping SFTP.
324
5609.24.8 by John Arbash Meinel
Fix the launchpad-login tests. And fix a bad commit typo.
325
    def test_with_login_avoid_resolve_factory(self):
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
326
        # Test that bzr+ssh URLs get rewritten to include the user's
327
        # Launchpad ID (assuming we know the Launchpad ID).
328
        factory = FakeResolveFactory(
329
            self, 'apt', dict(urls=[
5609.24.8 by John Arbash Meinel
Fix the launchpad-login tests. And fix a bad commit typo.
330
                    'bzr+ssh://my-super-custom/special/devel',
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
331
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
332
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
333
        self.assertEquals(
5609.24.8 by John Arbash Meinel
Fix the launchpad-login tests. And fix a bad commit typo.
334
            'bzr+ssh://bazaar.launchpad.net/+branch/apt',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
335
            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
336
337
    def test_no_rewrite_of_other_bzr_ssh(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
338
        # Test that we don't rewrite bzr+ssh URLs for other
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
339
        self.assertEqual(None, get_lp_login())
340
        factory = FakeResolveFactory(
341
            self, 'apt', dict(urls=[
342
                    'bzr+ssh://example.com/~apt/apt/devel',
343
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
344
        directory = LaunchpadDirectory()
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
345
        self.assertEquals('bzr+ssh://example.com/~apt/apt/devel',
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
346
                          directory._resolve('lp:///apt', factory))
2898.4.9 by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL
347
2245.8.4 by Martin Pool
lp:/// indirection works
348
    # TODO: check we get an error if the url is unreasonable
3251.4.3 by Aaron Bentley
More renames and cleanups
349
    def test_error_for_bad_url(self):
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
350
        directory = LaunchpadDirectory()
2245.8.4 by Martin Pool
lp:/// indirection works
351
        self.assertRaises(errors.InvalidURL,
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
352
            directory._resolve, 'lp://ratotehunoahu')
2898.4.12 by James Henstridge
Add tests that redirects get issued by appropriate transport methods.
353
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
354
    def test_resolve_tilde_to_user(self):
355
        factory = FakeResolveFactory(
356
            self, '~username/apt/test', dict(urls=[
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
357
                'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
358
        directory = LaunchpadDirectory()
359
        self.assertEquals(
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
360
            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
361
            directory._resolve('lp:~/apt/test', factory, _lp_login='username'))
362
        # Should also happen when the login is just set by config
363
        set_lp_login('username')
364
        self.assertEquals(
5609.24.9 by John Arbash Meinel
A bunch more tests and bug fixes for the local resolution.
365
            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
366
            directory._resolve('lp:~/apt/test', factory))
367
368
    def test_tilde_fails_no_login(self):
369
        factory = FakeResolveFactory(
370
            self, '~username/apt/test', dict(urls=[
371
                    'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
372
        self.assertIs(None, get_lp_login())
373
        directory = LaunchpadDirectory()
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
374
        self.assertRaises(errors.InvalidURL,
375
                          directory._resolve, 'lp:~/apt/test', factory)
5361.1.1 by John Arbash Meinel
Handle a simple ~ in lp: urls.
376
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
377
3251.4.3 by Aaron Bentley
More renames and cleanups
378
class DirectoryOpenBranchTests(TestCaseWithMemoryTransport):
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
379
3251.4.3 by Aaron Bentley
More renames and cleanups
380
    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.
381
        # Test that opening an lp: branch redirects to the real location.
382
        target_branch = self.make_branch('target')
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
383
        class FooService(object):
384
            """A directory service that maps the name to a FILE url"""
385
386
            def look_up(self, name, url):
387
                if 'lp:///apt' == url:
388
                    return target_branch.base.rstrip('/')
3251.4.2 by Aaron Bentley
Clean up Launchpad directory service code
389
                return '!unexpected look_up value!'
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
390
391
        directories.remove('lp:')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
392
        directories.remove('ubuntu:')
393
        directories.remove('debianlp:')
3251.4.1 by Aaron Bentley
Convert LP transport into directory service
394
        directories.register('lp:', FooService, 'Map lp URLs to local urls')
3251.4.2 by Aaron Bentley
Clean up Launchpad directory service code
395
        self.addCleanup(_register_directory)
4985.2.1 by Vincent Ladeuil
Deploy addAttrCleanup on the whole test suite.
396
        self.addCleanup(directories.remove, 'lp:')
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
397
        t = transport.get_transport('lp:///apt')
398
        branch = Branch.open_from_transport(t)
2898.4.17 by James Henstridge
Add a test that the redirect actually occurs when opening an lp: URL.
399
        self.assertEqual(target_branch.base, branch.base)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
400
401
402
class PredefinedRequestHandler(http_server.TestingHTTPRequestHandler):
403
    """Request handler for a unique and pre-defined request.
404
405
    The only thing we care about here is that we receive a connection. But
406
    since we want to dialog with a real http client, we have to send it correct
407
    responses.
408
409
    We expect to receive a *single* request nothing more (and we won't even
410
    check what request it is), the tests will recognize us from our response.
411
    """
412
413
    def handle_one_request(self):
414
        tcs = self.server.test_case_server
415
        requestline = self.rfile.readline()
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
416
        self.MessageClass(self.rfile, 0)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
417
        if requestline.startswith('POST'):
418
            # The body should be a single line (or we don't know where it ends
419
            # and we don't want to issue a blocking read)
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
420
            self.rfile.readline()
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
421
422
        self.wfile.write(tcs.canned_response)
423
4776.2.6 by Vincent Ladeuil
Fixed as per review comments.
424
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
425
class PreCannedServerMixin(object):
426
427
    def __init__(self):
428
        super(PreCannedServerMixin, self).__init__(
429
            request_handler=PredefinedRequestHandler)
430
        # Bytes read and written by the server
431
        self.bytes_read = 0
432
        self.bytes_written = 0
433
        self.canned_response = None
434
435
436
class PreCannedHTTPServer(PreCannedServerMixin, http_server.HttpServer):
437
    pass
438
439
5967.12.5 by Martin Pool
Update launchpad plugin for features under tests.features
440
if features.HTTPSServerFeature.available():
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
441
    from bzrlib.tests import https_server
442
    class PreCannedHTTPSServer(PreCannedServerMixin, https_server.HTTPSServer):
443
        pass
444
445
4776.2.6 by Vincent Ladeuil
Fixed as per review comments.
446
class TestXMLRPCTransport(tests.TestCase):
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
447
448
    # set by load_tests
449
    server_class = None
450
451
    def setUp(self):
452
        tests.TestCase.setUp(self)
453
        self.server = self.server_class()
4934.3.3 by Martin Pool
Rename Server.setUp to Server.start_server
454
        self.server.start_server()
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
455
        # Ensure we don't clobber env
5570.3.6 by Vincent Ladeuil
Get rid of all _captureVar() calls, no test failures, pfew.
456
        self.overrideEnv('BZR_LP_XMLRPC_URL', None)
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
457
458
    def tearDown(self):
4934.3.1 by Martin Pool
Rename Server.tearDown to .stop_server
459
        self.server.stop_server()
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
460
        tests.TestCase.tearDown(self)
461
462
    def set_canned_response(self, server, path):
463
        response_format = '''HTTP/1.1 200 OK\r
464
Date: Tue, 11 Jul 2006 04:32:56 GMT\r
465
Server: Apache/2.0.54 (Fedora)\r
466
Last-Modified: Sun, 23 Apr 2006 19:35:20 GMT\r
467
ETag: "56691-23-38e9ae00"\r
468
Accept-Ranges: bytes\r
469
Content-Length: %(length)d\r
470
Connection: close\r
471
Content-Type: text/plain; charset=UTF-8\r
472
\r
473
<?xml version='1.0'?>
474
<methodResponse>
475
<params>
476
<param>
477
<value><struct>
478
<member>
479
<name>urls</name>
480
<value><array><data>
481
<value><string>bzr+ssh://bazaar.launchpad.net/%(path)s</string></value>
482
<value><string>http://bazaar.launchpad.net/%(path)s</string></value>
483
</data></array></value>
484
</member>
485
</struct></value>
486
</param>
487
</params>
488
</methodResponse>
489
'''
490
        length = 334 + 2 * len(path)
491
        server.canned_response = response_format % dict(length=length,
492
                                                        path=path)
493
4776.2.3 by Vincent Ladeuil
Add NEWS entry.
494
    def do_request(self, server_url):
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
495
        os.environ['BZR_LP_XMLRPC_URL'] = self.server.get_url()
496
        service = lp_registration.LaunchpadService()
497
        resolve = lp_registration.ResolveLaunchpadPathRequest('bzr')
498
        result = resolve.submit(service)
4776.2.3 by Vincent Ladeuil
Add NEWS entry.
499
        return result
500
501
    def test_direct_request(self):
502
        self.set_canned_response(self.server, '~bzr-pqm/bzr/bzr.dev')
503
        result = self.do_request(self.server.get_url())
4776.2.2 by Vincent Ladeuil
Start testing the XMLRPC transport re-implemented on top of _urllib2_wrappers.
504
        urls = result.get('urls', None)
505
        self.assertIsNot(None, urls)
506
        self.assertEquals(
507
            ['bzr+ssh://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev',
508
             'http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev'],
509
            urls)
4776.2.3 by Vincent Ladeuil
Add NEWS entry.
510
    # FIXME: we need to test with a real proxy, I can't find a way so simulate
511
    # CONNECT without leaving one server hanging the test :-/ Since that maybe
512
    # related to the leaking tests problems, I'll punt for now -- vila 20091030
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
513
514
515
class TestDebuntuExpansions(TestCaseInTempDir):
516
    """Test expansions for ubuntu: and debianlp: schemes."""
517
518
    def setUp(self):
5558.1.1 by Vincent Ladeuil
Catch the fugitive TestDebuntuExpansions tests and bring them back in the isolation jail
519
        super(TestDebuntuExpansions, self).setUp()
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
520
        self.directory = LaunchpadDirectory()
521
522
    def _make_factory(self, package='foo', distro='ubuntu', series=None):
523
        if series is None:
524
            path = '%s/%s' % (distro, package)
525
            url_suffix = '~branch/%s/%s' % (distro, package)
526
        else:
527
            path = '%s/%s/%s' % (distro, series, package)
528
            url_suffix = '~branch/%s/%s/%s' % (distro, series, package)
529
        return FakeResolveFactory(
530
            self, path, dict(urls=[
531
                'http://bazaar.launchpad.net/' + url_suffix]))
532
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
533
    def assertURL(self, expected_url, shortcut, package='foo', distro='ubuntu',
534
                  series=None):
535
        factory = self._make_factory(package=package, distro=distro,
536
                                     series=series)
537
        self.assertEqual('http://bazaar.launchpad.net/~branch/' + expected_url,
538
                         self.directory._resolve(shortcut, factory))
539
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
540
    # Bogus distro.
541
542
    def test_bogus_distro(self):
543
        self.assertRaises(errors.InvalidURL,
544
                          self.directory._resolve, 'gentoo:foo')
545
546
    def test_trick_bogus_distro_u(self):
547
        self.assertRaises(errors.InvalidURL,
548
                          self.directory._resolve, 'utube:foo')
549
550
    def test_trick_bogus_distro_d(self):
551
        self.assertRaises(errors.InvalidURL,
552
                          self.directory._resolve, 'debuntu:foo')
553
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
554
    def test_missing_ubuntu_distroseries_without_project(self):
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
555
        # Launchpad does not hold source packages for Intrepid.  Missing or
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
556
        # bogus distroseries with no project name is treated like a project.
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
557
        self.assertURL('ubuntu/intrepid', 'ubuntu:intrepid', package='intrepid')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
558
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
559
    def test_missing_ubuntu_distroseries_with_project(self):
560
        # Launchpad does not hold source packages for Intrepid.  Missing or
561
        # bogus distroseries with a project name is treated like an unknown
562
        # series (i.e. we keep it verbatim).
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
563
        self.assertURL('ubuntu/intrepid/foo',
564
                       'ubuntu:intrepid/foo', series='intrepid')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
565
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
566
    def test_missing_debian_distroseries(self):
567
        # Launchpad does not hold source packages for unstable.  Missing or
568
        # bogus distroseries is treated like a project.
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
569
        self.assertURL('debian/sid',
570
                       'debianlp:sid', package='sid', distro='debian')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
571
572
    # Ubuntu Default distro series.
573
574
    def test_ubuntu_default_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
575
        self.assertURL('ubuntu/foo', 'ubuntu:foo')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
576
5462.4.2 by Barry Warsaw
Might as well support natty.
577
    def test_ubuntu_natty_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
578
        self.assertURL('ubuntu/natty/foo', 'ubuntu:natty/foo', series='natty')
5462.4.2 by Barry Warsaw
Might as well support natty.
579
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
580
    def test_ubuntu_n_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
581
        self.assertURL('ubuntu/natty/foo', 'ubuntu:n/foo', series='natty')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
582
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
583
    def test_ubuntu_maverick_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
584
        self.assertURL('ubuntu/maverick/foo', 'ubuntu:maverick/foo',
585
                       series='maverick')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
586
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
587
    def test_ubuntu_m_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
588
        self.assertURL('ubuntu/maverick/foo', 'ubuntu:m/foo', series='maverick')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
589
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
590
    def test_ubuntu_lucid_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
591
        self.assertURL('ubuntu/lucid/foo', 'ubuntu:lucid/foo', series='lucid')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
592
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
593
    def test_ubuntu_l_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
594
        self.assertURL('ubuntu/lucid/foo', 'ubuntu:l/foo', series='lucid')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
595
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
596
    def test_ubuntu_karmic_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
597
        self.assertURL('ubuntu/karmic/foo', 'ubuntu:karmic/foo',
598
                       series='karmic')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
599
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
600
    def test_ubuntu_k_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
601
        self.assertURL('ubuntu/karmic/foo', 'ubuntu:k/foo', series='karmic')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
602
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
603
    def test_ubuntu_jaunty_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
604
        self.assertURL('ubuntu/jaunty/foo', 'ubuntu:jaunty/foo',
605
                       series='jaunty')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
606
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
607
    def test_ubuntu_j_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
608
        self.assertURL('ubuntu/jaunty/foo', 'ubuntu:j/foo', series='jaunty')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
609
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
610
    def test_ubuntu_hardy_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
611
        self.assertURL('ubuntu/hardy/foo', 'ubuntu:hardy/foo', series='hardy')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
612
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
613
    def test_ubuntu_h_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
614
        self.assertURL('ubuntu/hardy/foo', 'ubuntu:h/foo', series='hardy')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
615
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
616
    def test_ubuntu_dapper_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
617
        self.assertURL('ubuntu/dapper/foo', 'ubuntu:dapper/foo',
618
                       series='dapper')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
619
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
620
    def test_ubuntu_d_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
621
        self.assertURL('ubuntu/dapper/foo', 'ubuntu:d/foo', series='dapper')
5462.4.3 by Barry Warsaw
* Add back Ubuntu distroseries shortcuts.
622
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
623
    # Debian default distro series.
624
625
    def test_debian_default_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
626
        self.assertURL('debian/foo', 'debianlp:foo', distro='debian')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
627
628
    def test_debian_squeeze_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
629
        self.assertURL('debian/squeeze/foo', 'debianlp:squeeze/foo',
630
                       distro='debian', series='squeeze')
5462.4.1 by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant
631
632
    def test_debian_lenny_distroseries_expansion(self):
5462.4.6 by Vincent Ladeuil
Add helper to simplify tests
633
        self.assertURL('debian/lenny/foo', 'debianlp:lenny/foo',
634
                       distro='debian', series='lenny')