~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Andrew Starr-Bochicchio
  • Date: 2014-03-30 17:59:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6592.
  • Revision ID: a.starr.b@gmail.com-20140330175929-rd97jstcbau2j1gy
Use LooseVersion from distutils to check Cython version in order to handle non-integers in the version string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
import zlib
29
29
 
30
30
from bzrlib import (
 
31
    bencode,
31
32
    branch as _mod_branch,
32
 
    bzrdir,
 
33
    controldir,
33
34
    errors,
34
35
    gpg,
 
36
    inventory_delta,
35
37
    tests,
36
38
    transport,
37
39
    urlutils,
80
82
 
81
83
    def setUp(self):
82
84
        self.vfs_transport_factory = memory.MemoryServer
83
 
        tests.TestCaseWithTransport.setUp(self)
 
85
        super(TestCaseWithChrootedTransport, self).setUp()
84
86
        self._chroot_server = None
85
87
 
86
88
    def get_transport(self, relpath=None):
119
121
        stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
120
122
            None, 'foo')]),('text', [
121
123
            versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
122
 
        fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
 
124
        fmt = controldir.format_registry.get('pack-0.92')().repository_format
123
125
        bytes = smart_repo._stream_to_byte_stream(stream, fmt)
124
126
        streams = []
125
127
        # Iterate the resulting iterable; checking that we get only one stream
224
226
        self.assertEqual(expected, request.execute('', 'False'))
225
227
 
226
228
 
 
229
class TestSmartServerBzrDirRequestCloningMetaDir(
 
230
    tests.TestCaseWithMemoryTransport):
 
231
    """Tests for BzrDir.checkout_metadir."""
 
232
 
 
233
    def test_checkout_metadir(self):
 
234
        backing = self.get_transport()
 
235
        request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
 
236
            backing)
 
237
        branch = self.make_branch('.', format='2a')
 
238
        response = request.execute('')
 
239
        self.assertEqual(
 
240
            smart_req.SmartServerResponse(
 
241
                ('Bazaar-NG meta directory, format 1\n',
 
242
                 'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
 
243
                 'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
 
244
            response)
 
245
 
 
246
 
227
247
class TestSmartServerBzrDirRequestDestroyBranch(
228
248
    tests.TestCaseWithMemoryTransport):
229
249
    """Tests for BzrDir.destroy_branch."""
313
333
        self.make_bzrdir('.')
314
334
        request_class = smart_dir.SmartServerRequestCreateRepository
315
335
        request = request_class(backing)
316
 
        reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
 
336
        reference_bzrdir_format = controldir.format_registry.get('pack-0.92')()
317
337
        reference_format = reference_bzrdir_format.repository_format
318
338
        network_name = reference_format.network_name()
319
339
        expected = smart_req.SuccessfulSmartServerResponse(
399
419
        backing = self.get_transport()
400
420
        request = self._request_class(backing)
401
421
        result = self._make_repository_and_result(
402
 
            format='dirstate-with-subtree')
 
422
            format='development-subtree')
403
423
        # check the test will be valid
404
424
        self.assertEqual('yes', result.args[2])
405
425
        self.assertEqual('yes', result.args[3])
410
430
        backing = self.get_transport()
411
431
        request = self._request_class(backing)
412
432
        result = self._make_repository_and_result(
413
 
            format='dirstate-with-subtree')
 
433
            format='development-subtree')
414
434
        # check the test will be valid
415
 
        self.assertEqual('no', result.args[4])
 
435
        self.assertEqual('yes', result.args[4])
416
436
        self.assertEqual(result, request.execute(''))
417
437
 
418
438
 
439
459
        self.assertEqual(expected, request.execute(''))
440
460
 
441
461
 
 
462
class TestSmartServerBzrDirRequestGetBranches(
 
463
    tests.TestCaseWithMemoryTransport):
 
464
    """Tests for BzrDir.get_branches."""
 
465
 
 
466
    def test_simple(self):
 
467
        backing = self.get_transport()
 
468
        branch = self.make_branch('.')
 
469
        request_class = smart_dir.SmartServerBzrDirRequestGetBranches
 
470
        request = request_class(backing)
 
471
        local_result = bencode.bencode(
 
472
            {"": ("branch", branch._format.network_name())})
 
473
        expected = smart_req.SuccessfulSmartServerResponse(
 
474
            ("success", ), local_result)
 
475
        self.assertEqual(expected, request.execute(''))
 
476
 
 
477
    def test_empty(self):
 
478
        backing = self.get_transport()
 
479
        dir = self.make_bzrdir('.')
 
480
        request_class = smart_dir.SmartServerBzrDirRequestGetBranches
 
481
        request = request_class(backing)
 
482
        local_result = bencode.bencode({})
 
483
        expected = smart_req.SuccessfulSmartServerResponse(
 
484
            ('success',), local_result)
 
485
        self.assertEqual(expected, request.execute(''))
 
486
 
 
487
 
442
488
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
443
489
 
444
490
    def test_empty_dir(self):
447
493
        request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
448
494
        self.assertEqual(smart_req.SmartServerResponse(('ok', )),
449
495
            request.execute(''))
450
 
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
 
496
        made_dir = controldir.ControlDir.open_from_transport(backing)
451
497
        # no branch, tree or repository is expected with the current
452
498
        # default formart.
453
499
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
466
512
        backing = self.get_transport()
467
513
        request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
468
514
        self.make_bzrdir('subdir')
469
 
        self.assertRaises(errors.FileExists,
 
515
        self.assertRaises(errors.AlreadyControlDirError,
470
516
            request.execute, 'subdir')
471
517
 
472
518
 
487
533
                                           'False', '', '', '')),
488
534
            request.execute(name, '', 'True', 'False', 'False', '', '', '', '',
489
535
                            'False'))
