938
933
SmartServerResponse(('TokenMismatch',)), response)
941
class TestSmartServerRepositoryTarball(tests.TestCaseWithTransport):
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
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,
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")
965
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithMemoryTransport):
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('.')
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)
979
response = request.execute('', rev_id2_utf8)
980
self.assertEqual(('ok',), response.args)
981
unpacker = pack.ContainerReader(StringIO(response.body))
983
for [name], read_bytes in unpacker.iter_records():
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
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)
998
SmartServerResponse(('NoSuchRevision', rev_id1_utf8)),
1002
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithMemoryTransport):
1004
def test_fetch_revisions(self):
1005
backing = self.get_transport()
1006
request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
1008
tree = self.make_branch_and_memory_tree('.')
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)
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()
1023
for stream_bytes in response.body_stream:
1024
parser.accept_bytes(stream_bytes)
1025
for [name], record_bytes in parser.read_pending_records():
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
1032
def test_no_such_revision_error(self):
1033
backing = self.get_transport()
1034
request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
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,))
1042
FailedSmartServerResponse(('NoSuchRevision', )),
1046
936
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
1048
938
def test_is_readonly_no(self):