45
45
from bzrlib.branch import Branch
46
from bzrlib.bzrdir import BzrDir, BzrDirFormat
46
from bzrlib.bzrdir import (
47
51
from bzrlib.remote import (
49
53
RemoteBranchFormat,
53
56
RemoteRepositoryFormat,
89
91
self.transport = self.get_transport()
90
92
# make a branch that can be opened over the smart transport
91
93
self.local_wt = BzrDir.create_standalone_workingtree('.')
94
self.transport.disconnect()
95
tests.TestCaseWithTransport.tearDown(self)
94
self.addCleanup(self.transport.disconnect)
97
96
def test_create_remote_bzrdir(self):
98
97
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
122
121
def test_find_correct_format(self):
123
122
"""Should open a RemoteBzrDir over a RemoteTransport"""
124
123
fmt = BzrDirFormat.find_format(self.transport)
125
self.assertTrue(RemoteBzrDirFormat
126
in BzrDirFormat._control_server_formats)
124
self.assertTrue(bzrdir.RemoteBzrProber
125
in controldir.ControlDirFormat._server_probers)
127
126
self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
129
128
def test_open_detected_smart_format(self):
359
358
a given client_base and transport_base.
361
360
client_medium = medium.SmartClientMedium(client_base)
362
transport = get_transport(transport_base)
363
result = client_medium.remote_path_from_transport(transport)
361
t = transport.get_transport(transport_base)
362
result = client_medium.remote_path_from_transport(t)
364
363
self.assertEqual(expected, result)
366
365
def test_remote_path_from_transport(self):
377
376
a given transport_base and relpath of that transport. (Note that
378
377
HttpTransportBase is a subclass of SmartClientMedium)
380
base_transport = get_transport(transport_base)
379
base_transport = transport.get_transport(transport_base)
381
380
client_medium = base_transport.get_smart_medium()
382
381
cloned_transport = base_transport.clone(relpath)
383
382
result = client_medium.remote_path_from_transport(cloned_transport)
418
417
# Calling _remember_remote_is_before again with a lower value works.
419
418
client_medium._remember_remote_is_before((1, 5))
420
419
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))
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)))
426
428
class TestBzrDirCloningMetaDir(TestRemote):
528
530
self.assertIsInstance(bd, RemoteBzrDir)
529
531
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)
532
556
class TestBzrDirOpenBranch(TestRemote):
584
608
# _get_tree_branch is a form of open_branch, but it should only ask for
585
609
# branch opening, not any other network requests.
611
def open_branch(name=None):
588
612
calls.append("Called")
589
613
return "a-branch"
590
614
transport = MemoryTransport()
663
687
self.assertRaises(errors.NotBranchError,
664
RemoteBzrDirFormat.probe_transport, OldServerTransport())
688
RemoteBzrProber.probe_transport, OldServerTransport())
667
691
class TestBzrDirCreateBranch(TestRemote):
1223
1247
len(branch.repository._real_repository._fallback_repositories))
1225
1249
def test_get_stacked_on_real_branch(self):
1226
base_branch = self.make_branch('base', format='1.6')
1227
stacked_branch = self.make_branch('stacked', format='1.6')
1250
base_branch = self.make_branch('base')
1251
stacked_branch = self.make_branch('stacked')
1228
1252
stacked_branch.set_stacked_on_url('../base')
1229
1253
reference_format = self.get_repo_format()
1230
1254
network_name = reference_format.network_name()
1235
1259
'success', ('branch', branch_network_name))
1236
1260
client.add_expected_call(
1237
1261
'BzrDir.find_repositoryV3', ('stacked/',),
1238
'success', ('ok', '', 'no', 'no', 'yes', network_name))
1262
'success', ('ok', '', 'yes', 'no', 'yes', network_name))
1239
1263
# called twice, once from constructor and then again by us
1240
1264
client.add_expected_call(
1241
1265
'Branch.get_stacked_on_url', ('stacked/',),
1593
1617
def test_get_multi_line_branch_conf(self):
1594
1618
# Make sure that multiple-line branch.conf files are supported
1596
# https://bugs.edge.launchpad.net/bzr/+bug/354075
1620
# https://bugs.launchpad.net/bzr/+bug/354075
1597
1621
client = FakeClient()
1598
1622
client.add_expected_call(
1599
1623
'Branch.get_stacked_on_url', ('memory:///',),
1627
1651
branch.unlock()
1628
1652
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)
1630
1680
def test_backwards_compat_set_option(self):
1631
1681
self.setup_smart_server_with_call_log()
1632
1682
branch = self.make_branch('.')
1639
1689
self.assertLength(10, self.hpss_calls)
1640
1690
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'))
1643
1707
class TestBranchLockWrite(RemoteBranchTestCase):
2192
2256
# Make a repo with a fallback repo, both using a FakeClient.
2193
2257
format = remote.response_tuple_to_repo_format(
2194
('yes', 'no', 'yes', 'fake-network-name'))
2258
('yes', 'no', 'yes', self.get_repo_format().network_name()))
2195
2259
repo, client = self.setup_fake_client_and_repository('quack')
2196
2260
repo._format = format
2197
2261
fallback_repo, ignored = self.setup_fake_client_and_repository(
2199
2263
fallback_repo._client = client
2264
fallback_repo._format = format
2200
2265
repo.add_fallback_repository(fallback_repo)
2201
2266
# First the client should ask the primary repo
2202
2267
client.add_expected_call(
2275
2341
transport_path = 'quack'
2276
2342
repo, client = self.setup_fake_client_and_repository(transport_path)
2277
2343
client.add_success_response('ok', 'a token')
2278
result = repo.lock_write()
2344
token = repo.lock_write().repository_token
2279
2345
self.assertEqual(
2280
2346
[('call', 'Repository.lock_write', ('quack/', ''))],
2282
self.assertEqual('a token', result)
2348
self.assertEqual('a token', token)
2284
2350
def test_lock_write_already_locked(self):
2285
2351
transport_path = 'quack'