~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Martin Packman
  • Date: 2012-02-01 13:24:42 UTC
  • mto: (6437.23.4 2.5)
  • mto: This revision was merged to the branch mainline in revision 6462.
  • Revision ID: martin.packman@canonical.com-20120201132442-ela7jc4mxv4b058o
Treat path for .bzr.log as unicode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
30
30
from bzrlib import (
31
31
    bencode,
32
32
    branch as _mod_branch,
33
 
    controldir,
 
33
    bzrdir,
34
34
    errors,
35
35
    gpg,
36
36
    inventory_delta,
82
82
 
83
83
    def setUp(self):
84
84
        self.vfs_transport_factory = memory.MemoryServer
85
 
        super(TestCaseWithChrootedTransport, self).setUp()
 
85
        tests.TestCaseWithTransport.setUp(self)
86
86
        self._chroot_server = None
87
87
 
88
88
    def get_transport(self, relpath=None):
121
121
        stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
122
122
            None, 'foo')]),('text', [
123
123
            versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
124
 
        fmt = controldir.format_registry.get('pack-0.92')().repository_format
 
124
        fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
125
125
        bytes = smart_repo._stream_to_byte_stream(stream, fmt)
126
126
        streams = []
127
127
        # Iterate the resulting iterable; checking that we get only one stream
333
333
        self.make_bzrdir('.')
334
334
        request_class = smart_dir.SmartServerRequestCreateRepository
335
335
        request = request_class(backing)
336
 
        reference_bzrdir_format = controldir.format_registry.get('pack-0.92')()
 
336
        reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
337
337
        reference_format = reference_bzrdir_format.repository_format
338
338
        network_name = reference_format.network_name()
339
339
        expected = smart_req.SuccessfulSmartServerResponse(
419
419
        backing = self.get_transport()
420
420
        request = self._request_class(backing)
421
421
        result = self._make_repository_and_result(
422
 
            format='development-subtree')
 
422
            format='dirstate-with-subtree')
423
423
        # check the test will be valid
424
424
        self.assertEqual('yes', result.args[2])
425
425
        self.assertEqual('yes', result.args[3])
430
430
        backing = self.get_transport()
431
431
        request = self._request_class(backing)
432
432
        result = self._make_repository_and_result(
433
 
            format='development-subtree')
 
433
            format='dirstate-with-subtree')
434
434
        # check the test will be valid
435
 
        self.assertEqual('yes', result.args[4])
 
435
        self.assertEqual('no', result.args[4])
436
436
        self.assertEqual(result, request.execute(''))
437
437
 
438
438
 
493
493
        request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
494
494
        self.assertEqual(smart_req.SmartServerResponse(('ok', )),
495
495
            request.execute(''))
496
 
        made_dir = controldir.ControlDir.open_from_transport(backing)
 
496
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
497
497
        # no branch, tree or repository is expected with the current
498
498
        # default formart.
499
499
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
533
533
                                           'False', '', '', '')),
534
534
            request.execute(name, '', 'True', 'False', 'False', '', '', '', '',
535
535
                            'False'))
536
 
        made_dir = controldir.ControlDir.open_from_transport(backing)
 
536
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
537
537
        # no branch, tree or repository is expected with the current
538
538
        # default format.
539
539
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
944
944
        self.assertEqual(
945
945
            smart_req.SmartServerResponse(('ok', )),
946
946
            request.do_body('foo bar baz'))
