本文整理匯總了Python中rest_framework.parsers.FileUploadParser.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python FileUploadParser.parse方法的具體用法?Python FileUploadParser.parse怎麽用?Python FileUploadParser.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rest_framework.parsers.FileUploadParser
的用法示例。
在下文中一共展示了FileUploadParser.parse方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_parse_missing_filename
# 需要導入模塊: from rest_framework.parsers import FileUploadParser [as 別名]
# 或者: from rest_framework.parsers.FileUploadParser import parse [as 別名]
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)
示例2: test_parse_missing_filename
# 需要導入模塊: from rest_framework.parsers import FileUploadParser [as 別名]
# 或者: from rest_framework.parsers.FileUploadParser import parse [as 別名]
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.'
示例3: test_parse_missing_filename_large_file
# 需要導入模塊: from rest_framework.parsers import FileUploadParser [as 別名]
# 或者: from rest_framework.parsers.FileUploadParser import parse [as 別名]
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."
)
示例4: test_parse_missing_filename_multiple_upload_handlers
# 需要導入模塊: from rest_framework.parsers import FileUploadParser [as 別名]
# 或者: from rest_framework.parsers.FileUploadParser import parse [as 別名]
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)
示例5: test_parse_missing_filename_multiple_upload_handlers
# 需要導入模塊: from rest_framework.parsers import FileUploadParser [as 別名]
# 或者: from rest_framework.parsers.FileUploadParser import parse [as 別名]
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.'
示例6: test_parse
# 需要導入模塊: from rest_framework.parsers import FileUploadParser [as 別名]
# 或者: from rest_framework.parsers.FileUploadParser import parse [as 別名]
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)
示例7: test_parse
# 需要導入模塊: from rest_framework.parsers import FileUploadParser [as 別名]
# 或者: from rest_framework.parsers.FileUploadParser import parse [as 別名]
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