当前位置: 首页>>代码示例>>Python>>正文


Python django.DjangoModelFactory方法代码示例

本文整理汇总了Python中factory.django.DjangoModelFactory方法的典型用法代码示例。如果您正苦于以下问题:Python django.DjangoModelFactory方法的具体用法?Python django.DjangoModelFactory怎么用?Python django.DjangoModelFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在factory.django的用法示例。


在下文中一共展示了django.DjangoModelFactory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _test_uniqueness_ignores_deleted

# 需要导入模块: from factory import django [as 别名]
# 或者: from factory.django import DjangoModelFactory [as 别名]
def _test_uniqueness_ignores_deleted(
        self, factory: Type[DjangoModelFactory], **kwargs
    ):
        """Ensure uniqueness doesn't take deleted instances into account.

        Parameters
        ----------
        factory: Type[DjangoModelFactory]
            The factory to use to create/delete some objects
        kwargs:
            Arguments to pass to the given `factory`.

        """
        obj1 = factory(**kwargs)

        # force a soft deletion (useful for through models configured with ``HARD_DELETE``)
        obj1.delete(force_policy=SOFT_DELETE_CASCADE)
        self.assertIsSoftDeleted(obj1)

        # we can create it again
        factory(**kwargs)

        # when exists non-deleted, cannot create another one
        with self.assertRaises(IntegrityError):
            factory(**kwargs) 
开发者ID:openfun,项目名称:marsha,代码行数:27,代码来源:test_models_deletion.py

示例2: _test_soft_deletion

# 需要导入模块: from factory import django [as 别名]
# 或者: from factory.django import DjangoModelFactory [as 别名]
def _test_soft_deletion(self, factory: Type[DjangoModelFactory], **kwargs):
        """Ensure that soft deletion works for the model represented by the factory.

        Parameters
        ----------
        factory: Type[DjangoModelFactory]
            The factory to use to create an object to soft-delete.
        kwargs:
            Arguments to pass to the given `factory`.

        """
        model = factory._meta.model  # noqa

        obj = factory(**kwargs)
        self.assertIsNone(obj.deleted)

        obj.delete()
        self.assertIsNotNone(obj.deleted)

        # object should be invisible to normal queryset
        with self.assertRaises(model.DoesNotExist):
            model.objects.get(pk=obj.pk)

        # but still present in deleted mode
        self.assertEqual(model.objects.deleted_only().get(pk=obj.pk), obj)

        # we could still force delete it
        obj.delete(force_policy=HARD_DELETE)

        self.assertIsHardDeleted(obj) 
开发者ID:openfun,项目名称:marsha,代码行数:32,代码来源:test_models_deletion.py

示例3: _test_hard_deletion

# 需要导入模块: from factory import django [as 别名]
# 或者: from factory.django import DjangoModelFactory [as 别名]
def _test_hard_deletion(self, factory: Type[DjangoModelFactory], **kwargs):
        """Ensure directly deleting an instance of the given kind implies hard deletion.

        Parameters
        ----------
        factory: Type[DjangoModelFactory]
            The factory to use to create an object to delete.
        kwargs:
            Arguments to pass to the given `factory`.

        """
        obj = factory(**kwargs)
        obj.delete()

        self.assertIsHardDeleted(obj) 
开发者ID:openfun,项目名称:marsha,代码行数:17,代码来源:test_models_deletion.py


注:本文中的factory.django.DjangoModelFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。