42
62
old_format = bzrdir.BzrDirFormat.get_default_format()
43
63
# default is BzrDirFormat6
44
64
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
45
bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
65
self.applyDeprecated(symbol_versioning.zero_fourteen,
66
bzrdir.BzrDirFormat.set_default_format,
46
68
# creating a bzr dir should now create an instrumented dir.
48
70
result = bzrdir.BzrDir.create('memory:///')
49
71
self.failUnless(isinstance(result, SampleBzrDir))
51
bzrdir.BzrDirFormat.set_default_format(old_format)
73
self.applyDeprecated(symbol_versioning.zero_fourteen,
74
bzrdir.BzrDirFormat.set_default_format, old_format)
52
75
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
78
class TestFormatRegistry(TestCase):
80
def make_format_registry(self):
81
my_format_registry = bzrdir.BzrDirFormatRegistry()
82
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
83
'Pre-0.8 format. Slower and does not support checkouts or shared'
84
' repositories', deprecated=True)
85
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
86
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
87
my_format_registry.register_metadir('knit',
88
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
91
my_format_registry.set_default('knit')
92
my_format_registry.register_metadir(
94
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
95
'Experimental successor to knit. Use at your own risk.',
96
branch_format='bzrlib.branch.BzrBranchFormat6')
97
my_format_registry.register_metadir(
99
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
100
'Experimental successor to knit. Use at your own risk.',
101
branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
102
my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
103
'Pre-0.8 format. Slower and does not support checkouts or shared'
104
' repositories', hidden=True)
105
my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
106
'BzrDirFormat6', 'Format registered lazily', deprecated=True,
108
return my_format_registry
110
def test_format_registry(self):
111
my_format_registry = self.make_format_registry()
112
my_bzrdir = my_format_registry.make_bzrdir('lazy')
113
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
114
my_bzrdir = my_format_registry.make_bzrdir('weave')
115
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
116
my_bzrdir = my_format_registry.make_bzrdir('default')
117
self.assertIsInstance(my_bzrdir.repository_format,
118
knitrepo.RepositoryFormatKnit1)
119
my_bzrdir = my_format_registry.make_bzrdir('knit')
120
self.assertIsInstance(my_bzrdir.repository_format,
121
knitrepo.RepositoryFormatKnit1)
122
my_bzrdir = my_format_registry.make_bzrdir('branch6')
123
self.assertIsInstance(my_bzrdir.get_branch_format(),
124
bzrlib.branch.BzrBranchFormat6)
126
def test_get_help(self):
127
my_format_registry = self.make_format_registry()
128
self.assertEqual('Format registered lazily',
129
my_format_registry.get_help('lazy'))
130
self.assertEqual('Format using knits',
131
my_format_registry.get_help('knit'))
132
self.assertEqual('Format using knits',
133
my_format_registry.get_help('default'))
134
self.assertEqual('Pre-0.8 format. Slower and does not support'
135
' checkouts or shared repositories',
136
my_format_registry.get_help('weave'))
138
def test_help_topic(self):
139
topics = help_topics.HelpTopicRegistry()
140
topics.register('formats', self.make_format_registry().help_topic,
142
topic = topics.get_detail('formats')
143
new, deprecated = topic.split('Deprecated formats')
144
self.assertContainsRe(new, 'These formats can be used')
145
self.assertContainsRe(new,
146
':knit:\n \(native\) \(default\) Format using knits\n')
147
self.assertContainsRe(deprecated,
148
':lazy:\n \(native\) Format registered lazily\n')
149
self.assertNotContainsRe(new, 'hidden')
151
def test_set_default_repository(self):
152
default_factory = bzrdir.format_registry.get('default')
153
old_default = [k for k, v in bzrdir.format_registry.iteritems()
154
if v == default_factory and k != 'default'][0]
155
bzrdir.format_registry.set_default_repository('dirstate-with-subtree')
157
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
158
bzrdir.format_registry.get('default'))
160
repository.RepositoryFormat.get_default_format().__class__,
161
knitrepo.RepositoryFormatKnit3)
163
bzrdir.format_registry.set_default_repository(old_default)
55
166
class SampleBranch(bzrlib.branch.Branch):
56
167
"""A dummy branch for guess what, dummy use."""
153
263
# now open_downlevel should fail too.
154
264
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
156
def test_create_repository(self):
266
def test_create_repository_deprecated(self):
267
# new interface is to make the bzrdir, then a repository within that.
157
268
format = SampleBzrDirFormat()
158
old_format = bzrdir.BzrDirFormat.get_default_format()
159
bzrdir.BzrDirFormat.set_default_format(format)
161
repo = bzrdir.BzrDir.create_repository(self.get_url())
162
self.assertEqual('A repository', repo)
164
bzrdir.BzrDirFormat.set_default_format(old_format)
269
repo = self.applyDeprecated(zero_ninetyone,
270
bzrdir.BzrDir.create_repository,
271
self.get_url(), format=format)
272
self.assertEqual('A repository', repo)
166
274
def test_create_repository_shared(self):
275
# new interface is to make the bzrdir, then a repository within that.
167
276
old_format = bzrdir.BzrDirFormat.get_default_format()
168
repo = bzrdir.BzrDir.create_repository('.', shared=True)
277
repo = self.applyDeprecated(zero_ninetyone,
278
bzrdir.BzrDir.create_repository,
169
280
self.assertTrue(repo.is_shared())
171
282
def test_create_repository_nonshared(self):
283
# new interface is to make the bzrdir, then a repository within that.
172
284
old_format = bzrdir.BzrDirFormat.get_default_format()
173
repo = bzrdir.BzrDir.create_repository('.')
285
repo = self.applyDeprecated(zero_ninetyone,
286
bzrdir.BzrDir.create_repository,
174
288
self.assertFalse(repo.is_shared())
176
290
def test_create_repository_under_shared(self):
177
291
# an explicit create_repository always does so.
178
292
# we trust the format is right from the 'create_repository test'
179
old_format = bzrdir.BzrDirFormat.get_default_format()
180
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
182
self.make_repository('.', shared=True)
183
repo = bzrdir.BzrDir.create_repository(self.get_url('child'))
184
self.assertTrue(isinstance(repo, repository.Repository))
185
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
187
bzrdir.BzrDirFormat.set_default_format(old_format)
293
# new interface is to make the bzrdir, then a repository within that.
294
format = bzrdir.format_registry.make_bzrdir('knit')
295
self.make_repository('.', shared=True, format=format)
296
repo = self.applyDeprecated(zero_ninetyone,
297
bzrdir.BzrDir.create_repository,
298
self.get_url('child'),
300
self.assertTrue(isinstance(repo, repository.Repository))
301
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
189
303
def test_create_branch_and_repo_uses_default(self):
190
304
format = SampleBzrDirFormat()
191
old_format = bzrdir.BzrDirFormat.get_default_format()
192
bzrdir.BzrDirFormat.set_default_format(format)
194
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url())
195
self.assertTrue(isinstance(branch, SampleBranch))
197
bzrdir.BzrDirFormat.set_default_format(old_format)
305
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
307
self.assertTrue(isinstance(branch, SampleBranch))
199
309
def test_create_branch_and_repo_under_shared(self):
200
310
# creating a branch and repo in a shared repo uses the
201
311
# shared repository
202
old_format = bzrdir.BzrDirFormat.get_default_format()
203
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
205
self.make_repository('.', shared=True)
206
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'))
207
self.assertRaises(errors.NoRepositoryPresent,
208
branch.bzrdir.open_repository)
210
bzrdir.BzrDirFormat.set_default_format(old_format)
312
format = bzrdir.format_registry.make_bzrdir('knit')
313
self.make_repository('.', shared=True, format=format)
314
branch = bzrdir.BzrDir.create_branch_and_repo(
315
self.get_url('child'), format=format)
316
self.assertRaises(errors.NoRepositoryPresent,
317
branch.bzrdir.open_repository)
212
319
def test_create_branch_and_repo_under_shared_force_new(self):
213
320
# creating a branch and repo in a shared repo can be forced to
214
321
# make a new repo
215
old_format = bzrdir.BzrDirFormat.get_default_format()
216
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
218
self.make_repository('.', shared=True)
219
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
221
branch.bzrdir.open_repository()
223
bzrdir.BzrDirFormat.set_default_format(old_format)
322
format = bzrdir.format_registry.make_bzrdir('knit')
323
self.make_repository('.', shared=True, format=format)
324
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
327
branch.bzrdir.open_repository()
225
329
def test_create_standalone_working_tree(self):
226
330
format = SampleBzrDirFormat()
227
old_format = bzrdir.BzrDirFormat.get_default_format()
228
bzrdir.BzrDirFormat.set_default_format(format)
230
# note this is deliberately readonly, as this failure should
231
# occur before any writes.
232
self.assertRaises(errors.NotLocalUrl,
233
bzrdir.BzrDir.create_standalone_workingtree,
234
self.get_readonly_url())
235
tree = bzrdir.BzrDir.create_standalone_workingtree('.')
236
self.assertEqual('A tree', tree)
238
bzrdir.BzrDirFormat.set_default_format(old_format)
331
# note this is deliberately readonly, as this failure should
332
# occur before any writes.
333
self.assertRaises(errors.NotLocalUrl,
334
bzrdir.BzrDir.create_standalone_workingtree,
335
self.get_readonly_url(), format=format)
336
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
338
self.assertEqual('A tree', tree)
240
340
def test_create_standalone_working_tree_under_shared_repo(self):
241
341
# create standalone working tree always makes a repo.
242
old_format = bzrdir.BzrDirFormat.get_default_format()
243
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
245
self.make_repository('.', shared=True)
246
# note this is deliberately readonly, as this failure should
247
# occur before any writes.
248
self.assertRaises(errors.NotLocalUrl,
249
bzrdir.BzrDir.create_standalone_workingtree,
250
self.get_readonly_url('child'))
251
tree = bzrdir.BzrDir.create_standalone_workingtree('child')
252
tree.bzrdir.open_repository()
254
bzrdir.BzrDirFormat.set_default_format(old_format)
342
format = bzrdir.format_registry.make_bzrdir('knit')
343
self.make_repository('.', shared=True, format=format)
344
# note this is deliberately readonly, as this failure should
345
# occur before any writes.
346
self.assertRaises(errors.NotLocalUrl,
347
bzrdir.BzrDir.create_standalone_workingtree,
348
self.get_readonly_url('child'), format=format)
349
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
351
tree.bzrdir.open_repository()
256
353
def test_create_branch_convenience(self):
257
354
# outside a repo the default convenience output is a repo+branch_tree
258
old_format = bzrdir.BzrDirFormat.get_default_format()
259
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
261
branch = bzrdir.BzrDir.create_branch_convenience('.')
262
branch.bzrdir.open_workingtree()
263
branch.bzrdir.open_repository()
265
bzrdir.BzrDirFormat.set_default_format(old_format)
355
format = bzrdir.format_registry.make_bzrdir('knit')
356
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
357
branch.bzrdir.open_workingtree()
358
branch.bzrdir.open_repository()
360
def test_create_branch_convenience_possible_transports(self):
361
"""Check that the optional 'possible_transports' is recognized"""
362
format = bzrdir.format_registry.make_bzrdir('knit')
363
t = self.get_transport()
364
branch = bzrdir.BzrDir.create_branch_convenience(
365
'.', format=format, possible_transports=[t])
366
branch.bzrdir.open_workingtree()
367
branch.bzrdir.open_repository()
267
369
def test_create_branch_convenience_root(self):
268
370
"""Creating a branch at the root of a fs should work."""
269
self.transport_server = MemoryServer
371
self.vfs_transport_factory = MemoryServer
270
372
# outside a repo the default convenience output is a repo+branch_tree
271
old_format = bzrdir.BzrDirFormat.get_default_format()
272
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
274
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url())
275
self.assertRaises(errors.NoWorkingTree,
276
branch.bzrdir.open_workingtree)
277
branch.bzrdir.open_repository()
279
bzrdir.BzrDirFormat.set_default_format(old_format)
373
format = bzrdir.format_registry.make_bzrdir('knit')
374
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
376
self.assertRaises(errors.NoWorkingTree,
377
branch.bzrdir.open_workingtree)
378
branch.bzrdir.open_repository()
281
380
def test_create_branch_convenience_under_shared_repo(self):
282
381
# inside a repo the default convenience output is a branch+ follow the
283
382
# repo tree policy
284
old_format = bzrdir.BzrDirFormat.get_default_format()
285
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
287
self.make_repository('.', shared=True)
288
branch = bzrdir.BzrDir.create_branch_convenience('child')
289
branch.bzrdir.open_workingtree()
290
self.assertRaises(errors.NoRepositoryPresent,
291
branch.bzrdir.open_repository)
293
bzrdir.BzrDirFormat.set_default_format(old_format)
383
format = bzrdir.format_registry.make_bzrdir('knit')
384
self.make_repository('.', shared=True, format=format)
385
branch = bzrdir.BzrDir.create_branch_convenience('child',
387
branch.bzrdir.open_workingtree()
388
self.assertRaises(errors.NoRepositoryPresent,
389
branch.bzrdir.open_repository)
295
391
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
296
392
# inside a repo the default convenience output is a branch+ follow the
297
393
# repo tree policy but we can override that
298
old_format = bzrdir.BzrDirFormat.get_default_format()
299
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
301
self.make_repository('.', shared=True)
302
branch = bzrdir.BzrDir.create_branch_convenience('child',
303
force_new_tree=False)
304
self.assertRaises(errors.NoWorkingTree,
305
branch.bzrdir.open_workingtree)
306
self.assertRaises(errors.NoRepositoryPresent,
307
branch.bzrdir.open_repository)
309
bzrdir.BzrDirFormat.set_default_format(old_format)
394
format = bzrdir.format_registry.make_bzrdir('knit')
395
self.make_repository('.', shared=True, format=format)
396
branch = bzrdir.BzrDir.create_branch_convenience('child',
397
force_new_tree=False, format=format)
398
self.assertRaises(errors.NoWorkingTree,
399
branch.bzrdir.open_workingtree)
400
self.assertRaises(errors.NoRepositoryPresent,
401
branch.bzrdir.open_repository)
311
403
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
312
404
# inside a repo the default convenience output is a branch+ follow the
313
405
# repo tree policy
314
old_format = bzrdir.BzrDirFormat.get_default_format()
315
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
317
repo = self.make_repository('.', shared=True)
318
repo.set_make_working_trees(False)
319
branch = bzrdir.BzrDir.create_branch_convenience('child')
320
self.assertRaises(errors.NoWorkingTree,
321
branch.bzrdir.open_workingtree)
322
self.assertRaises(errors.NoRepositoryPresent,
323
branch.bzrdir.open_repository)
325
bzrdir.BzrDirFormat.set_default_format(old_format)
406
format = bzrdir.format_registry.make_bzrdir('knit')
407
repo = self.make_repository('.', shared=True, format=format)
408
repo.set_make_working_trees(False)
409
branch = bzrdir.BzrDir.create_branch_convenience('child',
411
self.assertRaises(errors.NoWorkingTree,
412
branch.bzrdir.open_workingtree)
413
self.assertRaises(errors.NoRepositoryPresent,
414
branch.bzrdir.open_repository)
327
416
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
328
417
# inside a repo the default convenience output is a branch+ follow the
329
418
# repo tree policy but we can override that
330
old_format = bzrdir.BzrDirFormat.get_default_format()
331
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
333
repo = self.make_repository('.', shared=True)
334
repo.set_make_working_trees(False)
335
branch = bzrdir.BzrDir.create_branch_convenience('child',
337
branch.bzrdir.open_workingtree()
338
self.assertRaises(errors.NoRepositoryPresent,
339
branch.bzrdir.open_repository)
341
bzrdir.BzrDirFormat.set_default_format(old_format)
419
format = bzrdir.format_registry.make_bzrdir('knit')
420
repo = self.make_repository('.', shared=True, format=format)
421
repo.set_make_working_trees(False)
422
branch = bzrdir.BzrDir.create_branch_convenience('child',
423
force_new_tree=True, format=format)
424
branch.bzrdir.open_workingtree()
425
self.assertRaises(errors.NoRepositoryPresent,
426
branch.bzrdir.open_repository)
343
428
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
344
429
# inside a repo the default convenience output is overridable to give
345
430
# repo+branch+tree
346
old_format = bzrdir.BzrDirFormat.get_default_format()
347
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
349
self.make_repository('.', shared=True)
350
branch = bzrdir.BzrDir.create_branch_convenience('child',
352
branch.bzrdir.open_repository()
353
branch.bzrdir.open_workingtree()
355
bzrdir.BzrDirFormat.set_default_format(old_format)
431
format = bzrdir.format_registry.make_bzrdir('knit')
432
self.make_repository('.', shared=True, format=format)
433
branch = bzrdir.BzrDir.create_branch_convenience('child',
434
force_new_repo=True, format=format)
435
branch.bzrdir.open_repository()
436
branch.bzrdir.open_workingtree()
358
439
class ChrootedTests(TestCaseWithTransport):
392
473
get_transport(self.get_readonly_url('g/p/q')))
393
474
self.assertEqual('g/p/q', relpath)
476
def test_open_containing_tree_or_branch(self):
477
def local_branch_path(branch):
478
return os.path.realpath(
479
urlutils.local_path_from_url(branch.base))
481
self.make_branch_and_tree('topdir')
482
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
484
self.assertEqual(os.path.realpath('topdir'),
485
os.path.realpath(tree.basedir))
486
self.assertEqual(os.path.realpath('topdir'),
487
local_branch_path(branch))
488
self.assertIs(tree.bzrdir, branch.bzrdir)
489
self.assertEqual('foo', relpath)
490
# opening from non-local should not return the tree
491
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
492
self.get_readonly_url('topdir/foo'))
493
self.assertEqual(None, tree)
494
self.assertEqual('foo', relpath)
496
self.make_branch('topdir/foo')
497
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
499
self.assertIs(tree, None)
500
self.assertEqual(os.path.realpath('topdir/foo'),
501
local_branch_path(branch))
502
self.assertEqual('', relpath)
504
def test_open_from_transport(self):
505
# transport pointing at bzrdir should give a bzrdir with root transport
506
# set to the given transport
507
control = bzrdir.BzrDir.create(self.get_url())
508
transport = get_transport(self.get_url())
509
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
510
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
511
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
513
def test_open_from_transport_no_bzrdir(self):
514
transport = get_transport(self.get_url())
515
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
518
def test_open_from_transport_bzrdir_in_parent(self):
519
control = bzrdir.BzrDir.create(self.get_url())
520
transport = get_transport(self.get_url())
521
transport.mkdir('subdir')
522
transport = transport.clone('subdir')
523
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
526
def test_sprout_recursive(self):
527
tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
528
sub_tree = self.make_branch_and_tree('tree1/subtree',
529
format='dirstate-with-subtree')
530
tree.add_reference(sub_tree)
531
self.build_tree(['tree1/subtree/file'])
533
tree.commit('Initial commit')
534
tree.bzrdir.sprout('tree2')
535
self.failUnlessExists('tree2/subtree/file')
537
def test_cloning_metadir(self):
538
"""Ensure that cloning metadir is suitable"""
539
bzrdir = self.make_bzrdir('bzrdir')
540
bzrdir.cloning_metadir()
541
branch = self.make_branch('branch', format='knit')
542
format = branch.bzrdir.cloning_metadir()
543
self.assertIsInstance(format.workingtree_format,
544
workingtree.WorkingTreeFormat3)
546
def test_sprout_recursive_treeless(self):
547
tree = self.make_branch_and_tree('tree1',
548
format='dirstate-with-subtree')
549
sub_tree = self.make_branch_and_tree('tree1/subtree',
550
format='dirstate-with-subtree')
551
tree.add_reference(sub_tree)
552
self.build_tree(['tree1/subtree/file'])
554
tree.commit('Initial commit')
555
tree.bzrdir.destroy_workingtree()
556
repo = self.make_repository('repo', shared=True,
557
format='dirstate-with-subtree')
558
repo.set_make_working_trees(False)
559
tree.bzrdir.sprout('repo/tree2')
560
self.failUnlessExists('repo/tree2/subtree')
561
self.failIfExists('repo/tree2/subtree/file')
396
564
class TestMeta1DirFormat(TestCaseWithTransport):
397
565
"""Tests specific to the meta1 dir format."""
602
789
result.open_branch()
603
790
result.open_repository()
792
def test_checkout_metadir(self):
793
# checkout_metadir has reasonable working tree format even when no
794
# working tree is present
795
self.make_branch('branch-knit2', format='dirstate-with-subtree')
796
my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
797
checkout_format = my_bzrdir.checkout_metadir()
798
self.assertIsInstance(checkout_format.workingtree_format,
799
workingtree.WorkingTreeFormat3)
802
class TestHTTPRedirectionLoop(object):
803
"""Test redirection loop between two http servers.
805
This MUST be used by daughter classes that also inherit from
806
TestCaseWithTwoWebservers.
808
We can't inherit directly from TestCaseWithTwoWebservers or the
809
test framework will try to create an instance which cannot
810
run, its implementation being incomplete.
813
# Should be defined by daughter classes to ensure redirection
814
# still use the same transport implementation (not currently
815
# enforced as it's a bit tricky to get right (see the FIXME
816
# in BzrDir.open_from_transport for the unique use case so
820
def create_transport_readonly_server(self):
821
return HTTPServerRedirecting()
823
def create_transport_secondary_server(self):
824
return HTTPServerRedirecting()
827
# Both servers redirect to each server creating a loop
828
super(TestHTTPRedirectionLoop, self).setUp()
829
# The redirections will point to the new server
830
self.new_server = self.get_readonly_server()
831
# The requests to the old server will be redirected
832
self.old_server = self.get_secondary_server()
833
# Configure the redirections
834
self.old_server.redirect_to(self.new_server.host, self.new_server.port)
835
self.new_server.redirect_to(self.old_server.host, self.old_server.port)
837
def _qualified_url(self, host, port):
838
return 'http+%s://%s:%s' % (self._qualifier, host, port)
841
# Starting from either server should loop
842
old_url = self._qualified_url(self.old_server.host,
843
self.old_server.port)
844
oldt = self._transport(old_url)
845
self.assertRaises(errors.NotBranchError,
846
bzrdir.BzrDir.open_from_transport, oldt)
847
new_url = self._qualified_url(self.new_server.host,
848
self.new_server.port)
849
newt = self._transport(new_url)
850
self.assertRaises(errors.NotBranchError,
851
bzrdir.BzrDir.open_from_transport, newt)
854
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
855
TestCaseWithTwoWebservers):
856
"""Tests redirections for urllib implementation"""
858
_qualifier = 'urllib'
859
_transport = HttpTransport_urllib
863
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
864
TestHTTPRedirectionLoop,
865
TestCaseWithTwoWebservers):
866
"""Tests redirections for pycurl implementation"""
868
_qualifier = 'pycurl'