本文整理汇总了Python中rest_framework.parsers.FileUploadParser类的典型用法代码示例。如果您正苦于以下问题:Python FileUploadParser类的具体用法?Python FileUploadParser怎么用?Python FileUploadParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileUploadParser类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse
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)
示例2: test_parse
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
示例3: test_parse_missing_filename
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)
示例4: test_parse_missing_filename
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.'
示例5: test_get_encoded_filename
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'
示例6: test_parse_missing_filename_large_file
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."
)
示例7: test_parse_missing_filename_multiple_upload_handlers
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)
示例8: test_parse_missing_filename_multiple_upload_handlers
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.'
示例9: test_get_encoded_filename
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")
示例10: test_get_encoded_filename
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))
示例11: test_get_filename
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'))
示例12: test_get_filename
def test_get_filename(self):
parser = FileUploadParser()
filename = parser.get_filename(self.stream, None, self.parser_context)
self.assertEqual(filename, "file.txt")
示例13: test_get_filename
def test_get_filename(self):
parser = FileUploadParser()
filename = parser.get_filename(self.stream, None, self.parser_context)
assert filename == 'file.txt'