45
45
from bzrlib.branch import Branch
46
from bzrlib.bzrdir import (
46
from bzrlib.bzrdir import BzrDir, BzrDirFormat
51
47
from bzrlib.remote import (
53
49
RemoteBranchFormat,
56
53
RemoteRepositoryFormat,
91
89
self.transport = self.get_transport()
92
90
# make a branch that can be opened over the smart transport
93
91
self.local_wt = BzrDir.create_standalone_workingtree('.')
94
self.addCleanup(self.transport.disconnect)
94
self.transport.disconnect()
95
tests.TestCaseWithTransport.tearDown(self)
96
97
def test_create_remote_bzrdir(self):
97
98
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
121
122
def test_find_correct_format(self):
122
123
"""Should open a RemoteBzrDir over a RemoteTransport"""
123
124
fmt = BzrDirFormat.find_format(self.transport)
124
self.assertTrue(bzrdir.RemoteBzrProber
125
in controldir.ControlDirFormat._server_probers)
125
self.assertTrue(RemoteBzrDirFormat
126
in BzrDirFormat._control_server_formats)
126
127
self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
128
129
def test_open_detected_smart_format(self):
358
359
a given client_base and transport_base.
360
361
client_medium = medium.SmartClientMedium(client_base)
361
t = transport.get_transport(transport_base)
362
result = client_medium.remote_path_from_transport(t)
362
transport = get_transport(transport_base)
363
result = client_medium.remote_path_from_transport(transport)
363
364
self.assertEqual(expected, result)
365
366
def test_remote_path_from_transport(self):
376
377
a given transport_base and relpath of that transport. (Note that
377
378
HttpTransportBase is a subclass of SmartClientMedium)
379
base_transport = transport.get_transport(transport_base)
380
base_transport = get_transport(transport_base)
380
381
client_medium = base_transport.get_smart_medium()
381
382
cloned_transport = base_transport.clone(relpath)
382
383
result = client_medium.remote_path_from_transport(cloned_transport)
417
418
# Calling _remember_remote_is_before again with a lower value works.
418
419
client_medium._remember_remote_is_before((1, 5))
419
420
self.assertTrue(client_medium._is_remote_before((1, 5)))
420
# If you call _remember_remote_is_before with a higher value it logs a
421
# warning, and continues to remember the lower value.
422
self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
423
client_medium._remember_remote_is_before((1, 9))
424
self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
425
self.assertTrue(client_medium._is_remote_before((1, 5)))
421
# You cannot call _remember_remote_is_before with a larger value.
423
AssertionError, client_medium._remember_remote_is_before, (1, 9))
428
426
class TestBzrDirCloningMetaDir(TestRemote):
530
528
self.assertIsInstance(bd, RemoteBzrDir)
531
529
self.assertFinished(client)
533
def test_backwards_compat_hpss_v2(self):
534
client, transport = self.make_fake_client_and_transport()
535
# Monkey-patch fake client to simulate real-world behaviour with v2
536
# server: upon first RPC call detect the protocol version, and because
537
# the version is 2 also do _remember_remote_is_before((1, 6)) before
538
# continuing with the RPC.
539
orig_check_call = client._check_call
540
def check_call(method, args):
541
client._medium._protocol_version = 2
542
client._medium._remember_remote_is_before((1, 6))
543
client._check_call = orig_check_call
544
client._check_call(method, args)
545
client._check_call = check_call
546
client.add_expected_call(
547
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
548
client.add_expected_call(
549
'BzrDir.open', ('quack/',), 'success', ('yes',))
550
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
551
_client=client, _force_probe=True)
552
self.assertIsInstance(bd, RemoteBzrDir)
553
self.assertFinished(client)
556
532
class TestBzrDirOpenBranch(TestRemote):
608
584
# _get_tree_branch is a form of open_branch, but it should only ask for
609
585
# branch opening, not any other network requests.
611
def open_branch(name=None):
612
588
calls.append("Called")
613
589
return "a-branch"
614
590
transport = MemoryTransport()
687
663
self.assertRaises(errors.NotBranchError,
688
RemoteBzrProber.probe_transport, OldServerTransport())
664
RemoteBzrDirFormat.probe_transport, OldServerTransport())
691
667
class TestBzrDirCreateBranch(TestRemote):
1247
1223
len(branch.repository._real_repository._fallback_repositories))
1249
1225
def test_get_stacked_on_real_branch(self):
1250
base_branch = self.make_branch('base')
1251
stacked_branch = self.make_branch('stacked')
1226
base_branch = self.make_branch('base', format='1.6')
1227
stacked_branch = self.make_branch('stacked', format='1.6')
1252
1228
stacked_branch.set_stacked_on_url('../base')
1253
1229
reference_format = self.get_repo_format()
1254
1230
network_name = reference_format.network_name()
1259
1235
'success', ('branch', branch_network_name))
1260
1236
client.add_expected_call(
1261
1237
'BzrDir.find_repositoryV3', ('stacked/',),
1262
'success', ('ok', '', 'yes', 'no', 'yes', network_name))
1238
'success', ('ok', '', 'no', 'no', 'yes', network_name))
1263
1239
# called twice, once from constructor and then again by us
1264
1240
client.add_expected_call(
1265
1241
'Branch.get_stacked_on_url', ('stacked/',),
1617
1593
def test_get_multi_line_branch_conf(self):
1618
1594
# Make sure that multiple-line branch.conf files are supported
1620
# https://bugs.launchpad.net/bzr/+bug/354075
1596
# https://bugs.edge.launchpad.net/bzr/+bug/354075
1621
1597
client = FakeClient()
1622
1598
client.add_expected_call(
1623
1599
'Branch.get_stacked_on_url', ('memory:///',),
1651
1627
branch.unlock()
1652
1628
self.assertFinished(client)
1654
def test_set_option_with_dict(self):
1655
client = FakeClient()
1656
client.add_expected_call(
1657
'Branch.get_stacked_on_url', ('memory:///',),
1658
'error', ('NotStacked',),)
1659
client.add_expected_call(
1660
'Branch.lock_write', ('memory:///', '', ''),
1661
'success', ('ok', 'branch token', 'repo token'))
1662
encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1663
client.add_expected_call(
1664
'Branch.set_config_option_dict', ('memory:///', 'branch token',
1665
'repo token', encoded_dict_value, 'foo', ''),
1667
client.add_expected_call(
1668
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1670
transport = MemoryTransport()
1671
branch = self.make_remote_branch(transport, client)
1673
config = branch._get_config()
1675
{'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
1678
self.assertFinished(client)
1680
1630
def test_backwards_compat_set_option(self):
1681
1631
self.setup_smart_server_with_call_log()
1682
1632
branch = self.make_branch('.')
1689
1639
self.assertLength(10, self.hpss_calls)
1690
1640
self.assertEqual('value', branch._get_config().get_option('name'))
1692
def test_backwards_compat_set_option_with_dict(self):
1693
self.setup_smart_server_with_call_log()
1694
branch = self.make_branch('.')
1695
verb = 'Branch.set_config_option_dict'
1696
self.disable_verb(verb)
1698
self.addCleanup(branch.unlock)
1699
self.reset_smart_call_log()
1700
config = branch._get_config()
1701
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1702
config.set_option(value_dict, 'name')
1703
self.assertLength(10, self.hpss_calls)
1704
self.assertEqual(value_dict, branch._get_config().get_option('name'))
1707
1643
class TestBranchLockWrite(RemoteBranchTestCase):
2256
2192
# Make a repo with a fallback repo, both using a FakeClient.
2257
2193
format = remote.response_tuple_to_repo_format(
2258
('yes', 'no', 'yes', self.get_repo_format().network_name()))
2194
('yes', 'no', 'yes', 'fake-network-name'))
2259
2195
repo, client = self.setup_fake_client_and_repository('quack')
2260
2196
repo._format = format
2261
2197
fallback_repo, ignored = self.setup_fake_client_and_repository(
2263
2199
fallback_repo._client = client
2264
fallback_repo._format = format
2265
2200
repo.add_fallback_repository(fallback_repo)
2266
2201
# First the client should ask the primary repo
2267
2202
client.add_expected_call(
2341
2275
transport_path = 'quack'
2342
2276
repo, client = self.setup_fake_client_and_repository(transport_path)
2343
2277
client.add_success_response('ok', 'a token')
2344
token = repo.lock_write().repository_token
2278
result = repo.lock_write()
2345
2279
self.assertEqual(
2346
2280
[('call', 'Repository.lock_write', ('quack/', ''))],
2348
self.assertEqual('a token', token)
2282
self.assertEqual('a token', result)
2350
2284
def test_lock_write_already_locked(self):
2351
2285
transport_path = 'quack'