コード例 #1
0
    def test_parse(self):
        """ Make sure the `QueryDict` works OK """
        parser = FormParser()

        stream = StringIO(self.string)
        data = parser.parse(stream)

        assert Form(data).is_valid() is True
コード例 #2
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']}
コード例 #3
0
 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())
コード例 #4
0
 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())
コード例 #5
0
 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']
コード例 #6
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