/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_smart.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-22 02:05:12 UTC
  • mto: (6973.12.2 python3-k)
  • mto: This revision was merged to the branch mainline in revision 6992.
  • Revision ID: jelmer@jelmer.uk-20180522020512-btpj2jchdlehi3en
Add more bees.

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
 
122
122
    def test_repeated_substreams_same_kind_are_one_stream(self):
123
123
        # Make a stream - an iterable of bytestrings.
124
 
        stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
125
 
            None, 'foo')]), ('text', [
126
 
            versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
 
124
        stream = [('text', [versionedfile.FulltextContentFactory((b'k1',), None,
 
125
            None, b'foo')]), ('text', [
 
126
            versionedfile.FulltextContentFactory((b'k2',), None, None, b'bar')])]
127
127
        fmt = controldir.format_registry.get('pack-0.92')().repository_format
128
128
        bytes = smart_repo._stream_to_byte_stream(stream, fmt)
129
129
        streams = []
141
141
    def test__eq__(self):
142
142
        self.assertEqual(smart_req.SmartServerResponse((b'ok', )),
143
143
            smart_req.SmartServerResponse((b'ok', )))
144
 
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), 'body'),
145
 
            smart_req.SmartServerResponse((b'ok', ), 'body'))
 
144
        self.assertEqual(smart_req.SmartServerResponse((b'ok', ), b'body'),
 
145
            smart_req.SmartServerResponse((b'ok', ), b'body'))
146
146
        self.assertNotEqual(smart_req.SmartServerResponse((b'ok', )),
147
147
            smart_req.SmartServerResponse((b'notok', )))
148
 
        self.assertNotEqual(smart_req.SmartServerResponse((b'ok', ), 'body'),
 
148
        self.assertNotEqual(smart_req.SmartServerResponse((b'ok', ), b'body'),
149
149
            smart_req.SmartServerResponse((b'ok', )))
150
150
        self.assertNotEqual(None,
151
151
            smart_req.SmartServerResponse((b'ok', )))
210
210
        expected = smart_req.SuccessfulSmartServerResponse(
211
211
            (local_result.network_name(),
212
212
            local_result.repository_format.network_name(),
213
 
            ('branch', local_result.get_branch_format().network_name())))
214
 
        self.assertEqual(expected, request.execute('', 'False'))
 
213
            (b'branch', local_result.get_branch_format().network_name())))
 
214
        self.assertEqual(expected, request.execute(b'', b'False'))
215
215
 
216
216
    def test_cloning_metadir_reference(self):
217
217
        """The request fails when bzrdir contains a branch reference."""
228
228
        request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
229
229
        request = request_class(backing)
230
230
        expected = smart_req.FailedSmartServerResponse((b'BranchReference',))
231
 
        self.assertEqual(expected, request.execute('', 'False'))
 
231
        self.assertEqual(expected, request.execute(b'', b'False'))
232
232
 
233
233
 
234
234
class TestSmartServerBzrDirRequestCloningMetaDir(
240
240
        request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
241
241
            backing)
242
242
        branch = self.make_branch('.', format='2a')
243
 
        response = request.execute('')
 
243
        response = request.execute(b'')
