~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

Small optimisation: don't bother trying RPCs from >= 1.6 if the server doesn't support protocol v3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2709
2709
        self.assertCallDoesNotBreakMedium('method', ('args',), u'body')
2710
2710
 
2711
2711
 
2712
 
class MockMedium(object):
 
2712
class MockMedium(medium.SmartClientMedium):
2713
2713
    """A mock medium that can be used to test _SmartClient.
2714
2714
    
2715
2715
    It can be given a series of requests to expect (and responses it should
2726
2726
    """
2727
2727
 
2728
2728
    def __init__(self):
2729
 
        self.base = 'dummy base'
 
2729
        super(MockMedium, self).__init__('dummy base')
2730
2730
        self._mock_request = _MockMediumRequest(self)
2731
2731
        self._expected_events = []
2732
 
        self._protocol_version = None
2733
2732
        
2734
2733
    def expect_request(self, request_bytes, response_bytes,
2735
2734
                       allow_partial_read=False):
2866
2865
        # medium, and the smart_client returns the response from the server.
2867
2866
        self.assertEqual(('response value',), result)
2868
2867
        self.assertEqual([], medium._expected_events)
 
2868
        # Also, the v3 works then the server should be assumed to support RPCs
 
2869
        # introduced in 1.6.
 
2870
        self.assertTrue(medium._is_remote_at_least((1, 6)))
2869
2871
 
2870
2872
    def test_version_two_server(self):
2871
2873
        """If the server only speaks protocol 2, the client will first try
2904
2906
        self.assertEqual(('another response',), result)
2905
2907
        self.assertEqual([], medium._expected_events)
2906
2908
 
 
2909
        # Also, because v3 is not supported, the client medium should assume
 
2910
        # that RPCs introduced in 1.6 aren't supported either.
 
2911
        self.assertFalse(medium._is_remote_at_least((1, 6)))
 
2912
 
2907
2913
    def test_unknown_version(self):
2908
2914
        """If the server does not use any known (or at least supported)
2909
2915
        protocol version, a SmartProtocolError is raised.