~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
796
796
        request = smart.repository.SmartServerRepositoryGatherStats(backing)
797
797
        repository = self.make_repository('.')
798
798
        stats = repository.gather_stats()
799
 
        size = stats['size']
800
 
        expected_body = 'revisions: 0\nsize: %d\n' % size
 
799
        expected_body = 'revisions: 0\n'
801
800
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
802
801
                         request.execute('', '', 'no'))
803
802
 
816
815
        tree.unlock()
817
816
 
818
817
        stats = tree.branch.repository.gather_stats()
819
 
        size = stats['size']
820
818
        expected_body = ('firstrev: 123456.200 3600\n'
821
819
                         'latestrev: 654321.400 0\n'
822
 
                         'revisions: 2\n'
823
 
                         'size: %d\n' % size)
 
820
                         'revisions: 2\n')
824
821
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
825
822
                         request.execute('',
826
823
                                         rev_id_utf8, 'no'))
841
838
        tree.unlock()
842
839
        stats = tree.branch.repository.gather_stats()
843
840
 
844
 
        size = stats['size']
845
841
        expected_body = ('committers: 2\n'
846
842
                         'firstrev: 123456.200 3600\n'
847
843
                         'latestrev: 654321.400 0\n'
848
 
                         'revisions: 2\n'
849
 
                         'size: %d\n' % size)
 
844
                         'revisions: 2\n')
850
845
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
851
846
                         request.execute('',
852
847
                                         rev_id_utf8, 'yes'))
938
933
            SmartServerResponse(('TokenMismatch',)), response)
939
934
 
940
935
 
941
 
class TestSmartServerRepositoryTarball(tests.TestCaseWithTransport):
942
 
 
943
 
    def test_repository_tarball(self):
944
 
        backing = self.get_transport()
945
 
        request = smart.repository.SmartServerRepositoryTarball(backing)
946
 
        repository = self.make_repository('.')
947
 
        # make some extraneous junk in the repository directory which should
948
 
        # not be copied
949
 
        self.build_tree(['.bzr/repository/extra-junk'])
950
 
        response = request.execute('', 'bz2')
951
 
        self.assertEqual(('ok',), response.args)
952
 
        # body should be a tbz2
953
 
        body_file = StringIO(response.body)
954
 
        body_tar = tarfile.open('body_tar.tbz2', fileobj=body_file,
955
 
            mode='r|bz2')
956
 
        # let's make sure there are some key repository components inside it.
957
 
        # the tarfile returns directories with trailing slashes...
958
 
        names = set([n.rstrip('/') for n in body_tar.getnames()])
959
 
        self.assertTrue('.bzr/repository/lock' in names)
960
 
        self.assertTrue('.bzr/repository/format' in names)
961
 
        self.assertTrue('.bzr/repository/extra-junk' not in names,
962
 
            "extraneous file present in tar file")
963
 
 
964
 
 
965
 
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithMemoryTransport):
966
 
 
967
 
    def test_fetch_revisions(self):
968
 
        backing = self.get_transport()
969
 
        request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
970
 
        tree = self.make_branch_and_memory_tree('.')
971
 
        tree.lock_write()
972
 
        tree.add('')
973
 
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
974
 
        rev_id2_utf8 = u'\xc9'.encode('utf-8')
975
 
        r1 = tree.commit('1st commit', rev_id=rev_id1_utf8)
976
 
        r1 = tree.commit('2nd commit', rev_id=rev_id2_utf8)
977
 
        tree.unlock()
978
 
 
979
 
        response = request.execute('', rev_id2_utf8)
980
 
        self.assertEqual(('ok',), response.args)
981
 
        unpacker = pack.ContainerReader(StringIO(response.body))
982
 
        names = []
983
 
        for [name], read_bytes in unpacker.iter_records():
984
 
            names.append(name)
985
 
            bytes = read_bytes(None)
986
 
            # The bytes should be a valid bencoded string.
987
 
            bencode.bdecode(bytes)
988
 
            # XXX: assert that the bencoded knit records have the right
989
 
            # contents?
990
 
        
991
 
    def test_no_such_revision_error(self):
992
 
        backing = self.get_transport()
993
 
        request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
994
 
        repo = self.make_repository('.')
995
 
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
996
 
        response = request.execute('', rev_id1_utf8)
997
 
        self.assertEqual(
998
 
            SmartServerResponse(('NoSuchRevision', rev_id1_utf8)),
999
 
            response)
1000
 
 
1001
 
 
1002
 
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithMemoryTransport):
1003
 
 
1004
 
    def test_fetch_revisions(self):
1005
 
        backing = self.get_transport()
1006
 
        request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
1007
 
            backing)
1008
 
        tree = self.make_branch_and_memory_tree('.')
1009
 
        tree.lock_write()
1010
 
        tree.add('')
1011
 
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
1012
 
        rev_id2_utf8 = u'\xc9'.encode('utf-8')
1013
 
        tree.commit('1st commit', rev_id=rev_id1_utf8)
1014
 
        tree.commit('2nd commit', rev_id=rev_id2_utf8)
1015
 
        tree.unlock()
1016
 
 
1017
 
        response = request.execute('')
1018
 
        self.assertEqual(None, response)
1019
 
        response = request.do_body("%s\n%s\n1" % (rev_id2_utf8, rev_id1_utf8))
1020
 
        self.assertEqual(('ok',), response.args)
1021
 
        parser = pack.ContainerPushParser()
1022
 
        names = []
1023
 
        for stream_bytes in response.body_stream:
1024
 
            parser.accept_bytes(stream_bytes)
1025
 
            for [name], record_bytes in parser.read_pending_records():
1026
 
                names.append(name)
1027
 
                # The bytes should be a valid bencoded string.
1028
 
                bencode.bdecode(record_bytes)
1029
 
                # XXX: assert that the bencoded knit records have the right
1030
 
                # contents?
1031
 
        
1032
 
    def test_no_such_revision_error(self):
1033
 
        backing = self.get_transport()
1034
 
        request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
1035
 
            backing)
1036
 
        repo = self.make_repository('.')
1037
 
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
1038
 
        response = request.execute('')
1039
 
        self.assertEqual(None, response)
1040
 
        response = request.do_body("%s\n\n1" % (rev_id1_utf8,))
1041
 
        self.assertEqual(
1042
 
            FailedSmartServerResponse(('NoSuchRevision', )),
1043
 
            response)
1044
 
 
1045
 
 
1046
936
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
1047
937
 
1048
938
    def test_is_readonly_no(self):