~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Alexander Belchenko
  • Date: 2010-06-17 08:53:15 UTC
  • mfrom: (5300 +trunk)
  • mto: (5303.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5305.
  • Revision ID: bialix@ukr.net-20100617085315-hr8186zck57zn35s
merge bzr.dev; fix NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
        dir = self.make_bzrdir('.')
215
215
        local_result = dir.cloning_metadir()
216
216
        reference = _mod_branch.BranchReferenceFormat().initialize(
217
 
            dir, referenced_branch)
 
217
            dir, target_branch=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):
768
768
 
769
769
    def get_lock_tokens(self, branch):
770
 
        branch_token = branch.lock_write()
771
 
        repo_token = branch.repository.lock_write()
 
770
        branch_token = branch.lock_write().branch_token
 
771
        repo_token = branch.repository.lock_write().repository_token
772
772
        branch.repository.unlock()
773
773
        return branch_token, repo_token
774
774
 
802
802
        branch.unlock()
803
803
 
804
804
 
 
805
class TestSmartServerBranchRequestSetConfigOptionDict(TestLockedBranch):
 
806
 
 
807
    def setUp(self):
 
808
        TestLockedBranch.setUp(self)
 
809
        # A dict with non-ascii keys and values to exercise unicode
 
810
        # roundtripping.
 
811
        self.encoded_value_dict = (
 
812
            'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde')
 
813
        self.value_dict = {
 
814
            'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
 
815
 
 
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'))
 
826
        # Cleanup
 
827
        branch.unlock()
 
828
 
 
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'))
 
839
        # Cleanup
 
840
        branch.unlock()
 
841
 
 
842
 
805
843
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
806
844
    # Only called when the branch format and tags match [yay factory
807
845
    # methods] so only need to test straight forward cases.
1073
1111
            response)
1074
1112
 
1075
1113
 
1076
 
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
 
1114
class TestSmartServerBranchRequestSetParent(TestLockedBranch):
1077
1115
 
1078
1116
    def test_set_parent_none(self):
1079
1117
        branch = self.make_branch('base', format="1.9")
1082
1120
        branch.unlock()
1083
1121
        request = smart_branch.SmartServerBranchRequestSetParentLocation(
1084
1122
            self.get_transport())
1085
 
        branch_token = branch.lock_write()
1086
 
        repo_token = branch.repository.lock_write()
 
1123
        branch_token, repo_token = self.get_lock_tokens(branch)
1087
1124
        try:
1088
1125
            response = request.execute('base', branch_token, repo_token, '')
1089
1126
        finally:
1090
 
            branch.repository.unlock()
1091
1127
            branch.unlock()
1092
1128
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1093
1129
        self.assertEqual(None, branch.get_parent())
1096
1132
        branch = self.make_branch('base', format="1.9")
1097
1133
        request = smart_branch.SmartServerBranchRequestSetParentLocation(
1098
1134
            self.get_transport())
1099
 
        branch_token = branch.lock_write()
1100
 
        repo_token = branch.repository.lock_write()
 
1135
        branch_token, repo_token = self.get_lock_tokens(branch)
1101
1136
        try:
1102
1137
            response = request.execute('base', branch_token, repo_token,
1103
1138
            'http://bar/')
1104
1139
        finally:
1105
 
            branch.repository.unlock()
1106
1140
            branch.unlock()
1107
1141
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1108
1142
        self.assertEqual('http://bar/', branch.get_parent())
1137
1171
            response)
1138
1172
 
1139
1173
 
1140
 
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):
 
1174
class TestSmartServerBranchRequestLockWrite(TestLockedBranch):
1141
1175
 
1142
1176
    def setUp(self):
1143
1177
        tests.TestCaseWithMemoryTransport.setUp(self)
1165
1199
        backing = self.get_transport()
1166
1200
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1167
1201
        branch = self.make_branch('.')
1168
 
        branch_token = branch.lock_write()
 
1202
        branch_token = branch.lock_write().branch_token
1169
1203
        branch.leave_lock_in_place()
1170
1204
        branch.unlock()
1171
1205
        response = request.execute('')
1180
1214
        backing = self.get_transport()
1181
1215
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1182
1216
        branch = self.make_branch('.', format='knit')
1183
 
        branch_token = branch.lock_write()
1184
 
        repo_token = branch.repository.lock_write()
1185
 
        branch.repository.unlock()
 
