def test_o2m_merge_with_audit_trail(self): primary_object = NewsAgencyFactory.create() alias_object = NewsAgencyFactory.create() related_objects = set( ReporterFactory.create_batch(3, news_agency=alias_object)) _, audit_trail = MergedModelInstance.create_with_audit_trail( primary_object, [alias_object]) assert set(audit_trail) == related_objects
def test_merge_model_with_o2m_relationship(self): primary_object = NewsAgencyFactory.create() alias_object = NewsAgencyFactory.create() related_object = ReporterFactory.create(news_agency=alias_object) merged_object = MergedModelInstance.create(primary_object, [alias_object]) assert related_object.news_agency != merged_object related_object.refresh_from_db() assert related_object.news_agency == merged_object
def test_m2m_merge_with_audit_trail(self): primary_object = ArticleFactory.create(reporter=None) related_object = ReporterFactory.create() alias_object = ArticleFactory.create(number_of_publications=3, reporter=related_object) related_objects = set(alias_object.publications.all()) _, audit_trail = MergedModelInstance.create_with_audit_trail( primary_object, [alias_object]) assert set(audit_trail) == related_objects
def test_merge_model_with_m2m_relationship(self): primary_object = ArticleFactory.create(reporter=None) related_object = ReporterFactory.create() alias_object = ArticleFactory.create(number_of_publications=3, reporter=related_object) assert primary_object.reporter is None assert primary_object.publications.count() == 0 merged_object = MergedModelInstance.create(primary_object, [alias_object]) assert merged_object.reporter == related_object assert merged_object.publications.count() == 3
def test_merge_different_models(self): primary_object = ArticleFactory.create() alias_object = ReporterFactory.create() with pytest.raises(TypeError): MergedModelInstance.create(primary_object, [alias_object])