244
244
        self.assertEqual(
245
245
            smart_req.SmartServerResponse(
246
 
                ('Bazaar-NG meta directory, format 1\n',
247
 
                 'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
248
 
                 'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
 
246
                (b'Bazaar-NG meta directory, format 1\n',
 
247
                 b'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
 
248
                 b'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
249
249
            response)
250
250
 
251
251
 
260
260
        request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
261
261
        request = request_class(backing)
262
262
        expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
263
 
        self.assertEqual(expected, request.execute('', None))
 
263
        self.assertEqual(expected, request.execute(b'', None))
264
264
 
265
265
    def test_destroy_branch_named(self):
266
266
        """A named branch can be removed."""
270
270
        request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
271
271
        request = request_class(backing)
272
272
        expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
273
 
        self.assertEqual(expected, request.execute('', "branchname"))
 
273
        self.assertEqual(expected, request.execute(b'', "branchname"))
274
274
 
275
275
    def test_destroy_branch_missing(self):
276
276
        """An error is raised if the branch didn't exist."""
279
279
        request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
280
280
        request = request_class(backing)
281
281
        expected = smart_req.FailedSmartServerResponse((b'nobranch',), None)
282
 
        self.assertEqual(expected, request.execute('', "branchname"))
 
282
        self.assertEqual(expected, request.execute(b'', b"branchname"))
283
283
 
284
284
 
285
285
class TestSmartServerBzrDirRequestHasWorkingTree(
316
316
        request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
317
317
        request = request_class(backing)
318
318
        expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
319
 
        self.assertEqual(expected, request.execute(''))
 
319
        self.assertEqual(expected, request.execute(b''))
320
320
 
321
321
    def test_destroy_repository_missing(self):
322
322
        """An error is raised if the repository didn't exist."""
325
325
        request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
326
326
        request = request_class(backing)
327
327
        expected = smart_req.FailedSmartServerResponse(
328
 
            ('norepository',), None)
329
 
        self.assertEqual(expected, request.execute(''))
 
328
            (b'norepository',), None)
 
329
        self.assertEqual(expected, request.execute(b''))
330
330
 
331
331
 
332
332
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
342
342
        reference_format = reference_bzrdir_format.repository_format
343
343
        network_name = reference_format.network_name()
344
344
        expected = smart_req.SuccessfulSmartServerResponse(
345
 
            ('ok', 'no', 'no', 'no', network_name))
346
 
        self.assertEqual(expected, request.execute('', network_name, 'True'))
 
345
            (b'ok', b'no', b'no', b'no', network_name))
 
346
        self.assertEqual(expected, request.execute(b'', network_name, b'True'))
347
347
 
348
348
 
349
349
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
355
355
        request = self._request_class(backing)
356
356
        self.make_controldir('.')
357
357
        self.assertEqual(smart_req.SmartServerResponse((b'norepository', )),
358
 
            request.execute(''))
 
358
            request.execute(b''))
359
359
 
360
360
    def test_nonshared_repository(self):
361
361
        # nonshared repositorys only allow 'find' to return a handle when the
410
410
        self.assertEqual(result, request.execute(b''))
411
411
        self.make_controldir('subdir')
412
412
        result2 = smart_req.SmartServerResponse(
413
 
            result.args[0:1] + ('..', ) + result.args[2:])
 
413
            result.args[0:1] + (b'..', ) + result.args[2:])
414
414
        self.assertEqual(result2,
415
415
            request.execute(b'subdir'))
416
416
        self.make_controldir('subdir/deeper')
417
417
        result3 = smart_req.SmartServerResponse(
418
 
            result.args[0:1] + ('../..', ) + result.args[2:])
 
418
            result.args[0:1] + (b'../..', ) + result.args[2:])
419
419
        self.assertEqual(result3,
420
420
            request.execute(b'subdir/deeper'))
421
421
 
460
460
        dir = self.make_controldir('.')
461
461
        request_class = smart_dir.SmartServerBzrDirRequestConfigFile
462
462
        request = request_class(backing)
463
 
        expected = smart_req.SuccessfulSmartServerResponse((), '')
 
463
        expected = smart_req.SuccessfulSmartServerResponse((), b'')
464
464
        self.assertEqual(expected, request.execute(b''))
465
465
 
466
466
 
474
474
        request_class = smart_dir.SmartServerBzrDirRequestGetBranches
475
475
        request = request_class(backing)
476
476
        local_result = bencode.bencode(
477
 
            {"": ("branch", branch._format.network_name())})
 
477
            {b"": (b"branch", branch._format.network_name())})
