Esempio n. 1
0
 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")
Esempio n. 2
0
 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")
Esempio n. 3
0
 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