本文整理汇总了Python中django.core.files.uploadedfile.UploadedFile.size方法的典型用法代码示例。如果您正苦于以下问题:Python UploadedFile.size方法的具体用法?Python UploadedFile.size怎么用?Python UploadedFile.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.uploadedfile.UploadedFile
的用法示例。
在下文中一共展示了UploadedFile.size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFileUpload
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import size [as 别名]
def testFileUpload(self):
from django.http import QueryDict, HttpRequest
from tardis.tardis_portal.views import upload
from django.core.files import File
from django.core.files.uploadedfile import UploadedFile
from django.utils.datastructures import MultiValueDict
from os import path
# create request.FILES object
django_file = File(self.f1)
uploaded_file = UploadedFile(file=django_file)
uploaded_file.name = self.filename
uploaded_file.size = self.f1_size
post_data = [("enctype", "multipart/form-data")]
post = QueryDict("&".join(["%s=%s" % (k, v) for (k, v) in post_data]))
files = MultiValueDict({"Filedata": [uploaded_file]})
request = HttpRequest()
request.FILES = files
request.POST = post
request.method = "POST"
response = upload(request, self.dataset.id)
test_files_db = models.Dataset_File.objects.filter(dataset__id=self.dataset.id)
self.assertTrue(path.exists(path.join(self.dataset_path, self.filename)))
self.assertTrue(self.dataset.id == 1)
self.assertTrue(test_files_db[0].url == "tardis://testfile.txt")