1217
        branch_token, repo_token = self.get_lock_tokens(branch)
1186
1218
        branch.leave_lock_in_place()
1187
1219
        branch.repository.leave_lock_in_place()
1188
1220
        branch.unlock()
1203
1235
        backing = self.get_transport()
1204
1236
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1205
1237
        branch = self.make_branch('.', format='knit')
1206
 
        branch_token = branch.lock_write()
1207
 
        repo_token = branch.repository.lock_write()
1208
 
        branch.repository.unlock()
 
1238
        branch_token, repo_token = self.get_lock_tokens(branch)
1209
1239
        branch.leave_lock_in_place()
1210
1240
        branch.repository.leave_lock_in_place()
1211
1241
        branch.unlock()
1226
1256
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1227
1257
        branch = self.make_branch('.', format='knit')
1228
1258
        repo = branch.repository
1229
 
        repo_token = repo.lock_write()
 
1259
        repo_token = repo.lock_write().repository_token
1230
1260
        repo.leave_lock_in_place()
1231
1261
        repo.unlock()
1232
1262
        response = request.execute('')
1249
1279
        self.assertEqual('LockFailed', error_name)
1250
1280
 
1251
1281
 
1252
 
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithMemoryTransport):
 
1282
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
1253
1283
 
1254
1284
    def setUp(self):
1255
1285
        tests.TestCaseWithMemoryTransport.setUp(self)
1259
1289
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
1260
1290
        branch = self.make_branch('.', format='knit')
1261
1291
        # Lock the branch
1262
 
        branch_token = branch.lock_write()
1263
 
        repo_token = branch.repository.lock_write()
1264
 
        branch.repository.unlock()
 
1292
        branch_token, repo_token = self.get_lock_tokens(branch)
1265
1293
        # Unlock the branch (and repo) object, leaving the physical locks
1266
1294
        # in place.
1267
1295
        branch.leave_lock_in_place()
1291
1319
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
1292
1320
        branch = self.make_branch('.', format='knit')
1293
1321
        # Lock the repository.
1294
 
        repo_token = branch.repository.lock_write()
 
1322
        repo_token = branch.repository.lock_write().repository_token
1295
1323
        branch.repository.leave_lock_in_place()
1296
1324
        branch.repository.unlock()
1297
1325
        # Issue branch lock_write request on the unlocked branch (with locked
1298
1326
        # repo).
1299
 
        response = request.execute(
1300
 
            '', 'branch token', repo_token)
 
1327
        response = request.execute('', 'branch token', repo_token)
1301
1328
        self.assertEqual(
1302
1329
            smart_req.SmartServerResponse(('TokenMismatch',)), response)
1303
1330
        # Cleanup
1610
1637
        backing = self.get_transport()
1611
1638
        request = smart_repo.SmartServerRepositoryLockWrite(backing)
1612
1639
        repository = self.make_repository('.', format='knit')
1613
 
        repo_token = repository.lock_write()
 
1640
        repo_token = repository.lock_write().repository_token
1614
1641
        repository.leave_lock_in_place()
1615
1642
        repository.unlock()
1616
1643
        response = request.execute('')
1658
1685
        request = smart_repo.SmartServerRepositoryInsertStreamLocked(
1659
1686
            backing)
1660
1687
        repository = self.make_repository('.', format='knit')
1661
 
        lock_token = repository.lock_write()
 
1688
        lock_token = repository.lock_write().repository_token
1662
1689
        response = request.execute('', '', lock_token)
1663
1690
        self.assertEqual(None, response)
1664
1691
        response = request.do_chunk(self.make_empty_byte_stream(repository))
1672
1699
        request = smart_repo.SmartServerRepositoryInsertStreamLocked(
1673
1700
            backing)
1674
1701
        repository = self.make_repository('.', format='knit')
1675
 
        lock_token = repository.lock_write()
 
1702
        lock_token = repository.lock_write().repository_token
1676
1703
        self.assertRaises(
1677
1704
            errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1678
1705
        repository.unlock()
1687
1714
        backing = self.get_transport()
1688
1715
        request = smart_repo.SmartServerRepositoryUnlock(backing)
1689
1716
        repository = self.make_repository('.', format='knit')
1690
 
        token = repository.lock_write()
 
1717
        token = repository.lock_write().repository_token
1691
1718
        repository.leave_lock_in_place()
1692
1719
        repository.unlock()
1693
1720
        response = request.execute('', token)