Exemple #1
0
 def test_post_accessed_in_put_method(self):
     django_request = self.factory.put('/', {'foo': 'bar'})
     request = Request(django_request,
                       parsers=[FormParser(),
                                MultiPartParser()])
     django_request.POST
     assert request.POST == {'foo': ['bar']}
     assert request.data == {'foo': ['bar']}
 def test_request_POST_with_form_content(self):
     """
     Ensure request.POST returns content for POST request with form content.
     """
     data = {'qwerty': 'uiop'}
     request = Request(factory.post('/', data))
     request.parsers = (FormParser(), MultiPartParser())
     assert list(request.POST.items()) == list(data.items())
 def test_standard_behaviour_determines_form_content_PUT(self):
     """
     Ensure request.data returns content for PUT request with form content.
     """
     data = {'qwerty': 'uiop'}
     request = Request(factory.put('/', data))
     request.parsers = (FormParser(), MultiPartParser())
     assert list(request.data.items()) == list(data.items())
 def test_request_POST_with_files(self):
     """
     Ensure request.POST returns no content for POST request with file content.
     """
     upload = SimpleUploadedFile("file.txt", b"file_content")
     request = Request(factory.post('/', {'upload': upload}))
     request.parsers = (FormParser(), MultiPartParser())
     assert list(request.POST) == []
     assert list(request.FILES) == ['upload']
Exemple #5
0
 def test_request_read_before_parsing(self):
     django_request = self.factory.put('/', {'foo': 'bar'})
     request = Request(django_request,
                       parsers=[FormParser(),
                                MultiPartParser()])
     django_request.read()
     with pytest.raises(RawPostDataException):
         request.POST
     with pytest.raises(RawPostDataException):
         request.POST
         request.data