1332
1332
self.assertEqual('rejection message', err.msg)
1335
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
1336
"""Getting the branch configuration should use an abstract method not vfs.
1335
class TestBranchGetSetConfig(RemoteBranchTestCase):
1339
1337
def test_get_branch_conf(self):
1340
raise tests.KnownFailure('branch.conf is not retrieved by get_config_file')
1341
## # We should see that branch.get_config() does a single rpc to get the
1342
## # remote configuration file, abstracting away where that is stored on
1343
## # the server. However at the moment it always falls back to using the
1344
## # vfs, and this would need some changes in config.py.
1346
## # in an empty branch we decode the response properly
1347
## client = FakeClient([(('ok', ), '# config file body')], self.get_url())
1348
## # we need to make a real branch because the remote_branch.control_files
1349
## # will trigger _ensure_real.
1350
## branch = self.make_branch('quack')
1351
## transport = branch.bzrdir.root_transport
1352
## # we do not want bzrdir to make any remote calls
1353
## bzrdir = RemoteBzrDir(transport, _client=False)
1354
## branch = RemoteBranch(bzrdir, None, _client=client)
1355
## config = branch.get_config()
1356
## self.assertEqual(
1357
## [('call_expecting_body', 'Branch.get_config_file', ('quack/',))],
1338
# in an empty branch we decode the response properly
1339
client = FakeClient()
1340
client.add_expected_call(
1341
'Branch.get_stacked_on_url', ('memory:///',),
1342
'error', ('NotStacked',),)
1343
client.add_success_response_with_body('# config file body', 'ok')
1344
transport = MemoryTransport()
1345
branch = self.make_remote_branch(transport, client)
1346
config = branch.get_config()
1347
config.has_explicit_nickname()
1349
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
1350
('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
1353
def test_get_multi_line_branch_conf(self):
1354
# Make sure that multiple-line branch.conf files are supported
1356
# https://bugs.edge.launchpad.net/bzr/+bug/354075
1357
client = FakeClient()
1358
client.add_expected_call(
1359
'Branch.get_stacked_on_url', ('memory:///',),
1360
'error', ('NotStacked',),)
1361
client.add_success_response_with_body('a = 1\nb = 2\nc = 3\n', 'ok')
1362
transport = MemoryTransport()
1363
branch = self.make_remote_branch(transport, client)
1364
config = branch.get_config()
1365
self.assertEqual(u'2', config.get_user_option('b'))
1367
def test_set_option(self):
1368
client = FakeClient()
1369
client.add_expected_call(
1370
'Branch.get_stacked_on_url', ('memory:///',),
1371
'error', ('NotStacked',),)
1372
client.add_expected_call(
1373
'Branch.lock_write', ('memory:///', '', ''),
1374
'success', ('ok', 'branch token', 'repo token'))
1375
client.add_expected_call(
1376
'Branch.set_config_option', ('memory:///', 'branch token',
1377
'repo token', 'foo', 'bar', ''),
1379
client.add_expected_call(
1380
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1382
transport = MemoryTransport()
1383
branch = self.make_remote_branch(transport, client)
1385
config = branch._get_config()
1386
config.set_option('foo', 'bar')
1388
client.finished_test()
1390
def test_backwards_compat_set_option(self):
1391
self.setup_smart_server_with_call_log()
1392
branch = self.make_branch('.')
1393
verb = 'Branch.set_config_option'
1394
self.disable_verb(verb)
1396
self.addCleanup(branch.unlock)
1397
self.reset_smart_call_log()
1398
branch._get_config().set_option('value', 'name')
1399
self.assertLength(10, self.hpss_calls)
1400
self.assertEqual('value', branch._get_config().get_option('name'))
1361
1403
class TestBranchLockWrite(RemoteBranchTestCase):
1673
1715
'more-missing']))
1674
1716
self.assertLength(1, self.hpss_calls)
1718
def disableExtraResults(self):
1719
old_flag = SmartServerRepositoryGetParentMap.no_extra_results
1720
SmartServerRepositoryGetParentMap.no_extra_results = True
1722
SmartServerRepositoryGetParentMap.no_extra_results = old_flag
1723
self.addCleanup(reset_values)
1725
def test_null_cached_missing_and_stop_key(self):
1726
self.setup_smart_server_with_call_log()
1727
# Make a branch with a single revision.
1728
builder = self.make_branch_builder('foo')
1729
builder.start_series()
1730
builder.build_snapshot('first', None, [
1731
('add', ('', 'root-id', 'directory', ''))])
1732
builder.finish_series()
1733
branch = builder.get_branch()
1734
repo = branch.repository
1735
self.assertIsInstance(repo, RemoteRepository)
1736
# Stop the server from sending extra results.
1737
self.disableExtraResults()
1739
self.addCleanup(repo.unlock)
1740
self.reset_smart_call_log()
1741
graph = repo.get_graph()
1742
# Query for 'first' and 'null:'. Because 'null:' is a parent of
1743
# 'first' it will be a candidate for the stop_keys of subsequent
1744
# requests, and because 'null:' was queried but not returned it will be
1745
# cached as missing.
1746
self.assertEqual({'first': ('null:',)},
1747
graph.get_parent_map(['first', 'null:']))
1748
# Now query for another key. This request will pass along a recipe of
1749
# start and stop keys describing the already cached results, and this
1750
# recipe's revision count must be correct (or else it will trigger an
1751
# error from the server).
1752
self.assertEqual({}, graph.get_parent_map(['another-key']))
1753
# This assertion guards against disableExtraResults silently failing to
1754
# work, thus invalidating the test.
1755
self.assertLength(2, self.hpss_calls)
1676
1757
def test_get_parent_map_gets_ghosts_from_result(self):
1677
1758
# asking for a revision should negatively cache close ghosts in its