def test_send(self):
     finished = defer.Deferred()
     handler = log_client.ResponseBodyHandler(finished)
     transport = proto_helpers.StringTransportWithDisconnection()
     handler.makeConnection(transport)
     transport.protocol = handler
     handler.dataReceived("test")
     transport.loseConnection()
     finished.addCallback(self.assertEqual, "test")
     return finished
 def test_buffer_overflow(self):
     original = FLAGS.response_buffer_size_bytes
     FLAGS.response_buffer_size_bytes = 10
     test_msg = "x" * 11
     finished = defer.Deferred()
     handler = log_client.ResponseBodyHandler(finished)
     transport = proto_helpers.StringTransportWithDisconnection()
     handler.makeConnection(transport)
     transport.protocol = handler
     handler.dataReceived(test_msg)
     transport.loseConnection()
     # TODO(ekasper): find a more elegant and robust way to save flags.
     FLAGS.response_buffer_size_bytes = original
     return self.assertFailure(finished,
                               log_client.HTTPResponseSizeExceededError)
 def test_send_chunks(self):
     test_msg = "x" * 1024
     chunk_size = 100
     finished = defer.Deferred()
     handler = log_client.ResponseBodyHandler(finished)
     transport = proto_helpers.StringTransportWithDisconnection()
     handler.makeConnection(transport)
     transport.protocol = handler
     sent = 0
     while sent < len(test_msg):
         handler.dataReceived(test_msg[sent:sent + chunk_size])
         sent += chunk_size
     transport.loseConnection()
     finished.addCallback(self.assertEqual, test_msg)
     return finished