74
72
test = unittest.FunctionTestCase(skipping_test)
75
73
result = runner.run(test)
76
74
self.assertTrue(result.wasSuccessful())
79
class TestTransportProviderAdapter(TestCase):
80
"""A group of tests that test the transport implementation adaption core.
82
This will be generalised in the future which is why it is in this
83
test file even though it is specific to transport tests at the moment.
86
def test_get_transport_permutations(self):
87
# this checks that we the module get_test_permutations call
88
# is made by the adapter get_transport_test_permitations method.
89
class MockModule(object):
90
def get_test_permutations(self):
91
return sample_permutation
92
sample_permutation = [(1,2), (3,4)]
93
from bzrlib.transport import TransportTestProviderAdapter
94
adapter = TransportTestProviderAdapter()
95
self.assertEqual(sample_permutation,
96
adapter.get_transport_test_permutations(MockModule()))
98
def test_adapter_checks_all_modules(self):
99
# this checks that the adapter returns as many permurtations as
100
# there are in all the registered# transport modules for there
101
# - we assume if this matches its probably doing the right thing
102
# especially in combination with the tests for setting the right
104
from bzrlib.transport import (TransportTestProviderAdapter,
105
_get_transport_modules
107
modules = _get_transport_modules()
108
permutation_count = 0
109
for module in modules:
110
permutation_count += len(reduce(getattr,
111
(module + ".get_test_permutations").split('.')[1:],
112
__import__(module))())
113
input_test = TestTransportProviderAdapter(
114
"test_adapter_sets_transport_class")
115
adapter = TransportTestProviderAdapter()
116
self.assertEqual(permutation_count,
117
len(list(iter(adapter.adapt(input_test)))))
119
def test_adapter_sets_transport_class(self):
120
# when the adapter adapts a test it needs to
121
# place one of the permutations from the transport
122
# providers in each test case copy. This checks
123
# that it does not just use the same one all the time.
124
# and that the id is set correctly so that debugging is
126
from bzrlib.transport.local import (LocalTransport,
131
from bzrlib.transport.sftp import (SFTPTransport,
134
SFTPSiblingAbsoluteServer,
136
from bzrlib.transport.http import (HttpTransport,
139
from bzrlib.transport.ftp import FtpTransport
140
from bzrlib.transport.memory import (MemoryTransport,
143
from bzrlib.transport import TransportTestProviderAdapter
144
# FIXME. What we want is a factory for the things
145
# needed to test the implementation. I.e. for transport we want:
146
# the class that connections should get; a local server factory
147
# so we would want the following permutations:
148
# LocalTransport relpath-factory
149
# LocalTransport abspath-factory
150
# LocalTransport file://-factory
151
# SFTPTransport homedir-factory
152
# SFTPTransport abssolute-factory
153
# HTTPTransport http-factory
154
# HTTPTransport https-factory
155
# etc, but we are currently lacking in this, so print out that
156
# this should be fixed.
157
input_test = TestTransportProviderAdapter(
158
"test_adapter_sets_transport_class")
159
suite = TransportTestProviderAdapter().adapt(input_test)
160
test_iter = iter(suite)
161
http_test = test_iter.next()
162
local_relpath_test = test_iter.next()
163
local_abspath_test = test_iter.next()
164
local_urlpath_test = test_iter.next()
165
memory_test = test_iter.next()
166
readonly_test = test_iter.next()
167
sftp_abs_test = test_iter.next()
168
sftp_homedir_test = test_iter.next()
169
sftp_sibling_abs_test = test_iter.next()
170
# ftp_test = test_iter.next()
171
self.assertRaises(StopIteration, test_iter.next)
172
self.assertEqual(LocalTransport, local_relpath_test.transport_class)
173
self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
175
self.assertEqual(LocalTransport, local_abspath_test.transport_class)
176
self.assertEqual(LocalAbspathServer, local_abspath_test.transport_server)
178
self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
179
self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
181
self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
182
self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
183
self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
184
self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
185
self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class)
186
self.assertEqual(SFTPSiblingAbsoluteServer,
187
sftp_sibling_abs_test.transport_server)
189
self.assertEqual(HttpTransport, http_test.transport_class)
190
self.assertEqual(HttpServer, http_test.transport_server)
191
# self.assertEqual(FtpTransport, ftp_test.transport_class)
193
self.assertEqual(MemoryTransport, memory_test.transport_class)
194
self.assertEqual(MemoryServer, memory_test.transport_server)
196
# we could test all of them for .id, but two is probably sufficient.
197
self.assertEqual("bzrlib.tests.test_selftest."
198
"TestTransportProviderAdapter."
199
"test_adapter_sets_transport_class(MemoryServer)",
201
self.assertEqual("bzrlib.tests.test_selftest."
202
"TestTransportProviderAdapter."
203
"test_adapter_sets_transport_class(LocalRelpathServer)",
204
local_relpath_test.id())
207
class TestBranchProviderAdapter(TestCase):
208
"""A group of tests that test the branch implementation test adapter."""
210
def test_adapted_tests(self):
211
# check that constructor parameters are passed through to the adapted
213
from bzrlib.branch import BranchTestProviderAdapter
214
input_test = TestBranchProviderAdapter(
215
"test_adapted_tests")
219
adapter = BranchTestProviderAdapter(server1, server2, formats)
220
suite = adapter.adapt(input_test)
221
tests = list(iter(suite))
222
self.assertEqual(2, len(tests))
223
self.assertEqual(tests[0].branch_format, formats[0])
224
self.assertEqual(tests[0].transport_server, server1)
225
self.assertEqual(tests[0].transport_readonly_server, server2)
226
self.assertEqual(tests[1].branch_format, formats[1])
227
self.assertEqual(tests[1].transport_server, server1)
228
self.assertEqual(tests[1].transport_readonly_server, server2)
231
class TestTestCaseWithTransport(TestCaseWithTransport):
232
"""Tests for the convenience functions TestCaseWithTransport introduces."""
234
def test_get_readonly_url_none(self):
235
from bzrlib.transport import get_transport
236
from bzrlib.transport.memory import MemoryServer
237
from bzrlib.transport.readonly import ReadonlyTransportDecorator
238
self.transport_server = MemoryServer
239
self.transport_readonly_server = None
240
# calling get_readonly_transport() constructs a decorator on the url
242
url = self.get_readonly_url()
243
url2 = self.get_readonly_url('foo/bar')
244
t = get_transport(url)
245
t2 = get_transport(url2)
246
self.failUnless(isinstance(t, ReadonlyTransportDecorator))
247
self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
248
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
250
def test_get_readonly_url_http(self):
251
from bzrlib.transport import get_transport
252
from bzrlib.transport.local import LocalRelpathServer
253
from bzrlib.transport.http import HttpServer, HttpTransport
254
self.transport_server = LocalRelpathServer
255
self.transport_readonly_server = HttpServer
256
# calling get_readonly_transport() gives us a HTTP server instance.
257
url = self.get_readonly_url()
258
url2 = self.get_readonly_url('foo/bar')
259
t = get_transport(url)
260
t2 = get_transport(url2)
261
self.failUnless(isinstance(t, HttpTransport))
262
self.failUnless(isinstance(t2, HttpTransport))
263
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))