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)
609
608
# _get_tree_branch is a form of open_branch, but it should only ask for
610
609
# branch opening, not any other network requests.
611
def open_branch(name=None):
613
612
calls.append("Called")
614
613
return "a-branch"
615
614
transport = MemoryTransport()
688
687
self.assertRaises(errors.NotBranchError,
689
RemoteBzrDirFormat.probe_transport, OldServerTransport())
688
RemoteBzrProber.probe_transport, OldServerTransport())
692
691
class TestBzrDirCreateBranch(TestRemote):
1618
1617
def test_get_multi_line_branch_conf(self):
1619
1618
# Make sure that multiple-line branch.conf files are supported
1621
# https://bugs.edge.launchpad.net/bzr/+bug/354075
1620
# https://bugs.launchpad.net/bzr/+bug/354075
1622
1621
client = FakeClient()
1623
1622
client.add_expected_call(
1624
1623
'Branch.get_stacked_on_url', ('memory:///',),
1652
1651
branch.unlock()
1653
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)
1655
1680
def test_backwards_compat_set_option(self):
1656
1681
self.setup_smart_server_with_call_log()
1657
1682
branch = self.make_branch('.')
1664
1689
self.assertLength(10, self.hpss_calls)
1665
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'))
1668
1707
class TestBranchLockWrite(RemoteBranchTestCase):
2301
2341
transport_path = 'quack'
2302
2342
repo, client = self.setup_fake_client_and_repository(transport_path)
2303
2343
client.add_success_response('ok', 'a token')
2304
result = repo.lock_write()
2344
token = repo.lock_write().repository_token
2305
2345
self.assertEqual(
2306
2346
[('call', 'Repository.lock_write', ('quack/', ''))],
2308
self.assertEqual('a token', result)
2348
self.assertEqual('a token', token)
2310
2350
def test_lock_write_already_locked(self):
2311
2351
transport_path = 'quack'