Python factory.DjangoModelFactory() Examples
The following are 1
code examples of factory.DjangoModelFactory().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
factory
, or try the search function
.
Example #1
Source File: test_signals.py From course-discovery with GNU Affero General Public License v3.0 | 5 votes |
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()