/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 bzrlib/tests/test_remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-11-20 10:30:56 UTC
  • mfrom: (3695.2.6 hpss-push-rpc)
  • mto: This revision was merged to the branch mainline in revision 3981.
  • Revision ID: andrew.bennetts@canonical.com-20081120103056-05g6c6nv30ceyxdx
Merge RemoteVersionedFiles class from hpss-push-rpc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1168
1168
    def test_get_parent_map_reconnects_if_unknown_method(self):
1169
1169
        transport_path = 'quack'
1170
1170
        repo, client = self.setup_fake_client_and_repository(transport_path)
1171
 
        client.add_unknown_method_response('Repository,get_parent_map')
 
1171
        client.add_unknown_method_response('Repository.get_parent_map')
1172
1172
        client.add_success_response_with_body('', 'ok')
1173
1173
        self.assertFalse(client._medium._is_remote_before((1, 2)))
1174
1174
        rev_id = 'revision-id'
1509
1509
            client._calls)
1510
1510
 
1511
1511
 
 
1512
class TestVersionedFilesGetParentMap(tests.TestCaseWithTransport):
 
1513
 
 
1514
    def test_backwards_compat(self):
 
1515
        """If the server does not recognise the VersionedFiles.get_parent_map
 
1516
        then the client will fallback to calling get_parent_map on the 'real'
 
1517
        versioned files object.
 
1518
        """
 
1519
        self.transport_server = server.SmartTCPServer_for_testing
 
1520
        self.make_repository('branch')
 
1521
        repo = repository.Repository.open(self.get_url('branch'))
 
1522
        repo._ensure_real()
 
1523
        repo.lock_read()
 
1524
        # Sabotage the real smart medium so that the test will fail if
 
1525
        # something tries to use it after this point.
 
1526
        repo._client._medium._socket = None
 
1527
        # Replace the _real_repository with a test double so that we can
 
1528
        # observe the fallback to using the 'real' object.
 
1529
        class FakeRealVf(object):
 
1530
            def get_parent_map(self, keys):
 
1531
                client._calls.append(('real vf get_parent_map', keys))
 
1532
                return {}
 
1533
        class FakeRealRepo(object):
 
1534
            def __init__(self):
 
1535
                self.revisions = FakeRealVf()
 
1536
            def unlock(self):
 
1537
                pass
 
1538
        repo._real_repository = FakeRealRepo()
 
1539
        # Inject a test double client.
 
1540
        client = FakeClient(repo.bzrdir.root_transport.base)
 
1541
        repo._client = client
 
1542
        # Configure the fake client.
 
1543
        client.add_unknown_method_response('VersionedFiles.get_parent_map')
 
1544
        client.add_success_response_with_body('', 'ok')
 
1545
        # Call get_parent_map.
 
1546
        rev_id = 'revision-id'
 
1547
        repo.revisions.get_parent_map([('rev-id',)])
 
1548
        repo.unlock()
 
1549
        self.assertEqual(
 
1550
            [('call_with_body_bytes_expecting_body',
 
1551
              'VersionedFiles.get_parent_map',
 
1552
              ('extra/branch/', 'revisions', ('rev-id',)),
 
1553
              '\n\n0'),
 
1554
             ('real vf get_parent_map', [('rev-id',)]),
 
1555
             ],
 
1556
            client._calls)
 
1557
        # The medium is now marked as being connected to an older server
 
1558
        self.assertTrue(client._medium._is_remote_before((1, 8)))
 
1559
 
 
1560
 
 
1561
class TestVersionedFilesGetParentMapSerialisation(tests.TestCase):
 
1562
 
 
1563
    def test_serialise_search_recipe_empty(self):
 
1564
        recipe = ([], [], 0)
 
1565
        bytes = remote._serialise_search_tuple_key_recipe(recipe)
 
1566
        self.assertEqual('\n\n0', bytes)
 
1567
 
 
1568
    def test_serialise_search_recipe(self):
 
1569
        start = [('start', 'key', 'one'), ('start', 'key', 'two')]
 
1570
        stop = [('stop', 'key', 'one'), ('stop', 'key', 'two')]
 
1571
        recipe = (start, stop, 123)
 
1572
        bytes = remote._serialise_search_tuple_key_recipe(recipe)
 
1573
        self.assertEqual(
 
1574
            'start key one\x00start key two\nstop key one\x00stop key two\n123',
 
1575
            bytes)
 
1576
 
 
1577
 
1512
1578
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):
1513
1579
    """Base class for unit tests for bzrlib.remote._translate_error."""
1514
1580