214
214
dir = self.make_bzrdir('.')
215
215
local_result = dir.cloning_metadir()
216
216
reference = _mod_branch.BranchReferenceFormat().initialize(
217
dir, target_branch=referenced_branch)
217
dir, referenced_branch)
218
218
reference_url = _mod_branch.BranchReferenceFormat().get_reference(dir)
219
219
# The server shouldn't try to follow the branch reference, so it's fine
220
220
# if the referenced branch isn't reachable.
767
767
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
769
769
def get_lock_tokens(self, branch):
770
branch_token = branch.lock_write().branch_token
771
repo_token = branch.repository.lock_write().repository_token
770
branch_token = branch.lock_write()
771
repo_token = branch.repository.lock_write()
772
772
branch.repository.unlock()
773
773
return branch_token, repo_token
805
class TestSmartServerBranchRequestSetConfigOptionDict(TestLockedBranch):
808
TestLockedBranch.setUp(self)
809
# A dict with non-ascii keys and values to exercise unicode
811
self.encoded_value_dict = (
812
'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde')
814
'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
816
def test_value_name(self):
817
branch = self.make_branch('.')
818
request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
819
branch.bzrdir.root_transport)
820
branch_token, repo_token = self.get_lock_tokens(branch)
821
config = branch._get_config()
822
result = request.execute('', branch_token, repo_token,
823
self.encoded_value_dict, 'foo', '')
824
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
825
self.assertEqual(self.value_dict, config.get_option('foo'))
829
def test_value_name_section(self):
830
branch = self.make_branch('.')
831
request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
832
branch.bzrdir.root_transport)
833
branch_token, repo_token = self.get_lock_tokens(branch)
834
config = branch._get_config()
835
result = request.execute('', branch_token, repo_token,
836
self.encoded_value_dict, 'foo', 'gam')
837
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
838
self.assertEqual(self.value_dict, config.get_option('foo', 'gam'))
843
805
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
844
806
# Only called when the branch format and tags match [yay factory
845
807
# methods] so only need to test straight forward cases.
1114
class TestSmartServerBranchRequestSetParent(TestLockedBranch):
1076
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
1116
1078
def test_set_parent_none(self):
1117
1079
branch = self.make_branch('base', format="1.9")
1120
1082
branch.unlock()
1121
1083
request = smart_branch.SmartServerBranchRequestSetParentLocation(
1122
1084
self.get_transport())
1123
branch_token, repo_token = self.get_lock_tokens(branch)
1085
branch_token = branch.lock_write()
1086
repo_token = branch.repository.lock_write()
1125
1088
response = request.execute('base', branch_token, repo_token, '')
1090
branch.repository.unlock()
1127
1091
branch.unlock()
1128
1092
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1129
1093
self.assertEqual(None, branch.get_parent())
1132
1096
branch = self.make_branch('base', format="1.9")
1133
1097
request = smart_branch.SmartServerBranchRequestSetParentLocation(
1134
1098
self.get_transport())
1135
branch_token, repo_token = self.get_lock_tokens(branch)
1099
branch_token = branch.lock_write()
1100
repo_token = branch.repository.lock_write()
1137
1102
response = request.execute('base', branch_token, repo_token,
1105
branch.repository.unlock()
1140
1106
branch.unlock()
1141
1107
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1142
1108
self.assertEqual('http://bar/', branch.get_parent())
1199
1165
backing = self.get_transport()
1200
1166
request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1201
1167
branch = self.make_branch('.')
1202
branch_token = branch.lock_write().branch_token
1168
branch_token = branch.lock_write()
1203
1169
branch.leave_lock_in_place()
1204
1170
branch.unlock()
1205
1171
response = request.execute('')
1214
1180
backing = self.get_transport()
1215
1181
request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1216
1182
branch = self.make_branch('.', format='knit')
1217
branch_token, repo_token = self.get_lock_tokens(branch)
1183
branch_token = branch.lock_write()
1184
repo_token = branch.repository.lock_write()
1185
branch.repository.unlock()
1218
1186
branch.leave_lock_in_place()
1219
1187
branch.repository.leave_lock_in_place()
1220
1188
branch.unlock()
1235
1203
backing = self.get_transport()
1236
1204
request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1237
1205
branch = self.make_branch('.', format='knit')
1238
branch_token, repo_token = self.get_lock_tokens(branch)
1206
branch_token = branch.lock_write()
1207
repo_token = branch.repository.lock_write()
1208
branch.repository.unlock()
1239
1209
branch.leave_lock_in_place()
1240
1210
branch.repository.leave_lock_in_place()
1241
1211
branch.unlock()
1256
1226
request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1257
1227
branch = self.make_branch('.', format='knit')
1258
1228
repo = branch.repository
1259
repo_token = repo.lock_write().repository_token
1229
repo_token = repo.lock_write()
1260
1230
repo.leave_lock_in_place()
1262
1232
response = request.execute('')
1279
1249
self.assertEqual('LockFailed', error_name)
1282
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
1252
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithMemoryTransport):
1284
1254
def setUp(self):
1285
1255
tests.TestCaseWithMemoryTransport.setUp(self)
1289
1259
request = smart_branch.SmartServerBranchRequestUnlock(backing)
1290
1260
branch = self.make_branch('.', format='knit')
1291
1261
# Lock the branch
1292
branch_token, repo_token = self.get_lock_tokens(branch)
1262
branch_token = branch.lock_write()
1263
repo_token = branch.repository.lock_write()
1264
branch.repository.unlock()
1293
1265
# Unlock the branch (and repo) object, leaving the physical locks
1295
1267
branch.leave_lock_in_place()
1319
1291
request = smart_branch.SmartServerBranchRequestUnlock(backing)
1320
1292
branch = self.make_branch('.', format='knit')
1321
1293
# Lock the repository.
1322
repo_token = branch.repository.lock_write().repository_token
1294
repo_token = branch.repository.lock_write()
1323
1295
branch.repository.leave_lock_in_place()
1324
1296
branch.repository.unlock()
1325
1297
# Issue branch lock_write request on the unlocked branch (with locked
1327
response = request.execute('', 'branch token', repo_token)
1299
response = request.execute(
1300
'', 'branch token', repo_token)
1328
1301
self.assertEqual(
1329
1302
smart_req.SmartServerResponse(('TokenMismatch',)), response)
1637
1610
backing = self.get_transport()
1638
1611
request = smart_repo.SmartServerRepositoryLockWrite(backing)
1639
1612
repository = self.make_repository('.', format='knit')
1640
repo_token = repository.lock_write().repository_token
1613
repo_token = repository.lock_write()
1641
1614
repository.leave_lock_in_place()
1642
1615
repository.unlock()
1643
1616
response = request.execute('')
1685
1658
request = smart_repo.SmartServerRepositoryInsertStreamLocked(
1687
1660
repository = self.make_repository('.', format='knit')
1688
lock_token = repository.lock_write().repository_token
1661
lock_token = repository.lock_write()
1689
1662
response = request.execute('', '', lock_token)
1690
1663
self.assertEqual(None, response)
1691
1664
response = request.do_chunk(self.make_empty_byte_stream(repository))
1699
1672
request = smart_repo.SmartServerRepositoryInsertStreamLocked(
1701
1674
repository = self.make_repository('.', format='knit')
1702
lock_token = repository.lock_write().repository_token
1675
lock_token = repository.lock_write()
1703
1676
self.assertRaises(
1704
1677
errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1705
1678
repository.unlock()
1714
1687
backing = self.get_transport()
1715
1688
request = smart_repo.SmartServerRepositoryUnlock(backing)
1716
1689
repository = self.make_repository('.', format='knit')
1717
token = repository.lock_write().repository_token
1690
token = repository.lock_write()
1718
1691
repository.leave_lock_in_place()
1719
1692
repository.unlock()
1720
1693
response = request.execute('', token)