Skip to content

Instantly share code, notes, and snippets.

@richvdh
Created September 18, 2018 08:25
Show Gist options
  • Select an option

  • Save richvdh/9d741f851fbf82e5b7a485c45e3888be to your computer and use it in GitHub Desktop.

Select an option

Save richvdh/9d741f851fbf82e5b7a485c45e3888be to your computer and use it in GitHub Desktop.
def test_client_sends_body(self):
d = self.cl.post_json(
"testserv:8008", "foo/bar", timeout=10000,
data={"a": "b"},
)
self.pump()
clients = self.reactor.tcpClients
self.assertEqual(len(clients), 1)
client = clients[0][2].buildProtocol(None)
# XXX is there a way to do this without a pair of intermediary StringTransports?
client_transport = proto_helpers.StringTransport()
client.makeConnection(client_transport)
client_transport.producer.resumeProducing()
server_transport = proto_helpers.StringTransport()
server = HTTPChannel()
server.makeConnection(server_transport)
server.dataReceived(client_transport.value())
self.assertEqual(len(server.requests), 1)
request = server.requests[0]
content = request.content.read()
self.assertEqual(content, '{"a":"b"}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment