當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。