24
24
Tests for low-level protocol encoding are found in test_smart_transport.
28
27
from StringIO import StringIO
32
31
from bzrlib import bzrdir, errors, pack, smart, tests
33
from bzrlib.smart.request import (
34
FailedSmartServerResponse,
36
SuccessfulSmartServerResponse,
32
from bzrlib.smart.request import SmartServerResponse
38
33
import bzrlib.smart.bzrdir
39
34
import bzrlib.smart.branch
40
35
import bzrlib.smart.repository
530
525
request.execute, backing.local_abspath('subdir'))
533
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithTransport):
535
def test_trivial_bzipped(self):
536
# This tests that the wire encoding is actually bzipped
537
backing = self.get_transport()
538
request = smart.repository.SmartServerRepositoryGetParentMap(backing)
539
tree = self.make_branch_and_memory_tree('.')
541
self.assertEqual(None,
542
request.execute(backing.local_abspath(''), 'missing-id'))
543
# Note that it returns a body (of '' bzipped).
545
SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
546
request.do_body('\n\n0\n'))
549
528
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
551
530
def test_none_argument(self):
838
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithTransport):
840
def test_fetch_revisions(self):
841
backing = self.get_transport()
842
request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
844
tree = self.make_branch_and_memory_tree('.')
847
rev_id1_utf8 = u'\xc8'.encode('utf-8')
848
rev_id2_utf8 = u'\xc9'.encode('utf-8')
849
tree.commit('1st commit', rev_id=rev_id1_utf8)
850
tree.commit('2nd commit', rev_id=rev_id2_utf8)
853
response = request.execute(backing.local_abspath(''))
854
self.assertEqual(None, response)
855
response = request.do_body("%s\n%s\n1" % (rev_id2_utf8, rev_id1_utf8))
856
self.assertEqual(('ok',), response.args)
857
from cStringIO import StringIO
858
parser = pack.ContainerPushParser()
860
for stream_bytes in response.body_stream:
861
parser.accept_bytes(stream_bytes)
862
for [name], record_bytes in parser.read_pending_records():
864
# The bytes should be a valid bencoded string.
865
bencode.bdecode(record_bytes)
866
# XXX: assert that the bencoded knit records have the right
869
def test_no_such_revision_error(self):
870
backing = self.get_transport()
871
request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
873
repo = self.make_repository('.')
874
rev_id1_utf8 = u'\xc8'.encode('utf-8')
875
response = request.execute(backing.local_abspath(''))
876
self.assertEqual(None, response)
877
response = request.do_body("%s\n\n1" % (rev_id1_utf8,))
879
FailedSmartServerResponse(('NoSuchRevision', )),
883
817
class TestSmartServerIsReadonly(tests.TestCaseWithTransport):
885
819
def test_is_readonly_no(self):
933
867
smart.request.request_handlers.get('Repository.gather_stats'),
934
868
smart.repository.SmartServerRepositoryGatherStats)
935
869
self.assertEqual(
936
smart.request.request_handlers.get('Repository.get_parent_map'),
937
smart.repository.SmartServerRepositoryGetParentMap)
939
870
smart.request.request_handlers.get(
940
871
'Repository.get_revision_graph'),
941
872
smart.repository.SmartServerRepositoryGetRevisionGraph)
949
880
smart.request.request_handlers.get('Repository.lock_write'),
950
881
smart.repository.SmartServerRepositoryLockWrite)
951
882
self.assertEqual(
883
smart.request.request_handlers.get(
884
'Repository.stream_knit_data_for_revisions'),
885
smart.repository.SmartServerRepositoryStreamKnitDataForRevisions)
952
887
smart.request.request_handlers.get('Repository.tarball'),
953
888
smart.repository.SmartServerRepositoryTarball)
954
889
self.assertEqual(