def test_parse(self): """ Make sure the `QueryDict` works OK """ parser = FileUploadParser() self.stream.seek(0) data_and_files = parser.parse(self.stream, None, self.parser_context) file_obj = data_and_files.files['file'] self.assertEqual(file_obj._size, 14)
def test_parse(self): """ Parse raw file upload. """ parser = FileUploadParser() self.stream.seek(0) data_and_files = parser.parse(self.stream, None, self.parser_context) file_obj = data_and_files.files['file'] assert file_obj._size == 14
def test_parse(self): """ Parse raw file upload. """ parser = FileUploadParser() self.stream.seek(0) data_and_files = parser.parse(self.stream, None, self.parser_context) file_obj = data_and_files.files['file'] assert file_obj.size == 14
def test_parse_missing_filename(self): """ Parse raw file upload when filename is missing. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = '' with self.assertRaises(ParseError): parser.parse(self.stream, None, self.parser_context)
def test_parse_missing_filename(self): """ Parse raw file upload when filename is missing. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = '' with pytest.raises(ParseError) as excinfo: parser.parse(self.stream, None, self.parser_context) assert str(excinfo.value) == 'Missing filename. Request should include a Content-Disposition header with a filename parameter.'
def test_parse_missing_filename(self): """ Parse raw file upload when filename is missing. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = '' with pytest.raises(ParseError) as excinfo: parser.parse(self.stream, None, self.parser_context) assert str( excinfo.value ) == 'Missing filename. Request should include a Content-Disposition header with a filename parameter.'
def test_parse_missing_filename_multiple_upload_handlers(self): """ Parse raw file upload with multiple handlers when filename is missing. Regression test for #2109. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context['request'].upload_handlers = ( MemoryFileUploadHandler(), MemoryFileUploadHandler()) self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = '' with self.assertRaises(ParseError): parser.parse(self.stream, None, self.parser_context)
def test_parse_missing_filename_large_file(self): """ Parse raw file upload when filename is missing with TemporaryFileUploadHandler. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context["request"].upload_handlers = (TemporaryFileUploadHandler(),) self.parser_context["request"].META["HTTP_CONTENT_DISPOSITION"] = "" with pytest.raises(ParseError) as excinfo: parser.parse(self.stream, None, self.parser_context) assert ( str(excinfo.value) == "Missing filename. Request should include a Content-Disposition header with a filename parameter." )
def test_parse_missing_filename_multiple_upload_handlers(self): """ Parse raw file upload with multiple handlers when filename is missing. Regression test for #2109. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context['request'].upload_handlers = ( MemoryFileUploadHandler(), MemoryFileUploadHandler() ) self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = '' with self.assertRaises(ParseError): parser.parse(self.stream, None, self.parser_context)
def test_get_encoded_filename(self): parser = FileUploadParser() self.__replace_content_disposition('inline; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) assert filename == 'ÀĥƦ.txt' self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) assert filename == 'ÀĥƦ.txt' self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'en-us\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) assert filename == 'ÀĥƦ.txt'
def test_parse_missing_filename_multiple_upload_handlers(self): """ Parse raw file upload with multiple handlers when filename is missing. Regression test for #2109. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context['request'].upload_handlers = ( MemoryFileUploadHandler(), MemoryFileUploadHandler() ) self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = '' with pytest.raises(ParseError) as excinfo: parser.parse(self.stream, None, self.parser_context) assert str(excinfo.value) == 'Missing filename. Request should include a Content-Disposition header with a filename parameter.'
def test_parse_missing_filename_multiple_upload_handlers(self): """ Parse raw file upload with multiple handlers when filename is missing. Regression test for #2109. """ parser = FileUploadParser() self.stream.seek(0) self.parser_context['request'].upload_handlers = ( MemoryFileUploadHandler(), MemoryFileUploadHandler()) self.parser_context['request'].META['HTTP_CONTENT_DISPOSITION'] = '' with pytest.raises(ParseError) as excinfo: parser.parse(self.stream, None, self.parser_context) assert str( excinfo.value ) == 'Missing filename. Request should include a Content-Disposition header with a filename parameter.'
def test_get_encoded_filename(self): parser = FileUploadParser() self.__replace_content_disposition( 'inline; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) assert filename == 'ÀĥƦ.txt' self.__replace_content_disposition( 'inline; filename=fallback.txt; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) assert filename == 'ÀĥƦ.txt' self.__replace_content_disposition( 'inline; filename=fallback.txt; filename*=utf-8\'en-us\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) assert filename == 'ÀĥƦ.txt'
def test_get_encoded_filename(self): parser = FileUploadParser() self.__replace_content_disposition("inline; filename*=utf-8''ÀĥƦ.txt") filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, "ÀĥƦ.txt") self.__replace_content_disposition("inline; filename=fallback.txt; filename*=utf-8''ÀĥƦ.txt") filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, "ÀĥƦ.txt") self.__replace_content_disposition("inline; filename=fallback.txt; filename*=utf-8'en-us'ÀĥƦ.txt") filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, "ÀĥƦ.txt") self.__replace_content_disposition("inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt") filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, "fallback.txt")
def test_get_encoded_filename(self): parser = FileUploadParser() self.__replace_content_disposition('inline; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'ÀĥƦ.txt') self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'ÀĥƦ.txt') self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8\'en-us\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'ÀĥƦ.txt') self.__replace_content_disposition('inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) # Malformed. Either None or 'fallback.txt' will be acceptable. # See also https://code.djangoproject.com/ticket/24209 self.assertIn(filename, ('fallback.txt', None))
def test_get_encoded_filename(self): parser = FileUploadParser() self.__replace_content_disposition( 'inline; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'ÀĥƦ.txt') self.__replace_content_disposition( 'inline; filename=fallback.txt; filename*=utf-8\'\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'ÀĥƦ.txt') self.__replace_content_disposition( 'inline; filename=fallback.txt; filename*=utf-8\'en-us\'ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'ÀĥƦ.txt') self.__replace_content_disposition( 'inline; filename=fallback.txt; filename*=utf-8--ÀĥƦ.txt') filename = parser.get_filename(self.stream, None, self.parser_context) # Malformed. Either None or 'fallback.txt' will be acceptable. # See also https://code.djangoproject.com/ticket/24209 self.assertIn(filename, ('fallback.txt', None))
def test_get_filename(self): parser = FileUploadParser() filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'file.txt'.encode('utf-8'))
def test_get_filename(self): parser = FileUploadParser() filename = parser.get_filename(self.stream, None, self.parser_context) assert filename == 'file.txt'
def test_get_filename(self): parser = FileUploadParser() filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, "file.txt")
def test_get_filename(self): parser = FileUploadParser() filename = parser.get_filename(self.stream, None, self.parser_context) self.assertEqual(filename, 'file.txt')
def get_parsers(self): if self.request.method == 'PUT': return FileUploadParser(), else: return JSONParser(),