~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/test_lp_directory.py

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import xmlrpclib
21
21
 
22
22
from bzrlib import (
 
23
    debug,
23
24
    errors,
24
25
    tests,
25
26
    transport,
62
63
 
63
64
 
64
65
class FakeResolveFactory(object):
 
66
 
65
67
    def __init__(self, test, expected_path, result):
66
68
        self._test = test
67
69
        self._expected_path = expected_path
68
70
        self._result = result
 
71
        self._submitted = False
69
72
 
70
73
    def __call__(self, path):
71
74
        self._test.assertEqual(self._expected_path, path)
73
76
 
74
77
    def submit(self, service):
75
78
        self._service_url = service.service_url
 
79
        self._submitted = True
76
80
        return self._result
77
81
 
78
82
 
 
83
class LocalDirectoryURLTests(TestCaseInTempDir):
 
84
    """Tests for branch urls that we try to pass through local resolution."""
 
85
 
 
86
    def assertResolve(self, expected, url, submitted=False):
 
87
        path = url[url.index(':')+1:].lstrip('/')
 
88
        factory = FakeResolveFactory(self, path,
 
89
                    dict(urls=['bzr+ssh://fake-resolved']))
 
90
        directory = LaunchpadDirectory()
 
91
        self.assertEqual(expected,
 
92
            directory._resolve(url, factory, _lp_login='user'))
 
93
        # We are testing local resolution, and the fallback when necessary.
 
94
        self.assertEqual(submitted, factory._submitted)
 
95
 
 
96
    def test_short_form(self):
 
97
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
 
98
                           'lp:apt')
 
99
 
 
100
    def test_two_part_form(self):
 
101
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt/2.2',
 
102
                           'lp:apt/2.2')
 
103
 
 
104
    def test_two_part_plus_subdir(self):
 
105
        # We allow you to pass more than just what resolves. That way you can
 
106
        # do things like "bzr log lp:apt/2.2/BUGS"
 
107
        # Though the virtual FS implementation currently aborts when given a
 
108
        # URL like this, rather than letting you recurse upwards to find the
 
109
        # real branch at lp:apt/2.2
 
110
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt/2.2/BUGS',
 
111
                           'lp:apt/2.2/BUGS')
 
112
 
 
113
    def test_user_expansion(self):
 
114
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/~user/apt/foo',
 
115
                           'lp:~/apt/foo')
 
116
 
 
117
    def test_ubuntu(self):
 
118
        # Confirmed against xmlrpc. If you don't have a ~user, xmlrpc doesn't
 
119
        # care that you are asking for 'ubuntu'
 
120
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/ubuntu',
 
121
                           'lp:ubuntu')
 
122
 
 
123
    def test_ubuntu_apt(self):
 
124
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/apt',
 
125
                           'lp:ubuntu/apt')
 
126
 
 
127
    def test_ubuntu_natty_apt(self):
 
128
        self.assertResolve(
 
129
            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/apt',
 
130
            'lp:ubuntu/natty/apt')
 
131
 
 
132
    def test_ubuntu_natty_apt_filename(self):
 
133
        self.assertResolve(
 
134
            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/apt/filename',
 
135
            'lp:ubuntu/natty/apt/filename')
 
136
 
 
137
    def test_user_two_part(self):
 
138
        # We fall back to the ResolveFactory. The real Launchpad one will raise
 
139
        # InvalidURL for this case.
 
140
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/apt',
 
141
                           submitted=True)
 
142
 
 
143
    def test_user_three_part(self):
 
144
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/~jameinel/apt/foo',
 
145
                           'lp:~jameinel/apt/foo')
 
146
 
 
147
    def test_user_three_part_plus_filename(self):
 
148
        self.assertResolve(
 
149
            'bzr+ssh://bazaar.launchpad.net/~jameinel/apt/foo/fname',
 
150
            'lp:~jameinel/apt/foo/fname')
 
151
 
 
152
    def test_user_ubuntu_two_part(self):
 
153
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/ubuntu',
 
154
                           submitted=True)
 
155
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:~jameinel/debian',
 
156
                           submitted=True)
 
157
 
 
158
    def test_user_ubuntu_three_part(self):
 
159
        self.assertResolve('bzr+ssh://fake-resolved',
 
160
                           'lp:~jameinel/ubuntu/natty', submitted=True)
 
161
        self.assertResolve('bzr+ssh://fake-resolved',
 
162
                           'lp:~jameinel/debian/sid', submitted=True)
 
163
 
 
164
    def test_user_ubuntu_four_part(self):
 
165
        self.assertResolve('bzr+ssh://fake-resolved',
 
166
                           'lp:~jameinel/ubuntu/natty/project', submitted=True)
 
167
        self.assertResolve('bzr+ssh://fake-resolved',
 
168
                           'lp:~jameinel/debian/sid/project', submitted=True)
 
