factory_faker.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:django-elasticsearch-dsl-drf 作者: barseghyanartur 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号