490
 
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
 
536
        made_dir = controldir.ControlDir.open_from_transport(backing)
491
537
        # no branch, tree or repository is expected with the current
492
538
        # default format.
493
539
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
1012
1058
    """Base test case for verbs that implement set_last_revision."""
1013
1059
 
1014
1060
    def setUp(self):
1015
 
        tests.TestCaseWithMemoryTransport.setUp(self)
 
1061
        super(SetLastRevisionTestBase, self).setUp()
1016
1062
        backing_transport = self.get_transport()
1017
1063
        self.request = self.request_class(backing_transport)
1018
1064
        self.tree = self.make_branch_and_memory_tree('.')
1277
1323
        finally:
1278
1324
            branch.unlock()
1279
1325
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
 
1326
        # Refresh branch as SetParentLocation modified it
 
1327
        branch = branch.bzrdir.open_branch()
1280
1328
        self.assertEqual(None, branch.get_parent())
1281
1329
 
1282
1330
    def test_set_parent_something(self):
1286
1334
        branch_token, repo_token = self.get_lock_tokens(branch)
1287
1335
        try:
1288
1336
            response = request.execute('base', branch_token, repo_token,
1289
 
            'http://bar/')
 
1337
                                       'http://bar/')
1290
1338
        finally:
1291
1339
            branch.unlock()
1292
1340
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1293
 
        self.assertEqual('http://bar/', branch.get_parent())
 
1341
        refreshed = _mod_branch.Branch.open(branch.base)
 
1342
        self.assertEqual('http://bar/', refreshed.get_parent())
1294
1343
 
1295
1344
 
1296
1345
class TestSmartServerBranchRequestGetTagsBytes(
1324
1373
 
1325
1374
class TestSmartServerBranchRequestLockWrite(TestLockedBranch):
1326
1375
 
1327
 
    def setUp(self):
1328
 
        tests.TestCaseWithMemoryTransport.setUp(self)
1329
 
 
1330
1376
    def test_lock_write_on_unlocked_branch(self):
1331
1377
        backing = self.get_transport()
1332
1378
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1432
1478
 
1433
1479
class TestSmartServerBranchRequestGetPhysicalLockStatus(TestLockedBranch):
1434
1480
 
1435
 
    def setUp(self):
1436
 
        tests.TestCaseWithMemoryTransport.setUp(self)
1437
 
 
1438
1481
    def test_true(self):
1439
1482
        backing = self.get_transport()
1440
1483
        request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1460
1503
 
1461
1504
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
1462
1505
 
1463
 
    def setUp(self):
1464
 
        tests.TestCaseWithMemoryTransport.setUp(self)
1465
 
 
1466
1506
    def test_unlock_on_locked_branch_and_repo(self):
1467
1507
        backing = self.get_transport()
1468
1508
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
2152
2192
 
2153
2193
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
2154
2194
 
2155
 
    def setUp(self):
2156
 
        tests.TestCaseWithMemoryTransport.setUp(self)
2157
 
 
2158
2195
    def test_unlock_on_locked_repo(self):
2159
2196
        backing = self.get_transport()
2160
2197
        request = smart_repo.SmartServerRepositoryUnlock(backing)
2208
2245
            request.execute('', ))
2209
2246
 
2210
2247
 
 
2248
class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
 
2249
 
 
2250
    def test_reconcile(self):
 
2251
        backing = self.get_transport()
 
2252
        repo = self.make_repository('.')
 
2253
        token = repo.lock_write().repository_token
 
2254
        self.addCleanup(repo.unlock)
 
2255
        request_class = smart_repo.SmartServerRepositoryReconcile
 
2256
        request = request_class(backing)
 
2257
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
 
