def test_create_or_update_publisher(self): publisher = create_or_update_publisher("123456", "dcormier") self.assertEquals(publisher.name, "dcormier") self.assertEquals(publisher.edinum_id, "123456") publisher_2 = create_or_update_publisher("123456", "dcormier2") self.assertEquals(publisher_2.pk, publisher.pk) self.assertEquals(publisher_2.name, "dcormier2") # create another publisher with the same edinum_id Publisher.objects.create(name="bob", edinum_id="123456") publisher = create_or_update_publisher("123456", "dcormier2") self.assertIsNone(publisher)
def test_can_create_journal_and_publisher(self): publisher = create_or_update_publisher("123456", "dcormier") journal = create_or_update_journal( publisher, "123", "Journal of journals", "joj", "", "", None ) self.assertEquals( journal.edinum_id, "123" )
def handle(self, *args, **options): self.created_or_updated_publishers = [] self.created_or_updated_journals = [] for publisher_row in fetch_publishers_from_edinum(): (person_id, publisher_name, series_id, journal_id, journal_name, journal_shortname, journal_localidentifier, coll_id, journal_subtitle) = publisher_row if person_id not in self.created_or_updated_publishers: publisher = create_or_update_publisher( person_id, publisher_name ) self.created_or_updated_publishers.append(person_id) try: journal_collection = Collection.objects.get(edinum_id=coll_id) except: journal_collection = None create_or_update_journal( publisher, journal_id, journal_name, journal_shortname, journal_localidentifier, journal_subtitle, journal_collection ) self.created_or_updated_journals.append(journal_shortname) publisher_journals = fetch_publisher_journals_from_edinum() for journal_sn in self.created_or_updated_journals: journal = Journal.objects.get(code=journal_sn) # journal.publishers.all().delete() for publisher_id, journal_id in publisher_journals: if journal_id == journal.edinum_id: publisher = Publisher.objects.get(edinum_id=publisher_id) journal.publishers.add(publisher)