478
478
        expected = smart_req.SuccessfulSmartServerResponse(
479
479
            (b"success", ), local_result)
480
480
        self.assertEqual(expected, request.execute(b''))
534
534
        name = self.make_controldir('reference')._format.network_name()
535
535
        request = smart_dir.SmartServerRequestBzrDirInitializeEx(backing)
536
536
        self.assertEqual(
537
 
            smart_req.SmartServerResponse((b'', '', '', '', '', '', name,
538
 
                                           'False', '', '', '')),
 
537
            smart_req.SmartServerResponse((b'', b'', b'', b'', b'', b'', name,
 
538
                                           b'False', b'', b'', b'')),
539
539
            request.execute(name, b'', b'True', b'False', b'False', b'', b'', b'', b'',
540
540
                            b'False'))
541
541
        made_dir = controldir.ControlDir.open_from_transport(backing)
626
626
        bd.create_repository()
627
627
        bd.create_branch()
628
628
        bd.create_workingtree()
629
 
        self.assertEqual(smart_req.SmartServerResponse((b'yes', 'yes')),
 
629
        self.assertEqual(smart_req.SmartServerResponse((b'yes', b'yes')),
630
630
            request.execute(b''))
631
631
 
632
632
 
645
645
        backing = self.get_transport()
646
646
        request = smart_dir.SmartServerRequestOpenBranch(backing)
647
647
        self.make_branch('.')
648
 
        self.assertEqual(smart_req.SmartServerResponse((b'ok', '')),
 
648
        self.assertEqual(smart_req.SmartServerResponse((b'ok', b'')),
649
649
            request.execute(b''))
650
650
 
651
651
    def test_branch_reference(self):
783
783
            request.teardown_jail()
784
784
        expected_format = feature._format.network_name()
785
785
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
786
 
                ('branch', expected_format)),
 
786
                (b'branch', expected_format)),
787
787
                         response)
788
788
        self.assertLength(1, opened_branches)
789
789
 
839
839
        branch = self.make_branch('branch')
840
840
        checkout = branch.create_checkout('reference', lightweight=True)
841
841
        self.assertRaises(errors.NotBranchError,
842
 
            request.execute, 'checkout')
 
842
            request.execute, b'checkout')
843
843
 
844
844
 
845
845
class TestSmartServerBranchRequestLastRevisionInfo(
859
859
        request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
860
860
        branch = self.make_branch('.')
861
861
        def last_revision_info():
862
 
            raise errors.GhostRevisionsHaveNoRevno('revid1', 'revid2')
 
862
            raise errors.GhostRevisionsHaveNoRevno(b'revid1', b'revid2')
863
863
        self.overrideAttr(branch, 'last_revision_info', last_revision_info)
864
864
        self.assertRaises(errors.GhostRevisionsHaveNoRevno,
865
865
            request.do_with_branch, branch)
901
901
        r1 = tree.commit('1st commit')
902
902
        tree.unlock()
903
903
        self.assertEqual(
904
 
            smart_req.SmartServerResponse((b'ok', '1')),
 
904
            smart_req.SmartServerResponse((b'ok', b'1')),
905
905
            request.execute(b'', r1))
906
906
 
907
907
    def test_not_found(self):
1129
1129
        # its repository.
1130
1130
        self.make_tree_with_two_commits()
1131
1131
        rev_id_utf8 = u'\xc8'.encode('utf-8')
1132
 
        self.tree.branch.set_last_revision_info(0, 'null:')
 
1132
        self.tree.branch.set_last_revision_info(0, b'null:')
1133
1133
        self.assertEqual(
1134
 
            (0, 'null:'), self.tree.branch.last_revision_info())
 
1134
            (0, b'null:'), self.tree.branch.last_revision_info())
1135
1135
        # We can update the branch to a revision that is present in the
1136
1136
        # repository.
1137
1137
        self.assertRequestSucceeds(rev_id_utf8, 1)
1145
1145
        self.make_tree_with_two_commits()
1146
1146
        rev_id_utf8 = u'\xc8'.encode('utf-8')
1147
1147
        self.assertEqual(
1148
 
            (2, 'rev-2'), self.tree.branch.last_revision_info())
 
1148
            (2, b'rev-2'), self.tree.branch.last_revision_info())
1149
1149
        self.assertRequestSucceeds(rev_id_utf8, 1)
1150
1150
        self.assertEqual(
1151
1151
            (1, rev_id_utf8), self.tree.branch.last_revision_info())
1161
1161
            'pre_change_branch_tip', hook_that_rejects, None)
1162
1162
        self.assertEqual(
1163
1163
            smart_req.FailedSmartServerResponse(
1164
 
                ('TipChangeRejected', rejection_message.encode('utf-8'))),
1165
 
            self.set_last_revision('null:', 0))
 
1164
                (b'TipChangeRejected', rejection_message.encode('utf-8'))),
 
1165
            self.set_last_revision(b'null:', 0))
1166
1166
 
1167
1167
 
1168
1168
class TestSmartServerBranchRequestSetLastRevision(
1173
1173
 
1174
1174
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1175
1175
        return self.request.execute(
1176
 
            '', branch_token, repo_token, revision_id)
 
1176
            b'', branch_token, repo_token, revision_id)
1177
1177
 
1178
1178
 
1179
1179
class TestSmartServerBranchRequestSetLastRevisionInfo(
1184
1184
 
1185
1185
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1186
1186
        return self.request.execute(
1187
 
            '', branch_token, repo_token, revno, revision_id)
 
1187
            b'', branch_token, repo_token, revno, revision_id)
1188
1188
 
1189
1189
    def test_NoSuchRevision(self):
