Fix test, and remove custom status text feature

This commit is contained in:
Andrew Godwin 2016-03-11 10:29:17 -08:00
parent a6e11d55a4
commit ef22ac9528
2 changed files with 3 additions and 28 deletions

View File

@ -155,11 +155,7 @@ class WebRequest(http.Request):
raise ValueError("Got multiple Response messages for %s!" % self.reply_channel)
self._got_response_start = True
# Write code
status_text = message.get("status_text", None)
if isinstance(status_text, six.text_type):
logger.warn("HTTP status text for %s was text - should be bytes", self.reply_channel)
status_text = status_text.encode("ascii")
self.setResponseCode(message['status'], status_text)
self.setResponseCode(message['status'])
# Write headers
for header, value in message.get("headers", {}):
# Shim code from old ASGI version, can be removed after a while

View File

@ -39,7 +39,7 @@ class TestHTTPProtocol(TestCase):
self.assertEqual(message['scheme'], "http")
self.assertEqual(message['path'], b"/test/")
self.assertEqual(message['query_string'], b"foo=bar")
self.assertEqual(message['headers'], {"host": b"somewhere.com"})
self.assertEqual(message['headers'], [(b"host", b"somewhere.com")])
self.assertFalse(message.get("body", None))
self.assertTrue(message['reply_channel'])
# Send back an example response
@ -49,29 +49,8 @@ class TestHTTPProtocol(TestCase):
"status": 201,
"status_text": b"Created",
"content": b"OH HAI",
"headers": [["X-Test", b"Boom!"]],
"headers": [[b"X-Test", b"Boom!"]],
}
)
# Make sure that comes back right on the protocol
self.assertEqual(self.tr.value(), b"HTTP/1.1 201 Created\r\nTransfer-Encoding: chunked\r\nX-Test: Boom!\r\n\r\n6\r\nOH HAI\r\n0\r\n\r\n")
def test_custom_status_text(self):
"""
Tests basic HTTP parsing
"""
# Send a simple request to the protocol
self.proto.dataReceived(
b"GET /test/?foo=bar HTTP/1.0\r\n" +
b"\r\n"
)
# Send back an example response
_, message = self.channel_layer.receive_many(["http.request"])
self.factory.dispatch_reply(
message['reply_channel'],
{
"status": 484,
"status_text": b"Daphne Is Awesome",
}
)
# Make sure that comes back right on the protocol
self.assertStartsWith(self.tr.value(), b"HTTP/1.0 484 Daphne Is Awesome\r\n")