def test_update(self): # Tests that Metadata.update correctly prefers new fields to old, unless # new fields aren't defined. edition_old, pool = self._edition(with_license_pool=True) edition_old.publisher = "test_old_publisher" edition_old.subtitle = "old_subtitile" metadata_old = Metadata.from_edition(edition_old) edition_new, pool = self._edition(with_license_pool=True) # set more fields on metadatas edition_new.publisher = None edition_new.subtitle = "new_updated_subtitile" metadata_new = Metadata.from_edition(edition_new) metadata_old.update(metadata_new) eq_(metadata_old.publisher, "test_old_publisher") eq_(metadata_old.subtitle, metadata_new.subtitle)
def test_from_edition(self): # Makes sure Metadata.from_edition copies all the fields over. edition, pool = self._edition(with_license_pool=True) edition.series = "Harry Otter and the Mollusk of Infamy" edition.series_position = "14" metadata = Metadata.from_edition(edition) # make sure the metadata and the originating edition match for field in Metadata.BASIC_EDITION_FIELDS: eq_(getattr(edition, field), getattr(metadata, field)) e_contribution = edition.contributions[0] m_contributor_data = metadata.contributors[0] eq_(e_contribution.contributor.sort_name, m_contributor_data.sort_name) eq_(e_contribution.role, m_contributor_data.roles[0]) eq_(edition.data_source, metadata.data_source(self._db)) eq_(edition.primary_identifier.identifier, metadata.primary_identifier.identifier)