def test_paratext_from_gsx_entry( self, entry_original: Dict[str, Dict[str, str]], resource: Resource, ): assert Resource.paratext_from_gsx_entry(None, None) is None assert Resource.paratext_from_gsx_entry(entry_original, None) is None assert Resource.paratext_from_gsx_entry(None, resource) is None paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert paratext is not None assert paratext.title == resource.title assert paratext.summary is not None assert paratext.notes is not None assert paratext.relationships.count() == 1
def test__get_resource(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) assert doc._get_resource(resource) == resource paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert doc._get_resource(paratext) == resource
def test_get_date(self, entry_original: Dict[str, Dict[str, str]]): resource = Resource.from_gsx_entry(entry_original) assert resource.date is not None assert resource.get_date() is not None paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert paratext.date is None assert paratext.get_date() is not None assert paratext.get_date() == resource.get_date()
def test_prepare_subjects(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len(doc.prepare_subjects(resource)) == 2 paratext.subjects.add(search_term_or_none("fast-topic", "Operas")) assert len(doc.prepare_subjects(resource)) == 4
def test_paratext_of(self, entry_original: Dict[str, Dict[str, str]]): resource = Resource.from_gsx_entry(entry_original) assert resource.is_paratext() is False assert resource.paratext_of() is None paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert paratext.is_paratext() is True paratext_of = paratext.paratext_of() assert paratext_of is not None assert paratext_of.id == resource.id
def test_prepare_classifications_paratext(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len(doc.prepare_classifications_paratext(resource)) == 0 paratext.classifications.add( Classification(edition=search_term_or_none("rt-pt", "Preface")), bulk=False, ) assert len(doc.prepare_classifications_paratext(resource)) == 3
def test_prepare_form_genre(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len(doc.prepare_form_genre(resource)) == 0 resource.subjects.add(search_term_or_none("fast-forms", "History")) assert len(doc.prepare_form_genre(resource)) == 2 paratext.subjects.add(search_term_or_none("fast-forms", "Periodicals")) assert len(doc.prepare_form_genre(resource)) == 4
def test_prepare_title(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len(doc.prepare_title(resource)) == 1 paratext.title.main_title = "a different title" paratext.title.save() paratext.save() assert len(doc.prepare_title(resource)) == 2
def test_prepare_languages(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len(doc.prepare_languages(resource)) == 2 paratext.languages.add( ResourceLanguage( language=search_term_or_none("iso639-2", "english")), bulk=False, ) assert len(doc.prepare_languages(resource)) == 4
def test_prepare_classifications_translation(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len(doc.prepare_classifications_translation(resource)) == 0 resource.classifications.add( Classification(edition=search_term_or_none("rt-tt", "Integral")), bulk=False, ) assert len(doc.prepare_classifications_translation(resource)) == 2 paratext.classifications.add( Classification(edition=search_term_or_none("rt-tt", "Partial")), bulk=False, ) assert len(doc.prepare_classifications_translation(resource)) == 4
def test_prepare_contributions(self, entry_original, person): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len(doc.prepare_contributions(resource)) == 3 person.name = "Anonymous Badger" person.save() contribution = Contribution(resource=resource, agent=person) contribution.save() contribution.roles.add(search_term_or_none("wikidata", "bookseller")) paratext.contributions.add(contribution, bulk=False) assert len(doc.prepare_contributions(resource)) == 4 contribution = doc.prepare_contributions(resource)[2] assert contribution["agent"]["name"] == "Anonymous"
def test_prepare_classifications_printing_publishing(self, entry_original): doc = ResourceDocument() resource = Resource.from_gsx_entry(entry_original) paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert len( doc.prepare_classifications_printing_publishing(resource)) == 0 resource.classifications.add( Classification(edition=search_term_or_none("rt-ppt", "Forgeries")), bulk=False, ) assert len( doc.prepare_classifications_printing_publishing(resource)) == 2 paratext.classifications.add( Classification(edition=search_term_or_none("rt-ppt", "Piracies")), bulk=False, ) assert len( doc.prepare_classifications_printing_publishing(resource)) == 4
def test_get_paratext(self, entry_original: Dict[str, Dict[str, str]]): resource = Resource.from_gsx_entry(entry_original) assert resource.get_paratext().count() == 1 paratext = Resource.paratext_from_gsx_entry(entry_original, resource) assert paratext.get_paratext().count() == 0