本文整理匯總了Python中factory.DjangoModelFactory方法的典型用法代碼示例。如果您正苦於以下問題:Python factory.DjangoModelFactory方法的具體用法?Python factory.DjangoModelFactory怎麽用?Python factory.DjangoModelFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類factory
的用法示例。
在下文中一共展示了factory.DjangoModelFactory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_model_change
# 需要導入模塊: import factory [as 別名]
# 或者: from factory import DjangoModelFactory [as 別名]
def test_model_change(self, mock_set_api_timestamp):
"""
Verify that the API cache is invalidated after course_metadata models
are saved or deleted.
"""
factory_map = {}
for key, factorylike in factories.__dict__.items():
if 'NoSignals' in key:
continue
if isinstance(factorylike, type) and issubclass(factorylike, DjangoModelFactory):
if getattr(factorylike, '_meta', None) and factorylike._meta.model:
factory_map[factorylike._meta.model] = factorylike
# These are the models whose post_save and post_delete signals we're
# connecting to. We want to test each of them.
for model in apps.get_app_config('course_metadata').get_models():
# Ignore models that aren't exposed by the API or are only used for testing.
if model in [BackpopulateCourseTypeConfig, DataLoaderConfig, DeletePersonDupsConfig,
DrupalPublishUuidConfig, MigratePublisherToCourseMetadataConfig, SubjectTranslation,
TopicTranslation, ProfileImageDownloadConfig, TagCourseUuidsConfig, RemoveRedirectsConfig,
BulkModifyProgramHookConfig, BackfillCourseRunSlugsConfig, AlgoliaProxyCourse,
AlgoliaProxyProgram, AlgoliaProxyProduct, ProgramTypeTranslation, LevelTypeTranslation]:
continue
if 'abstract' in model.__name__.lower() or 'historical' in model.__name__.lower():
continue
factory = factory_map.get(model)
if not factory:
pytest.fail('The {} model is missing a factory.'.format(model))
# Verify that model creation and deletion invalidates the API cache.
instance = factory()
assert mock_set_api_timestamp.called
mock_set_api_timestamp.reset_mock()
instance.delete()
assert mock_set_api_timestamp.called
mock_set_api_timestamp.reset_mock()