本文整理汇总了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()