947
 
        self.assertEqual(
 
947
        self.assertEquals(
948
948
            branch.control_transport.get_bytes('branch.conf'),
949
949
            'foo bar baz')
950
950
        branch.unlock()
1033
1033
        response = request.do_chunk(tag_bytes)
1034
1034
        self.assertEqual(None, response)
1035
1035
        response = request.do_end()
1036
 
        self.assertEqual(
 
1036
        self.assertEquals(
1037
1037
            smart_req.SuccessfulSmartServerResponse(()), response)
1038
1038
        base_branch.unlock()
1039
1039
 
1058
1058
    """Base test case for verbs that implement set_last_revision."""
1059
1059
 
1060
1060
    def setUp(self):
1061
 
        super(SetLastRevisionTestBase, self).setUp()
 
1061
        tests.TestCaseWithMemoryTransport.setUp(self)
1062
1062
        backing_transport = self.get_transport()
1063
1063
        self.request = self.request_class(backing_transport)
1064
1064
        self.tree = self.make_branch_and_memory_tree('.')
1295
1295
        base_branch = self.make_branch('base')
1296
1296
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
1297
1297
        response = request.execute('base')
1298
 
        self.assertEqual(
 
1298
        self.assertEquals(
1299
1299
            smart_req.SuccessfulSmartServerResponse(('',)), response)
1300
1300
 
1301
1301
    def test_get_parent_something(self):
1303
1303
        base_branch.set_parent(self.get_url('foo'))
1304
1304
        request = smart_branch.SmartServerBranchGetParent(self.get_transport())
1305
1305
        response = request.execute('base')
1306
 
        self.assertEqual(
 
1306
        self.assertEquals(
1307
1307
            smart_req.SuccessfulSmartServerResponse(("../foo",)),
1308
1308
            response)
1309
1309
 
1323
1323
        finally:
1324
1324
            branch.unlock()
1325
1325
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1326
 
        # Refresh branch as SetParentLocation modified it
1327
 
        branch = branch.bzrdir.open_branch()
1328
1326
        self.assertEqual(None, branch.get_parent())
1329
1327
 
1330
1328
    def test_set_parent_something(self):
1334
1332
        branch_token, repo_token = self.get_lock_tokens(branch)
1335
1333
        try:
1336
1334
            response = request.execute('base', branch_token, repo_token,
1337
 
                                       'http://bar/')
 
1335
            'http://bar/')
1338
1336
        finally:
1339
1337
            branch.unlock()
1340
1338
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1341
 
        refreshed = _mod_branch.Branch.open(branch.base)
1342
 
        self.assertEqual('http://bar/', refreshed.get_parent())
 
1339
        self.assertEqual('http://bar/', branch.get_parent())
1343
1340
 
1344
1341
 
1345
1342
class TestSmartServerBranchRequestGetTagsBytes(
1352
1349
        request = smart_branch.SmartServerBranchGetTagsBytes(
1353
1350
            self.get_transport())
1354
1351
        response = request.execute('base')
1355
 
        self.assertEqual(
 
1352
        self.assertEquals(
1356
1353
            smart_req.SuccessfulSmartServerResponse(('',)), response)
1357
1354
 
1358
1355
 
1366
1363
        request = smart_branch.SmartServerBranchRequestGetStackedOnURL(
1367
1364
            self.get_transport())
1368
1365
        response = request.execute('stacked')
1369
 
        self.assertEqual(
 
1366
        self.assertEquals(
1370
1367
            smart_req.SmartServerResponse(('ok', '../base')),
1371
1368
            response)
1372
1369
 
1373
1370
 
1374
1371
class TestSmartServerBranchRequestLockWrite(TestLockedBranch):
1375
1372
 
 
1373
    def setUp(self):
 
1374
        tests.TestCaseWithMemoryTransport.setUp(self)
 
1375
 
1376
1376
    def test_lock_write_on_unlocked_branch(self):
1377
1377
        backing = self.get_transport()
1378
1378
        request = smart_branch.SmartServerBranchRequestLockWrite(backing)
1478
1478
 
1479
1479
class TestSmartServerBranchRequestGetPhysicalLockStatus(TestLockedBranch):
1480
1480
 
 
1481
    def setUp(self):
 
1482
        tests.TestCaseWithMemoryTransport.setUp(self)
 
1483
 
1481
1484
    def test_true(self):
1482
1485
        backing = self.get_transport()
1483
1486
        request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1484
1487
            backing)
1485
1488
        branch = self.make_branch('.')
1486
1489
        branch_token, repo_token = self.get_lock_tokens(branch)
1487
 
        self.assertEqual(True, branch.get_physical_lock_status())
 
1490
        self.assertEquals(True, branch.get_physical_lock_status())
1488
1491
        response = request.execute('')
1489
1492
        self.assertEqual(
1490
1493
            smart_req.SmartServerResponse(('yes',)), response)
1495
1498
        request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1496
1499
            backing)
1497
1500
        branch = self.make_branch('.')
1498
 
        self.assertEqual(False, branch.get_physical_lock_status())
 
1501
        self.assertEquals(False, branch.get_physical_lock_status())
1499
1502
        response = request.execute('')
1500
1503
        self.assertEqual(
1501
1504
            smart_req.SmartServerResponse(('no',)), response)
1503
1506
 
1504
1507
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
1505
1508
 
 
1509
    def setUp(self):
 
1510
        tests.TestCaseWithMemoryTransport.setUp(self)
 
1511
 
1506
1512
    def test_unlock_on_locked_branch_and_repo(self):
1507
1513
        backing = self.get_transport()
1508
1514
        request = smart_branch.SmartServerBranchRequestUnlock(backing)
1601
1607
        backing = self.get_transport()
1602
1608
        request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1603
1609
        self.make_repository('.')
1604
 
        self.assertEqual(
 
1610
        self.assertEquals(
1605
1611
            smart_req.SuccessfulSmartServerResponse(("ok", ), ""),
1606
1612
            request.execute(''))
1607
1613
 
1615
1621
        tree.commit(rev_id='origineel', message="message")
1616
1622
        tree.commit(rev_id='nog-een-revisie', message="message")
1617
1623
        tree.unlock()
1618
 
        self.assertEqual(
 
1624
        self.assertEquals(
1619
1625
            smart_req.SuccessfulSmartServerResponse(("ok", ),
1620
1626
                "origineel\nnog-een-revisie"),
1621
1627
            request.execute(''))
1783
1789
        response = request.do_body("rev1\nrev2")
1784
1790
        self.assertTrue(response.is_successful())
1785
1791
        # Format 2a uses serializer format 10
1786
 
        self.assertEqual(response.args, ("ok", "10"))
 
1792
        self.assertEquals(response.args, ("ok", "10"))
1787
1793
 
1788
1794
        self.addCleanup(tree.branch.lock_read().unlock)
1789
1795
        entries = [zlib.compress(record.get_bytes_as("fulltext")) for record in
1804
1810
        response = request.do_body("rev1\nrev2")
1805
1811
        self.assertTrue(response.is_successful())
1806
1812
        # Format 2a uses serializer format 10
1807
 
        self.assertEqual(response.args, ("ok", "10"))
 
1813
        self.assertEquals(response.args, ("ok", "10"))
1808
1814
 
1809
1815
        contents = "".join(response.body_stream)
1810
 
        self.assertEqual(contents, "")
 
1816
        self.assertEquals(contents, "")
1811
1817
 
1812
1818
 
1813
1819
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
1902
1908
        self.assertIs(None, request.execute(''))
1903
1909
        response = request.do_body("thefileid\0somerev\n")
1904
1910
        self.assertTrue(response.is_successful())
1905
 
        self.assertEqual(response.args, ("ok", ))
1906
 
        self.assertEqual("".join(response.body_stream),
 
1911
        self.assertEquals(response.args, ("ok", ))
 
1912
        self.assertEquals("".join(response.body_stream),
1907
1913
            "ok\x000\n" + zlib.compress("somecontents"))
1908
1914
 
1909
1915
    def test_missing(self):
1914
1920
        self.assertIs(None, request.execute(''))
1915
1921
        response = request.do_body("thefileid\0revision\n")
1916
1922
        self.assertTrue(response.is_successful())
1917
 
        self.assertEqual(response.args, ("ok", ))
1918
 
        self.assertEqual("".join(response.body_stream),
 
1923
        self.assertEquals(response.args, ("ok", ))
 
1924
        self.assertEquals("".join(response.body_stream),
1919
1925
            "absent\x00thefileid\x00revision\x000\n")
1920
1926
 
1921
1927
 
2192
2198
 
2193
2199
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
2194
2200
 
 
2201
    def setUp(self):
 
2202
        tests.TestCaseWithMemoryTransport.setUp(self)
 
2203
 
2195
2204
    def test_unlock_on_locked_repo(self):
2196
2205
        backing = self.get_transport()
2197
2206
        request = smart_repo.SmartServerRepositoryUnlock(backing)
2238
2247
    def test_without_write_lock(self):
2239
2248
        backing = self.get_transport()
2240
2249
        repo = self.make_repository('.')
2241
 
        self.assertEqual(False, repo.get_physical_lock_status())
 
2250
        self.assertEquals(False, repo.get_physical_lock_status())
2242
2251
        request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2243
2252
        request = request_class(backing)
2244
2253
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(('no',)),
2611
2620
            None)
2612
2621
        self.server._sockname = ('example.com', 42)
2613
2622
        self.server.run_server_started_hooks()
2614
 
        self.assertEqual(started_calls,
 
2623
        self.assertEquals(started_calls,
2615
2624
            [([self.get_transport().base], 'bzr://example.com:42/')])
2616
 
        self.assertEqual(started_ex_calls,
 
2625
        self.assertEquals(started_ex_calls,
2617
2626
            [([self.get_transport().base], self.server)])
2618
2627
 
2619
2628
    def test_run_server_started_hooks_ipv6(self):
2624
2633
            lambda backing_urls, url: started_calls.append((backing_urls, url)),
2625
2634
            None)
2626
2635
        self.server.run_server_started_hooks()
2627
 
        self.assertEqual(started_calls,
 
2636
        self.assertEquals(started_calls,
2628
2637
                [([self.get_transport().base], 'bzr://:::42/')])
2629
2638
 
2630
2639
    def test_run_server_stopped_hooks(self):
2635
2644
            lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2636
2645
            None)
2637
2646
        self.server.run_server_stopped_hooks()
2638
 
        self.assertEqual(stopped_calls,
 
2647
        self.assertEquals(stopped_calls,
2639
2648
            [([self.get_transport().base], 'bzr://example.com:42/')])
2640
2649
 
2641
2650
 
2657
2666
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2658
2667
 
2659
2668
    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
 
2669
        base_inv = repository.revision_tree(base_revid).inventory
 
2670
        inv = repository.revision_tree(revid).inventory
2662
2671
        inv_delta = inv._make_delta(base_inv)
2663
2672
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2664
2673
        return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2674
2683
        self.assertIs(None, request.execute('', 'unordered'))
2675
2684
        response = request.do_body("somerev\n")
2676
2685
        self.assertTrue(response.is_successful())
2677
 
        self.assertEqual(response.args, ("ok", ))
 
2686
        self.assertEquals(response.args, ("ok", ))
2678
2687
        stream = [('inventory-deltas', [
2679
2688
            versionedfile.FulltextContentFactory('somerev', None, None,
2680
2689
                self._get_serialized_inventory_delta(
2681
2690
                    t.branch.repository, 'null:', 'somerev'))])]
2682
 
        fmt = controldir.format_registry.get('2a')().repository_format
2683
 
        self.assertEqual(
 
2691
        fmt = bzrdir.format_registry.get('2a')().repository_format
 
2692
        self.assertEquals(
2684
2693
            "".join(response.body_stream),
2685
2694
            "".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2686
2695
 
2695
2704
        self.assertIs(None, request.execute('', 'unordered'))
2696
2705
        response = request.do_body("")
2697
2706
        self.assertTrue(response.is_successful())
2698
 
        self.assertEqual(response.args, ("ok", ))
2699
 
        self.assertEqual("".join(response.body_stream),
 
2707
        self.assertEquals(response.args, ("ok", ))
 
2708
        self.assertEquals("".join(response.body_stream),
2700
2709
            "Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")