/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2008-03-14 16:32:01 UTC
  • mfrom: (3277 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3280.
  • Revision ID: john@arbash-meinel.com-20080314163201-33r5errgr41hzaci
[merge] bzr.dev 3277, cleanup NEWS indentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Tests for indirect branch urls through Launchpad.net"""
 
17
"""Tests for directory lookup through Launchpad.net"""
18
18
 
19
19
import xmlrpclib
20
20
 
22
22
    errors,
23
23
    )
24
24
from bzrlib.branch import Branch
 
25
from bzrlib.directory_service import directories
25
26
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
26
27
from bzrlib.transport import get_transport
27
 
from bzrlib.plugins.launchpad.lp_indirect import (
28
 
    LaunchpadTransport)
 
28
from bzrlib.plugins.launchpad import _register_directory
 
29
from bzrlib.plugins.launchpad.lp_directory import (
 
30
    LaunchpadDirectory)
29
31
from bzrlib.plugins.launchpad.account import get_lp_login
30
32
 
31
33
 
44
46
        return self._result
45
47
 
46
48
 
47
 
class IndirectUrlTests(TestCase):
48
 
    """Tests for indirect branch urls through Launchpad.net"""
 
49
class DirectoryUrlTests(TestCase):
 
50
    """Tests for branch urls through Launchpad.net directory"""
49
51
 
50
52
    def test_short_form(self):
51
53
        """A launchpad url should map to a http url"""
52
54
        factory = FakeResolveFactory(
53
55
            self, 'apt', dict(urls=[
54
56
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
55
 
        transport = LaunchpadTransport('lp:///')
 
57
        directory = LaunchpadDirectory()
56
58
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
57
 
                          transport._resolve('lp:apt', factory))
 
59
                          directory._resolve('lp:apt', factory))
58
60
        # Make sure that resolve went to the production server.
59
61
        self.assertEquals('https://xmlrpc.edge.launchpad.net/bazaar/',
60
62
                          factory._service_url)
65
67
            self, 'apt', dict(urls=[
66
68
                    'http://bazaar.staging.launchpad.net/~apt/apt/devel']))
67
69
        url = 'lp://staging/apt'
68
 
        transport = LaunchpadTransport(url)
 
70
        directory = LaunchpadDirectory()
69
71
        self.assertEquals('http://bazaar.staging.launchpad.net/~apt/apt/devel',
70
 
                          transport._resolve(url, factory))
 
72
                          directory._resolve(url, factory))
71
73
        # Make sure that resolve went to the staging server.
72
74
        self.assertEquals('https://xmlrpc.staging.launchpad.net/bazaar/',
73
75
                          factory._service_url)
74
76
 
75
 
    def test_indirect_through_url(self):
 
77
    def test_url_from_directory(self):
76
78
        """A launchpad url should map to a http url"""
77
79
        factory = FakeResolveFactory(
78
80
            self, 'apt', dict(urls=[
79
81
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
80
 
        transport = LaunchpadTransport('lp:///')
 
82
        directory = LaunchpadDirectory()
81
83
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
82
 
                          transport._resolve('lp:///apt', factory))
 
84
                          directory._resolve('lp:///apt', factory))
83
85
 
84
 
    def test_indirect_skip_bad_schemes(self):
 
86
    def test_directory_skip_bad_schemes(self):
85
87
        factory = FakeResolveFactory(
86
88
            self, 'apt', dict(urls=[
87
89
                    'bad-scheme://bazaar.launchpad.net/~apt/apt/devel',
88
90
                    'http://bazaar.launchpad.net/~apt/apt/devel',
89
91
                    'http://another/location']))
90
 
        transport = LaunchpadTransport('lp:///')
 
92
        directory = LaunchpadDirectory()
91
93
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
92
 
                          transport._resolve('lp:///apt', factory))
 
94
                          directory._resolve('lp:///apt', factory))
93
95
 
94
 
    def test_indirect_no_matching_schemes(self):
 
96
    def test_directory_no_matching_schemes(self):
95
97
        # If the XMLRPC call does not return any protocols we support,
96
98
        # invalidURL is raised.
97
99
        factory = FakeResolveFactory(
98
100
            self, 'apt', dict(urls=[
99
101
                    'bad-scheme://bazaar.launchpad.net/~apt/apt/devel']))
100
 
        transport = LaunchpadTransport('lp:///')
 
102
        directory = LaunchpadDirectory()
101
103
        self.assertRaises(errors.InvalidURL,
102
 
                          transport._resolve, 'lp:///apt', factory)
 
104
                          directory._resolve, 'lp:///apt', factory)
103
105
 
104
 
    def test_indirect_fault(self):
 
106
    def test_directory_fault(self):
105
107
        # Test that XMLRPC faults get converted to InvalidURL errors.
106
108
        factory = FakeResolveFactory(self, 'apt', None)
107
109
        def submit(service):
108
110
            raise xmlrpclib.Fault(42, 'something went wrong')
109
111
        factory.submit = submit
110
 
        transport = LaunchpadTransport('lp:///')
 
112
        directory = LaunchpadDirectory()
111
113
        self.assertRaises(errors.InvalidURL,
112
 
                          transport._resolve, 'lp:///apt', factory)
 
114
                          directory._resolve, 'lp:///apt', factory)
113
115
 
114
116
    def test_skip_bzr_ssh_launchpad_net_when_anonymous(self):
115
117
        # Test that bzr+ssh://bazaar.launchpad.net gets skipped if
119
121
            self, 'apt', dict(urls=[
120
122
                    'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
121
123
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
122
 
        transport = LaunchpadTransport('lp:///')
 
124
        directory = LaunchpadDirectory()
123
125
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
124
 
                          transport._resolve('lp:///apt', factory))
 
126
                          directory._resolve('lp:///apt', factory))
125
127
 
126
128
    def test_skip_sftp_launchpad_net_when_anonymous(self):
127
129
        # Test that sftp://bazaar.launchpad.net gets skipped if
131
133
            self, 'apt', dict(urls=[
132
134
                    'sftp://bazaar.launchpad.net/~apt/apt/devel',
133
135
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
134
 
        transport = LaunchpadTransport('lp:///')
 
136
        directory = LaunchpadDirectory()
135
137
        self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
136
 
                          transport._resolve('lp:///apt', factory))
 
138
                          directory._resolve('lp:///apt', factory))
137
139
 
138
140
    def test_rewrite_bzr_ssh_launchpad_net(self):
139
141
        # Test that bzr+ssh URLs get rewritten to include the user's
142
144
            self, 'apt', dict(urls=[
143
145
                    'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
144
146
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
145
 
        transport = LaunchpadTransport('lp:///')
 
147
        directory = LaunchpadDirectory()
146
148
        self.assertEquals(
147
149
            'bzr+ssh://username@bazaar.launchpad.net/~apt/apt/devel',
148
 
            transport._resolve('lp:///apt', factory, _lp_login='username'))
 
150
            directory._resolve('lp:///apt', factory, _lp_login='username'))
149
151
 
150
152
    def test_no_rewrite_of_other_bzr_ssh(self):
151
153
        # Test that we don't rewrite bzr+ssh URLs for other 
154
156
            self, 'apt', dict(urls=[
155
157
                    'bzr+ssh://example.com/~apt/apt/devel',
156
158
                    'http://bazaar.launchpad.net/~apt/apt/devel']))
157
 
        transport = LaunchpadTransport('lp:///')
 
159
        directory = LaunchpadDirectory()
158
160
        self.assertEquals('bzr+ssh://example.com/~apt/apt/devel',
159
 
                          transport._resolve('lp:///apt', factory))
 
161
                          directory._resolve('lp:///apt', factory))
160
162
 
161
163
    # TODO: check we get an error if the url is unreasonable
162
 
    def test_error_for_bad_indirection(self):
 
164
    def test_error_for_bad_url(self):
 
165
        directory = LaunchpadDirectory()
163
166
        self.assertRaises(errors.InvalidURL,
164
 
            LaunchpadTransport, 'lp://ratotehunoahu')
165
 
 
166
 
    def catch_redirect(self, methodname, *args):
167
 
        transport = LaunchpadTransport('lp:///apt')
168
 
        def _resolve(abspath):
169
 
            self.assertEqual('lp:///apt', abspath)
170
 
            return 'http://example.com/~apt/apt/devel'
171
 
        transport._resolve = _resolve
172
 
        try:
173
 
            getattr(transport, methodname)(*args)
174
 
        except errors.RedirectRequested, exc:
175
 
            return exc
176
 
        else:
177
 
            raise self.failException('RedirectRequested not raised')
178
 
 
179
 
    def test_redirect_on_get(self):
180
 
        exc = self.catch_redirect('get', '.bzr/branch-format')
181
 
        self.assertEqual('lp:///apt/.bzr/branch-format', exc.source)
182
 
        self.assertEqual(
183
 
            'http://example.com/~apt/apt/devel/.bzr/branch-format', exc.target)
184
 
 
185
 
    def test_redirect_on_mkdir(self):
186
 
        exc = self.catch_redirect('mkdir', '.')
187
 
        self.assertEqual('lp:///apt', exc.source)
188
 
        self.assertEqual(
189
 
            'http://example.com/~apt/apt/devel', exc.target)
190
 
 
191
 
 
192
 
class IndirectOpenBranchTests(TestCaseWithMemoryTransport):
193
 
 
194
 
    def test_indirect_open_branch(self):
 
167
            directory._resolve, 'lp://ratotehunoahu')
 
168
 
 
169
 
 
170
class DirectoryOpenBranchTests(TestCaseWithMemoryTransport):
 
171
 
 
172
    def test_directory_open_branch(self):
195
173
        # Test that opening an lp: branch redirects to the real location.
196
174
        target_branch = self.make_branch('target')
 
175
        class FooService(object):
 
176
            """A directory service that maps the name to a FILE url"""
 
177
 
 
178
            def look_up(self, name, url):
 
179
                if 'lp:///apt' == url:
 
180
                    return target_branch.base.rstrip('/')
 
181
                return '!unexpected look_up value!'
 
182
 
 
183
        directories.remove('lp:')
 
184
        directories.register('lp:', FooService, 'Map lp URLs to local urls')
 
185
        self.addCleanup(_register_directory)
 
186
        self.addCleanup(lambda: directories.remove('lp:'))
197
187
        transport = get_transport('lp:///apt')
198
 
        def _resolve(abspath):
199
 
            self.assertEqual('lp:///apt', abspath)
200
 
            return target_branch.base.rstrip('/')
201
 
        transport._resolve = _resolve
202
188
        branch = Branch.open_from_transport(transport)
203
189
        self.assertEqual(target_branch.base, branch.base)