def test_remove_publisher_duplicates(self): publisher = synchroniser_factory.PublisherFactory.create(org_id='NL-1') publisher_duplicate = synchroniser_factory.PublisherFactory.create( org_id='NL-1') synchroniser_factory.DatasetFactory.create( ref='first_set', source_url='http://www.nourl.com/test1.xml', publisher=publisher) synchroniser_factory.DatasetFactory.create( ref='second_set', source_url='http://www.nourl.com/test2.xml', publisher=publisher_duplicate) syncer = DatasetSyncer() syncer.remove_publisher_duplicates('NL-1') # publisher duplicate should be removed, all datasets should be under the first publisher self.assertEqual(publisher, Publisher.objects.filter(org_id='NL-1')[0], "first publisher should still be in the database") self.assertEqual( 1, Publisher.objects.count(), "publisher duplicate should be removed from the database") self.assertEqual(2, publisher.iatixmlsource_set.all().count(), "Both XML sources should still be in the database") self.assertEqual(2, IatiXmlSource.objects.count(), "Both XML sources should still be in the database")