def django_file(cls, extension=None):
"""Generates a random file.
Example:
>>> from factory import DjangoModelFactory
>>>
>>> class ProductFactory(DjangoModelFactory):
>>> "Product factory."
>>>
>>> # ...
>>>
>>> image_file = Faker('django_file', extension='image')
>>> video_file = Faker('django_file', extension='video')
>>> text_file = Faker('django_file', extension='text')
>>>
>>> # ...
:param extension: File extension.
:type extension: str
:return: File object.
"""
fake = FakerFaker()
django_file = get_temporary_file(fake.file_name(extension=extension))
return File(django_file)
factory_faker.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录