/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_smart_transport.py

Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
576
576
 
577
577
class TestSmartServerStreamMedium(tests.TestCase):
578
578
 
 
579
    def setUp(self):
 
580
        super(TestSmartServerStreamMedium, self).setUp()
 
581
        self._captureVar('NO_SMART_VFS', None)
 
582
 
579
583
    def portable_socket_pair(self):
580
584
        """Return a pair of TCP sockets connected to each other.
581
585
        
782
786
 
783
787
    def test_get_error_unexpected(self):
784
788
        """Error reported by server with no specific representation"""
 
789
        self._captureVar('NO_SMART_VFS', None)
785
790
        class FlakyTransport(object):
786
791
            def get_bytes(self, path):
787
792
                raise Exception("some random exception from inside server")
842
847
 
843
848
    def test_smart_transport_has(self):
844
849
        """Checking for file existence over smart."""
 
850
        self._captureVar('NO_SMART_VFS', None)
845
851
        self.backing_transport.put_bytes("foo", "contents of foo\n")
846
852
        self.assertTrue(self.transport.has("foo"))
847
853
        self.assertFalse(self.transport.has("non-foo"))
848
854
 
849
855
    def test_smart_transport_get(self):
850
856
        """Read back a file over smart."""
 
857
        self._captureVar('NO_SMART_VFS', None)
851
858
        self.backing_transport.put_bytes("foo", "contents\nof\nfoo\n")
852
859
        fp = self.transport.get("foo")
853
860
        self.assertEqual('contents\nof\nfoo\n', fp.read())
857
864
        # The path in a raised NoSuchFile exception should be the precise path
858
865
        # asked for by the client. This gives meaningful and unsurprising errors
859
866
        # for users.
 
867
        self._captureVar('NO_SMART_VFS', None)
860
868
        try:
861
869
            self.transport.get('not%20a%20file')
862
870
        except errors.NoSuchFile, e:
883
891
 
884
892
    def test_open_dir(self):
885
893
        """Test changing directory"""
 
894
        self._captureVar('NO_SMART_VFS', None)
886
895
        transport = self.transport
887
896
        self.backing_transport.mkdir('toffee')
888
897
        self.backing_transport.mkdir('toffee/apple')
910
919
 
911
920
    def test_mkdir_error_readonly(self):
912
921
        """TransportNotPossible should be preserved from the backing transport."""
 
922
        self._captureVar('NO_SMART_VFS', None)
913
923
        self.setUpServer(readonly=True)
914
924
        self.assertRaises(errors.TransportNotPossible, self.transport.mkdir,
915
925
            'foo')
922
932
        
923
933
    def test_hello(self):
924
934
        cmd = request.HelloRequest(None)
925
 
        response = cmd.do()
 
935
        response = cmd.execute()
926
936
        self.assertEqual(('ok', '1'), response.args)
927
937
        self.assertEqual(None, response.body)
928
938
        
934
944
        rev_id = wt.commit('add hello')
935
945
        
936
946
        cmd = request.GetBundleRequest(self.get_transport())
937
 
        response = cmd.do('.', rev_id)
 
947
        response = cmd.execute('.', rev_id)
938
948
        bundle = serializer.read_bundle(StringIO(response.body))
939
949
        self.assertEqual((), response.args)
940
950
 
942
952
class SmartServerRequestHandlerTests(tests.TestCaseWithTransport):
943
953
    """Test that call directly into the handler logic, bypassing the network."""
944
954
 
 
955
    def setUp(self):
 
956
        super(SmartServerRequestHandlerTests, self).setUp()
 
957
        self._captureVar('NO_SMART_VFS', None)
 
958
 
945
959
    def build_handler(self, transport):
946
960
        """Returns a handler for the commands in protocol version one."""
947
961
        return smart.SmartServerRequestHandler(transport, request.request_handlers)
957
971
        self.assertEqual(('ok', '1'), handler.response.args)
958
972
        self.assertEqual(None, handler.response.body)
959
973
        
 
974
    def test_disable_vfs_handler_classes_via_environment(self):
 
975
        # VFS handler classes will raise an error from "execute" if NO_SMART_VFS
 
976
        # is set.
 
977
        handler = vfs.HasRequest(None)
 
978
        # set environment variable after construction to make sure it's
 
979
        # examined.
 
980
        # Note that we can safely clobber NO_SMART_VFS here, because setUp has
 
981
        # called _captureVar, so it will be restored to the right state
 
982
        # afterwards.
 
983
        os.environ['NO_SMART_VFS'] = ''
 
984
        self.assertRaises(errors.DisabledMethod, handler.execute)
 
985
 
960
986
    def test_readonly_exception_becomes_transport_not_possible(self):
961
987
        """The response for a read-only error is ('ReadOnlyError')."""
962
988
        handler = self.build_handler(self.get_readonly_transport())
1183
1209
        self.assertTrue(self.end_received)
1184
1210
 
1185
1211
    def test_accept_request_and_body_all_at_once(self):
 
1212
        self._captureVar('NO_SMART_VFS', None)
1186
1213
        mem_transport = memory.MemoryTransport()
1187
1214
        mem_transport.put_bytes('foo', 'abcdefghij')
1188
1215
        out_stream = StringIO()
1437
1464
 
1438
1465
class HTTPTunnellingSmokeTest(tests.TestCaseWithTransport):
1439
1466
    
 
1467
    def setUp(self):
 
1468
        super(HTTPTunnellingSmokeTest, self).setUp()
 
1469
        # We use the VFS layer as part of HTTP tunnelling tests.
 
1470
        self._captureVar('NO_SMART_VFS', None)
 
1471
 
1440
1472
    def _test_bulk_data(self, url_protocol):
1441
1473
        # We should be able to send and receive bulk data in a single message.
1442
1474
        # The 'readv' command in the smart protocol both sends and receives bulk