1190
1190
        """Branch.set_last_revision_info does not have to return
1201
1201
 
1202
1202
    def _set_last_revision(self, revision_id, revno, branch_token, repo_token):
1203
1203
        return self.request.execute(
1204
 
            '', branch_token, repo_token, revision_id, 0, 0)
 
1204
            b'', branch_token, repo_token, revision_id, 0, 0)
1205
1205
 
1206
1206
    def assertRequestSucceeds(self, revision_id, revno):
1207
1207
        response = self.set_last_revision(revision_id, revno)
1216
1216
        self.make_tree_with_two_commits()
1217
1217
        rev_id_utf8 = u'\xc8'.encode('utf-8')
1218
1218
        self.assertEqual(
1219
 
            (2, 'rev-2'), self.tree.branch.last_revision_info())
 
1219
            (2, b'rev-2'), self.tree.branch.last_revision_info())
1220
1220
        # If allow_overwrite_descendant flag is 0, then trying to set the tip
1221
1221
        # to an older revision ID has no effect.
1222
1222
        branch_token, repo_token = self.lock_branch()
1223
1223
        response = self.request.execute(
1224
 
            '', branch_token, repo_token, rev_id_utf8, 0, 0)
 
1224
            b'', branch_token, repo_token, rev_id_utf8, 0, 0)
1225
1225
        self.assertEqual(
1226
 
            smart_req.SuccessfulSmartServerResponse((b'ok', 2, 'rev-2')),
 
1226
            smart_req.SuccessfulSmartServerResponse((b'ok', 2, b'rev-2')),
1227
1227
            response)
1228
1228
        self.assertEqual(
1229
 
            (2, 'rev-2'), self.tree.branch.last_revision_info())
 
1229
            (2, b'rev-2'), self.tree.branch.last_revision_info())
1230
1230
 
1231
1231
        # If allow_overwrite_descendant flag is 1, then setting the tip to an
1232
1232
        # ancestor works.
1233
1233
        response = self.request.execute(
1234
 
            '', branch_token, repo_token, rev_id_utf8, 0, 1)
 
1234
            b'', branch_token, repo_token, rev_id_utf8, 0, 1)
1235
1235
        self.assertEqual(
1236
1236
            smart_req.SuccessfulSmartServerResponse((b'ok', 1, rev_id_utf8)),
1237
1237
            response)
1276
1276
        self.make_branch_with_divergent_history()
1277
1277
        branch_token, repo_token = self.lock_branch()
1278
1278
        response = self.request.execute(
1279
 
            '', branch_token, repo_token, 'child-1', 1, 0)
 
1279
            b'', branch_token, repo_token, b'child-1', 1, 0)
1280
1280
        self.assertEqual(
1281
 
            smart_req.SuccessfulSmartServerResponse((b'ok', 2, 'child-1')),
 
1281
            smart_req.SuccessfulSmartServerResponse((b'ok', 2, b'child-1')),
1282
1282
            response)
1283
1283
        self.unlock_branch()
1284
1284
        # The branch tip was changed.
1285
 
        self.assertEqual('child-1', self.tree.branch.last_revision())
 
1285
        self.assertEqual(b'child-1', self.tree.branch.last_revision())
1286
1286
 
1287
1287
 
1288
1288
class TestSmartServerBranchBreakLock(tests.TestCaseWithMemoryTransport):
1545
1545
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
1546
1546
        branch = self.make_branch('.', format='knit')
1547
1547
        response = request.execute(
1548
 
            '', 'branch token', 'repo token')
 
1548
            b'', b'branch token', b'repo token')
1549
1549
        self.assertEqual(
1550
1550
            smart_req.SmartServerResponse((b'TokenMismatch',)), response)
1551
1551
 
1559
1559
        branch.repository.unlock()
1560
1560
        # Issue branch lock_write request on the unlocked branch (with locked
1561
1561
        # repo).
1562
 
        response = request.execute(b'', 'branch token', repo_token)
 
1562
        response = request.execute(b'', b'branch token', repo_token)
1563
1563
        self.assertEqual(
1564
1564
            smart_req.SmartServerResponse((b'TokenMismatch',)), response)
1565
1565
        # Cleanup
1581
1581
        self.make_repository('.', shared=True)
1582
1582
        self.make_controldir('subdir')
1583
1583
        self.assertRaises(errors.NoRepositoryPresent,
1584
 
            request.execute, 'subdir')
 
1584
            request.execute, b'subdir')
1585
1585
 
1586
1586
 
1587
1587
class TestSmartServerRepositoryAddSignatureText(tests.TestCaseWithMemoryTransport):
1600
1600
            b'rev1', *write_group_tokens))
1601
1601
        response = request.do_body('somesignature')
1602
1602
        self.assertTrue(response.is_successful())
1603
 
        self.assertEqual(response.args[0], 'ok')
 
1603
        self.assertEqual(response.args[0], b'ok')
1604
1604
        write_group_tokens = response.args[1:]
1605
1605
        tree.branch.repository.resume_write_group(write_group_tokens)
1606
1606
        tree.branch.repository.commit_write_group()
1959
1959
        tree.add('')
1960
1960
        r1 = tree.commit('a commit', rev_id=b'A')
1961
1961
        tree.unlock()
1962
 
        self.assertTrue(tree.branch.repository.has_revision('A'))
 
1962
        self.assertTrue(tree.branch.repository.has_revision(b'A'))
1963
1963
        self.assertEqual(smart_req.SmartServerResponse((b'no', )),
1964
1964
            request.execute(b'', b'A'))
1965
1965
 
2087
2087
        repo.commit_write_group()
2088
2088
        expected_body = (
2089
2089
            b'-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
2090
 
            Testament.from_revision(repo, 'A').as_short_text() +
 
2090
            Testament.from_revision(repo, b'A').as_short_text() +
2091
2091
            b'-----END PSEUDO-SIGNED CONTENT-----\n')
2092
2092
        self.assertEqual(
2093
2093
            smart_req.SmartServerResponse((b'ok', ), expected_body),