1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
359
359
a given client_base and transport_base.
361
361
client_medium = medium.SmartClientMedium(client_base)
362
t = transport.get_transport(transport_base)
363
result = client_medium.remote_path_from_transport(t)
362
transport = get_transport(transport_base)
363
result = client_medium.remote_path_from_transport(transport)
364
364
self.assertEqual(expected, result)
366
366
def test_remote_path_from_transport(self):
377
377
a given transport_base and relpath of that transport. (Note that
378
378
HttpTransportBase is a subclass of SmartClientMedium)
380
base_transport = transport.get_transport(transport_base)
380
base_transport = get_transport(transport_base)
381
381
client_medium = base_transport.get_smart_medium()
382
382
cloned_transport = base_transport.clone(relpath)
383
383
result = client_medium.remote_path_from_transport(cloned_transport)
418
418
# Calling _remember_remote_is_before again with a lower value works.
419
419
client_medium._remember_remote_is_before((1, 5))
420
420
self.assertTrue(client_medium._is_remote_before((1, 5)))
421
# If you call _remember_remote_is_before with a higher value it logs a
422
# warning, and continues to remember the lower value.
423
self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
424
client_medium._remember_remote_is_before((1, 9))
425
self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
426
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))
429
426
class TestBzrDirCloningMetaDir(TestRemote):
531
528
self.assertIsInstance(bd, RemoteBzrDir)
532
529
self.assertFinished(client)
534
def test_backwards_compat_hpss_v2(self):
535
client, transport = self.make_fake_client_and_transport()
536
# Monkey-patch fake client to simulate real-world behaviour with v2
537
# server: upon first RPC call detect the protocol version, and because
538
# the version is 2 also do _remember_remote_is_before((1, 6)) before
539
# continuing with the RPC.
540
orig_check_call = client._check_call
541
def check_call(method, args):
542
client._medium._protocol_version = 2
543
client._medium._remember_remote_is_before((1, 6))
544
client._check_call = orig_check_call
545
client._check_call(method, args)
546
client._check_call = check_call
547
client.add_expected_call(
548
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
549
client.add_expected_call(
550
'BzrDir.open', ('quack/',), 'success', ('yes',))
551
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
552
_client=client, _force_probe=True)
553
self.assertIsInstance(bd, RemoteBzrDir)
554
self.assertFinished(client)
557
532
class TestBzrDirOpenBranch(TestRemote):
609
584
# _get_tree_branch is a form of open_branch, but it should only ask for
610
585
# branch opening, not any other network requests.
612
def open_branch(name=None):
613
588
calls.append("Called")
614
589
return "a-branch"
615
590
transport = MemoryTransport()
1248
1223
len(branch.repository._real_repository._fallback_repositories))
1250
1225
def test_get_stacked_on_real_branch(self):
1251
base_branch = self.make_branch('base')
1252
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')
1253
1228
stacked_branch.set_stacked_on_url('../base')
1254
1229
reference_format = self.get_repo_format()
1255
1230
network_name = reference_format.network_name()
1260
1235
'success', ('branch', branch_network_name))
1261
1236
client.add_expected_call(
1262
1237
'BzrDir.find_repositoryV3', ('stacked/',),
1263
'success', ('ok', '', 'yes', 'no', 'yes', network_name))
1238
'success', ('ok', '', 'no', 'no', 'yes', network_name))
1264
1239
# called twice, once from constructor and then again by us
1265
1240
client.add_expected_call(
1266
1241
'Branch.get_stacked_on_url', ('stacked/',),
1618
1593
def test_get_multi_line_branch_conf(self):
1619
1594
# Make sure that multiple-line branch.conf files are supported
1621
# https://bugs.launchpad.net/bzr/+bug/354075
1596
# https://bugs.edge.launchpad.net/bzr/+bug/354075
1622
1597
client = FakeClient()
1623
1598
client.add_expected_call(
1624
1599
'Branch.get_stacked_on_url', ('memory:///',),
1652
1627
branch.unlock()
1653
1628
self.assertFinished(client)
1655
def test_set_option_with_dict(self):
1656
client = FakeClient()
1657
client.add_expected_call(
1658
'Branch.get_stacked_on_url', ('memory:///',),
1659
'error', ('NotStacked',),)
1660
client.add_expected_call(
1661
'Branch.lock_write', ('memory:///', '', ''),
1662
'success', ('ok', 'branch token', 'repo token'))
1663
encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1664
client.add_expected_call(
1665
'Branch.set_config_option_dict', ('memory:///', 'branch token',
1666
'repo token', encoded_dict_value, 'foo', ''),
1668
client.add_expected_call(
1669
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1671
transport = MemoryTransport()
1672
branch = self.make_remote_branch(transport, client)
1674
config = branch._get_config()
1676
{'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
1679
self.assertFinished(client)
1681
1630
def test_backwards_compat_set_option(self):
1682
1631
self.setup_smart_server_with_call_log()
1683
1632
branch = self.make_branch('.')
1690
1639
self.assertLength(10, self.hpss_calls)
1691
1640
self.assertEqual('value', branch._get_config().get_option('name'))
1693
def test_backwards_compat_set_option_with_dict(self):
1694
self.setup_smart_server_with_call_log()
1695
branch = self.make_branch('.')
1696
verb = 'Branch.set_config_option_dict'
1697
self.disable_verb(verb)
1699
self.addCleanup(branch.unlock)
1700
self.reset_smart_call_log()
1701
config = branch._get_config()
1702
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1703
config.set_option(value_dict, 'name')
1704
self.assertLength(10, self.hpss_calls)
1705
self.assertEqual(value_dict, branch._get_config().get_option('name'))
1708
1643
class TestBranchLockWrite(RemoteBranchTestCase):
2257
2192
# Make a repo with a fallback repo, both using a FakeClient.
2258
2193
format = remote.response_tuple_to_repo_format(
2259
('yes', 'no', 'yes', self.get_repo_format().network_name()))
2194
('yes', 'no', 'yes', 'fake-network-name'))
2260
2195
repo, client = self.setup_fake_client_and_repository('quack')
2261
2196
repo._format = format
2262
2197
fallback_repo, ignored = self.setup_fake_client_and_repository(
2264
2199
fallback_repo._client = client
2265
fallback_repo._format = format
2266
2200
repo.add_fallback_repository(fallback_repo)
2267
2201
# First the client should ask the primary repo
2268
2202
client.add_expected_call(
2342
2275
transport_path = 'quack'
2343
2276
repo, client = self.setup_fake_client_and_repository(transport_path)
2344
2277
client.add_success_response('ok', 'a token')
2345
token = repo.lock_write().repository_token
2278
result = repo.lock_write()
2346
2279
self.assertEqual(
2347
2280
[('call', 'Repository.lock_write', ('quack/', ''))],
2349
self.assertEqual('a token', token)
2282
self.assertEqual('a token', result)
2351
2284
def test_lock_write_already_locked(self):
2352
2285
transport_path = 'quack'