def test_propagates_data_to_destination(self): destination = mock.Mock(Protocol) protocol = _BodyBufferingProtocol(destination, [], None) protocol.dataReceived(b"foo") destination.dataReceived.assert_called_once_with(b"foo") protocol.dataReceived(b"bar") destination.dataReceived.assert_called_with(b"bar")
def test_buffers_data(self): buffer = [] protocol = _BodyBufferingProtocol(mock.Mock(Protocol), buffer, None) protocol.dataReceived("foo") self.assertEqual(buffer, ["foo"]) protocol.dataReceived("bar") self.assertEqual(buffer, ["foo", "bar"])
def test_propagates_data_to_destination(self): destination = mock.Mock(Protocol) protocol = _BodyBufferingProtocol(destination, [], None) protocol.dataReceived("foo") destination.dataReceived.assert_called_once_with("foo") protocol.dataReceived("bar") destination.dataReceived.assert_called_with("bar")
def test_fires_finished_deferred(self): finished = Deferred() protocol = _BodyBufferingProtocol(mock.Mock(Protocol), [], finished) class TestResponseDone(Exception): pass protocol.connectionLost(TestResponseDone()) self.failureResultOf(finished, TestResponseDone)
def test_propogates_connectionLost_reason(self): destination = mock.Mock(Protocol) protocol = _BodyBufferingProtocol(destination, [], Deferred().addErrback(lambda ign: None)) class TestResponseDone(object): pass reason = TestResponseDone() protocol.connectionLost(reason) destination.connectionLost.assert_called_once_with(reason)
def test_fires_finished_deferred(self): finished = Deferred() protocol = _BodyBufferingProtocol(mock.Mock(Protocol), [], finished) class TestResponseDone(object): pass protocol.connectionLost(TestResponseDone()) self.failureResultOf(finished, TestResponseDone)
def test_propogates_connectionLost_reason(self): destination = mock.Mock(Protocol) protocol = _BodyBufferingProtocol( destination, [], Deferred().addErrback(lambda ign: None)) class TestResponseDone(Exception): pass reason = TestResponseDone() protocol.connectionLost(reason) destination.connectionLost.assert_called_once_with(reason)