23
from bzrlib import bzrdir, errors, smart, tests
23
from bzrlib import bzrdir, errors, pack, smart, tests
24
24
from bzrlib.smart.request import SmartServerResponse
25
25
import bzrlib.smart.bzrdir
26
26
import bzrlib.smart.branch
27
27
import bzrlib.smart.repository
28
from bzrlib.util import bencode
30
31
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
767
768
"extraneous file present in tar file")
771
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithTransport):
773
def test_fetch_revisions(self):
774
backing = self.get_transport()
775
request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
776
tree = self.make_branch_and_memory_tree('.')
779
rev_id1_utf8 = u'\xc8'.encode('utf-8')
780
rev_id2_utf8 = u'\xc9'.encode('utf-8')
781
r1 = tree.commit('1st commit', rev_id=rev_id1_utf8)
782
r1 = tree.commit('2nd commit', rev_id=rev_id2_utf8)
785
response = request.execute(backing.local_abspath(''), rev_id2_utf8)
786
self.assertEqual(('ok',), response.args)
787
from cStringIO import StringIO
788
unpacker = pack.ContainerReader(StringIO(response.body))
790
for [name], read_bytes in unpacker.iter_records():
792
bytes = read_bytes(None)
793
# The bytes should be a valid bencoded string.
794
bencode.bdecode(bytes)
795
# XXX: assert that the bencoded knit records have the right
798
def test_no_such_revision_error(self):
799
backing = self.get_transport()
800
request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
801
repo = self.make_repository('.')
802
rev_id1_utf8 = u'\xc8'.encode('utf-8')
803
response = request.execute(backing.local_abspath(''), rev_id1_utf8)
805
SmartServerResponse(('NoSuchRevision', rev_id1_utf8)),
770
809
class TestSmartServerIsReadonly(tests.TestCaseWithTransport):
772
811
def test_is_readonly_no(self):
820
859
smart.request.request_handlers.get('Repository.gather_stats'),
821
860
smart.repository.SmartServerRepositoryGatherStats)
822
861
self.assertEqual(
823
smart.request.request_handlers.get('Repository.get_revision_graph'),
862
smart.request.request_handlers.get(
863
'Repository.get_revision_graph'),
824
864
smart.repository.SmartServerRepositoryGetRevisionGraph)
825
865
self.assertEqual(
826
866
smart.request.request_handlers.get('Repository.has_revision'),
832
872
smart.request.request_handlers.get('Repository.lock_write'),
833
873
smart.repository.SmartServerRepositoryLockWrite)
834
874
self.assertEqual(
875
smart.request.request_handlers.get(
876
'Repository.stream_knit_data_for_revisions'),
877
smart.repository.SmartServerRepositoryStreamKnitDataForRevisions)
879
smart.request.request_handlers.get('Repository.tarball'),
880
smart.repository.SmartServerRepositoryTarball)
835
882
smart.request.request_handlers.get('Repository.unlock'),
836
883
smart.repository.SmartServerRepositoryUnlock)
837
884
self.assertEqual(
838
smart.request.request_handlers.get('Repository.tarball'),
839
smart.repository.SmartServerRepositoryTarball)
841
885
smart.request.request_handlers.get('Transport.is_readonly'),
842
886
smart.request.SmartServerIsReadonly)