def test_stream(self): """ Tests the body stream is emulated correctly. """ request = AsgiRequest( { "http_version": "1.1", "method": "PUT", "path": "/", "headers": {"host": b"example.com", "content-length": b"11"}, }, BytesIO(b"onetwothree"), ) self.assertEqual(request.method, "PUT") self.assertEqual(request.read(3), b"one") self.assertEqual(request.read(), b"twothree")
def test_stream(self): """ Tests the body stream is emulated correctly. """ request = AsgiRequest( { "http_version": "1.1", "method": "PUT", "path": "/", "headers": {"host": b"example.com", "content-length": b"11"}, }, b"onetwothree", ) self.assertEqual(request.method, "PUT") self.assertEqual(request.read(3), b"one") self.assertEqual(request.read(), b"twothree")
def test_reading_body_after_stream_raises(self): request = AsgiRequest( { "http_version": "1.1", "method": "POST", "path": "/test2/", "query_string": "django=great", "headers": { "host": b"example.com", "content-type": b"application/x-www-form-urlencoded", "content-length": b"18", }, }, BytesIO(b"djangoponies=are+awesome"), ) self.assertEqual(request.read(3), b"dja") with pytest.raises(RawPostDataException): request.body