169
 
 
170
    def test_user_ubuntu_five_part(self):
 
171
        self.assertResolve(
 
172
            'bzr+ssh://bazaar.launchpad.net/~jameinel/ubuntu/natty/apt/branch',
 
173
            'lp:~jameinel/ubuntu/natty/apt/branch')
 
174
        self.assertResolve(
 
175
            'bzr+ssh://bazaar.launchpad.net/~jameinel/debian/sid/apt/branch',
 
176
            'lp:~jameinel/debian/sid/apt/branch')
 
177
 
 
178
    def test_user_ubuntu_five_part_plus_subdir(self):
 
179
        self.assertResolve(
 
180
            'bzr+ssh://bazaar.launchpad.net/~jameinel/ubuntu/natty/apt/branch/f',
 
181
            'lp:~jameinel/ubuntu/natty/apt/branch/f')
 
182
        self.assertResolve(
 
183
            'bzr+ssh://bazaar.launchpad.net/~jameinel/debian/sid/apt/branch/f',
 
184
            'lp:~jameinel/debian/sid/apt/branch/f')
 
185
 
 
186
    def test_handles_special_lp(self):
 
187
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt', 'lp:apt')
 
188
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
 
189
                           'lp:///apt')
 
190
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/apt',
 
191
                           'lp://production/apt')
 
192
        self.assertResolve('bzr+ssh://bazaar.launchpad.dev/+branch/apt',
 
193
                           'lp://dev/apt')
 
194
        self.assertResolve('bzr+ssh://bazaar.staging.launchpad.net/+branch/apt',
 
195
                           'lp://staging/apt')
 
196
        self.assertResolve('bzr+ssh://bazaar.qastaging.launchpad.net/+branch/apt',
 
197
                           'lp://qastaging/apt')
 
198
        self.assertResolve('bzr+ssh://bazaar.demo.launchpad.net/+branch/apt',
 
199
                           'lp://demo/apt')
 
200
 
 
201
    def test_debug_launchpad_uses_resolver(self):
 
202
        self.assertResolve('bzr+ssh://bazaar.launchpad.net/+branch/bzr',
 
203
                           'lp:bzr', submitted=False)
 
204
        debug.debug_flags.add('launchpad')
 
205
        self.addCleanup(debug.debug_flags.discard, 'launchpad')
 
206
        self.assertResolve('bzr+ssh://fake-resolved', 'lp:bzr', submitted=True)
 
207
 
 
208
 
79
209
class DirectoryUrlTests(TestCaseInTempDir):
80
210
    """Tests for branch urls through Launchpad.net directory"""
81
211
 
91
221
        self.assertEquals('https://xmlrpc.launchpad.net/bazaar/',
92
222
                          factory._service_url)
93
223
 
 
224
    def test_qastaging(self):
 
225
        """A launchpad url should map to a http url"""
 
226
        factory = FakeResolveFactory(
 
227
            self, 'apt', dict(urls=[
 
228
                    'http://bazaar.qastaging.launchpad.net/~apt/apt/devel']))
 
229
        url = 'lp://qastaging/apt'
 
230
        directory = LaunchpadDirectory()
 
231
        self.assertEquals('http://bazaar.qastaging.launchpad.net/~apt/apt/devel',
 
232
                          directory._resolve(url, factory))
 
233
        # Make sure that resolve went to the qastaging server.
 
234
        self.assertEquals('https://xmlrpc.qastaging.launchpad.net/bazaar/',
 
235
                          factory._service_url)
 
236
 
94
237
    def test_staging(self):
95
238
        """A launchpad url should map to a http url"""
96
239
        factory = FakeResolveFactory(
167
310
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
168
311
                          directory._resolve('lp:///apt', factory))
169
312
 
170
 
    def test_rewrite_bzr_ssh_launchpad_net(self):
 
313
    def test_with_login_avoid_resolve_factory(self):
171
314
        # Test that bzr+ssh URLs get rewritten to include the user's
172
315
        # Launchpad ID (assuming we know the Launchpad ID).
173
316
        factory = FakeResolveFactory(
174
317
            self, 'apt', dict(urls=[
175
 
                    'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
 
318
                    'bzr+ssh://my-super-custom/special/devel',
176
319
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
177
320
        directory = LaunchpadDirectory()
178
321
        self.assertEquals(
179
 
            'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
 
322
            'bzr+ssh://bazaar.launchpad.net/+branch/apt',
180
323
            directory._resolve('lp:///apt', factory, _lp_login='username'))
181
324
 
182
325
    def test_no_rewrite_of_other_bzr_ssh(self):
199
342
    def test_resolve_tilde_to_user(self):
200
343
        factory = FakeResolveFactory(
201
344
            self, '~username/apt/test', dict(urls=[
202
 
                    'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
 
345
                'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
203
346
        directory = LaunchpadDirectory()
204
347
        self.assertEquals(
205
348
            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',