2258
            ('ok', ),
 
2259
             'garbage_inventories: 0\n'
 
2260
             'inconsistent_parents: 0\n'),
 
2261
            request.execute('', token))
 
2262
 
 
2263
 
2211
2264
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
2212
2265
 
2213
2266
    def test_is_readonly_no(self):
2461
2514
            smart_dir.SmartServerRequestInitializeBzrDir)
2462
2515
        self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2463
2516
            smart_dir.SmartServerRequestBzrDirInitializeEx)
 
2517
        self.assertHandlerEqual('BzrDir.checkout_metadir',
 
2518
            smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2464
2519
        self.assertHandlerEqual('BzrDir.cloning_metadir',
2465
2520
            smart_dir.SmartServerBzrDirRequestCloningMetaDir)
 
2521
        self.assertHandlerEqual('BzrDir.get_branches',
 
2522
            smart_dir.SmartServerBzrDirRequestGetBranches)
2466
2523
        self.assertHandlerEqual('BzrDir.get_config_file',
2467
2524
            smart_dir.SmartServerBzrDirRequestConfigFile)
2468
2525
        self.assertHandlerEqual('BzrDir.open_branch',
2513
2570
            smart_repo.SmartServerRepositoryMakeWorkingTrees)
2514
2571
        self.assertHandlerEqual('Repository.pack',
2515
2572
            smart_repo.SmartServerRepositoryPack)
 
2573
        self.assertHandlerEqual('Repository.reconcile',
 
2574
            smart_repo.SmartServerRepositoryReconcile)
2516
2575
        self.assertHandlerEqual('Repository.tarball',
2517
2576
            smart_repo.SmartServerRepositoryTarball)
2518
2577
        self.assertHandlerEqual('Repository.unlock',
2527
2586
            smart_repo.SmartServerRepositoryAbortWriteGroup)
2528
2587
        self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2529
2588
            smart_repo.SmartServerRepositoryGetSerializerFormat)
 
2589
        self.assertHandlerEqual('VersionedFileRepository.get_inventories',
 
2590
            smart_repo.SmartServerRepositoryGetInventories)
2530
2591
        self.assertHandlerEqual('Transport.is_readonly',
2531
2592
            smart_req.SmartServerIsReadonly)
2532
2593
 
2592
2653
            smart_req.SuccessfulSmartServerResponse(('ok', ), ),
2593
2654
            request.do_body(''))
2594
2655
 
 
2656
 
 
2657
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
 
2658
 
 
2659
    def _get_serialized_inventory_delta(self, repository, base_revid, revid):
 
2660
        base_inv = repository.revision_tree(base_revid).root_inventory
 
2661
        inv = repository.revision_tree(revid).root_inventory
 
2662
        inv_delta = inv._make_delta(base_inv)
 
2663
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
 
2664
        return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
 
2665
 
 
2666
    def test_single(self):
 
2667
        backing = self.get_transport()
 
2668
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
 
2669
        t = self.make_branch_and_tree('.', format='2a')
 
2670
        self.addCleanup(t.lock_write().unlock)
 
2671
        self.build_tree_contents([("file", "somecontents")])
 
2672
        t.add(["file"], ["thefileid"])
 
2673
        t.commit(rev_id='somerev', message="add file")
 
2674
        self.assertIs(None, request.execute('', 'unordered'))
 
2675
        response = request.do_body("somerev\n")
 
2676
        self.assertTrue(response.is_successful())
 
2677
        self.assertEquals(response.args, ("ok", ))
 
2678
        stream = [('inventory-deltas', [
 
2679
            versionedfile.FulltextContentFactory('somerev', None, None,
 
2680
                self._get_serialized_inventory_delta(
 
2681
                    t.branch.repository, 'null:', 'somerev'))])]
 
2682
        fmt = controldir.format_registry.get('2a')().repository_format
 
2683
        self.assertEquals(
 
2684
            "".join(response.body_stream),
 
2685
            "".join(smart_repo._stream_to_byte_stream(stream, fmt)))
 
2686
 
 
2687
    def test_empty(self):
 
2688
        backing = self.get_transport()
 
2689
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
 
2690
        t = self.make_branch_and_tree('.', format='2a')
 
2691
        self.addCleanup(t.lock_write().unlock)
 
2692
        self.build_tree_contents([("file", "somecontents")])
 
2693
        t.add(["file"], ["thefileid"])
 
2694
        t.commit(rev_id='somerev', message="add file")
 
2695
        self.assertIs(None, request.execute('', 'unordered'))
 
2696
        response = request.do_body("")
 
2697
        self.assertTrue(response.is_successful())
 
2698
        self.assertEquals(response.args, ("ok", ))
 
2699
        self.assertEquals("".join(response.body_stream),
 
2700
            "Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")