Accept responses with just a status code (Fixes #263)

This commit is contained in:
Miguel Grinberg
2024-11-10 00:34:21 +00:00
parent 496a288064
commit 4eac013087
2 changed files with 24 additions and 7 deletions

View File

@@ -109,6 +109,18 @@ class TestResponse(unittest.TestCase):
fd.response)
self.assertTrue(fd.response.endswith(b'\r\n\r\n[1, "2"]'))
def test_create_status_code(self):
res = Response(202)
self.assertEqual(res.status_code, 202)
self.assertEqual(res.body, b'')
fd = FakeStreamAsync()
self._run(res.write(fd))
self.assertIn(b'HTTP/1.0 202 N/A\r\n', fd.response)
self.assertIn(b'Content-Length: 0\r\n', fd.response)
self.assertIn(b'Content-Type: text/plain; charset=UTF-8\r\n',
fd.response)
self.assertTrue(fd.response.endswith(b'\r\n\r\n'))
def test_create_from_none(self):
res = Response(None)
self.assertEqual(res.status_code, 204)
@@ -136,10 +148,10 @@ class TestResponse(unittest.TestCase):
self.assertTrue(fd.response.endswith(b'\r\n\r\nfoobar'))
def test_create_from_other(self):
res = Response(123)
res = Response(23.7)
self.assertEqual(res.status_code, 200)
self.assertEqual(res.headers, {})
self.assertEqual(res.body, 123)
self.assertEqual(res.body, 23.7)
def test_create_with_status_code(self):
res = Response('not found', 404)