30
49
def test_short_form(self):
31
50
"""A launchpad url should map to a http url"""
33
t = get_transport(url)
34
self.assertEquals(t.base, 'http://code.launchpad.net/apt/')
51
factory = FakeResolveFactory(
52
self, 'apt', dict(urls=[
53
'http://bazaar.launchpad.net/~apt/apt/devel']))
54
transport = LaunchpadTransport('lp:///')
55
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
56
transport._resolve('lp:apt', factory))
36
58
def test_indirect_through_url(self):
37
59
"""A launchpad url should map to a http url"""
38
# These can change to use the smartserver protocol or something
41
t = get_transport(url)
43
self.assertEquals(real_url, 'http://code.launchpad.net/apt/')
60
factory = FakeResolveFactory(
61
self, 'apt', dict(urls=[
62
'http://bazaar.launchpad.net/~apt/apt/devel']))
63
transport = LaunchpadTransport('lp:///')
64
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
65
transport._resolve('lp:///apt', factory))
67
def test_indirect_skip_bad_schemes(self):
68
factory = FakeResolveFactory(
69
self, 'apt', dict(urls=[
70
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel',
71
'http://bazaar.launchpad.net/~apt/apt/devel',
72
'http://another/location']))
73
transport = LaunchpadTransport('lp:///')
74
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
75
transport._resolve('lp:///apt', factory))
77
def test_indirect_no_matching_schemes(self):
78
# If the XMLRPC call does not return any protocols we support,
79
# invalidURL is raised.
80
factory = FakeResolveFactory(
81
self, 'apt', dict(urls=[
82
'bad-scheme://bazaar.launchpad.net/~apt/apt/devel']))
83
transport = LaunchpadTransport('lp:///')
84
self.assertRaises(errors.InvalidURL,
85
transport._resolve, 'lp:///apt', factory)
87
def test_indirect_fault(self):
88
# Test that XMLRPC faults get converted to InvalidURL errors.
89
factory = FakeResolveFactory(self, 'apt', None)
91
raise xmlrpclib.Fault(42, 'something went wrong')
92
factory.submit = submit
93
transport = LaunchpadTransport('lp:///')
94
self.assertRaises(errors.InvalidURL,
95
transport._resolve, 'lp:///apt', factory)
97
def test_skip_bzr_ssh_launchpad_net_when_anonymous(self):
98
# Test that bzr+ssh://bazaar.launchpad.net gets skipped if
99
# Bazaar does not know the user's Launchpad ID:
100
self.assertEqual(None, get_lp_login())
101
factory = FakeResolveFactory(
102
self, 'apt', dict(urls=[
103
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
104
'http://bazaar.launchpad.net/~apt/apt/devel']))
105
transport = LaunchpadTransport('lp:///')
106
self.assertEquals('http://bazaar.launchpad.net/~apt/apt/devel',
107
transport._resolve('lp:///apt', factory))
109
def test_rewrite_bzr_ssh_launchpad_net(self):
110
# Test that bzr+ssh URLs get rewritten to include the user's
111
# Launchpad ID (assuming we know the Launchpad ID).
112
factory = FakeResolveFactory(
113
self, 'apt', dict(urls=[
114
'bzr+ssh://bazaar.launchpad.net/~apt/apt/devel',
115
'http://bazaar.launchpad.net/~apt/apt/devel']))
116
transport = LaunchpadTransport('lp:///')
118
'bzr+ssh://username@bazaar.launchpad.net/~apt/apt/devel',
119
transport._resolve('lp:///apt', factory, _lp_login='username'))
121
def test_no_rewrite_of_other_bzr_ssh(self):
122
# Test that we don't rewrite bzr+ssh URLs for other
123
self.assertEqual(None, get_lp_login())
124
factory = FakeResolveFactory(
125
self, 'apt', dict(urls=[
126
'bzr+ssh://example.com/~apt/apt/devel',
127
'http://bazaar.launchpad.net/~apt/apt/devel']))
128
transport = LaunchpadTransport('lp:///')
129
self.assertEquals('bzr+ssh://example.com/~apt/apt/devel',
130
transport._resolve('lp:///apt', factory))
45
132
# TODO: check we get an error if the url is unreasonable
46
133
def test_error_for_bad_indirection(self):
47
134
self.assertRaises(errors.InvalidURL,
135
LaunchpadTransport, 'lp://ratotehunoahu')
137
def catch_redirect(self, methodname, *args):
138
transport = LaunchpadTransport('lp:///apt')
139
def _resolve(abspath):
140
self.assertEqual('lp:///apt', abspath)
141
return 'http://example.com/~apt/apt/devel'
142
transport._resolve = _resolve
144
getattr(transport, methodname)(*args)
145
except errors.RedirectRequested, exc:
148
raise self.failException('RedirectRequested not raised')
150
def test_redirect_on_get(self):
151
exc = self.catch_redirect('get', '.bzr/branch-format')
152
self.assertEqual('lp:///apt/.bzr/branch-format', exc.source)
154
'http://example.com/~apt/apt/devel/.bzr/branch-format', exc.target)
156
def test_redirect_on_mkdir(self):
157
exc = self.catch_redirect('mkdir', '.')
158
self.assertEqual('lp:///apt', exc.source)
160
'http://example.com/~apt/apt/devel', exc.target)
163
class IndirectOpenBranchTests(TestCaseWithMemoryTransport):
165
def test_indirect_open_branch(self):
166
# Test that opening an lp: branch redirects to the real location.
167
target_branch = self.make_branch('target')
168
transport = get_transport('lp:///apt')
169
def _resolve(abspath):
170
self.assertEqual('lp:///apt', abspath)
171
return target_branch.base.rstrip('/')
172
transport._resolve = _resolve
173
branch = Branch.open_from_transport(transport)
174
self.assertEqual(target_branch.base, branch.base)