/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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-04-09 07:36:41 UTC
  • mfrom: (3297.3.7 unknown-response)
  • Revision ID: pqm@pqm.ubuntu.com-20080409073641-pvhyvdyt42fph5xf
Better infrastructure for dealing with 'bad request' responses from a
        smart server. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1603
1603
        smart_protocol.call_with_body_readv_array(('foo', ), [(1,2),(5,6)])
1604
1604
        self.assertEqual(expected_bytes, output.getvalue())
1605
1605
 
 
1606
    def _test_client_read_response_tuple_raises_UnknownSmartMethod(self,
 
1607
            server_bytes):
 
1608
        server_bytes = (
 
1609
            "error\x01Generic bzr smart protocol error: bad request 'foo'\n")
 
1610
        input = StringIO(server_bytes)
 
1611
        output = StringIO()
 
1612
        client_medium = medium.SmartSimplePipesClientMedium(input, output)
 
1613
        request = client_medium.get_request()
 
1614
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
 
1615
        smart_protocol.call('foo')
 
1616
        self.assertRaises(
 
1617
            errors.UnknownSmartMethod, smart_protocol.read_response_tuple)
 
1618
        # The request has been finished.  There is no body to read, and
 
1619
        # attempts to read one will fail.
 
1620
        self.assertRaises(
 
1621
            errors.ReadingCompleted, smart_protocol.read_body_bytes)
 
1622
 
 
1623
    def test_client_read_response_tuple_raises_UnknownSmartMethod(self):
 
1624
        """read_response_tuple raises UnknownSmartMethod if the response says
 
1625
        the server did not recognise the request.
 
1626
        """
 
1627
        server_bytes = (
 
1628
            "error\x01Generic bzr smart protocol error: bad request 'foo'\n")
 
1629
        self._test_client_read_response_tuple_raises_UnknownSmartMethod(
 
1630
            server_bytes)
 
1631
 
 
1632
    def test_client_read_response_tuple_raises_UnknownSmartMethod_0_11(self):
 
1633
        """read_response_tuple also raises UnknownSmartMethod if the response
 
1634
        from a bzr 0.11 says the server did not recognise the request.
 
1635
 
 
1636
        (bzr 0.11 sends a slightly different error message to later versions.)
 
1637
        """
 
1638
        server_bytes = (
 
1639
            "error\x01Generic bzr smart protocol error: bad request u'foo'\n")
 
1640
        self._test_client_read_response_tuple_raises_UnknownSmartMethod(
 
1641
            server_bytes)
 
1642
 
1606
1643
    def test_client_read_body_bytes_all(self):
1607
1644
        # read_body_bytes should decode the body bytes from the wire into
1608
1645
        # a response.
1932
1969
        smart_protocol.read_response_tuple(False)
1933
1970
        self.assertEqual(True, smart_protocol.response_status)
1934
1971
 
 
1972
    def test_client_read_response_tuple_raises_UnknownSmartMethod(self):
 
1973
        """read_response_tuple raises UnknownSmartMethod if the response is
 
1974
        says the server did not recognise the request.
 
1975
        """
 
1976
        server_bytes = (
 
1977
            protocol.RESPONSE_VERSION_TWO +
 
1978
            "failed\n" +
 
1979
            "error\x01Generic bzr smart protocol error: bad request 'foo'\n")
 
1980
        input = StringIO(server_bytes)
 
1981
        output = StringIO()
 
1982
        client_medium = medium.SmartSimplePipesClientMedium(input, output)
 
1983
        request = client_medium.get_request()
 
1984
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
 
1985
        smart_protocol.call('foo')
 
1986
        self.assertRaises(
 
1987
            errors.UnknownSmartMethod, smart_protocol.read_response_tuple)
 
1988
        self.assertEqual(False, smart_protocol.response_status)
 
1989
        # The request has been finished.  There is no body to read, and
 
1990
        # attempts to read one will fail.
 
1991
        self.assertRaises(
 
1992
            errors.ReadingCompleted, smart_protocol.read_body_bytes)
 
1993
 
1935
1994
    def test_client_read_body_bytes_all(self):
1936
1995
        # read_body_bytes should decode the body bytes from the wire into
1937
1996
        # a response.