class SiteUrlGeneratorTest(TestCase): @parameterized.expand([ ('/index.html', '/index.html'), ('/person/P1/index.html', Person('P1')), ('/event/E1/index.html', IdentifiableEvent('E1', Event.Type.DEATH)), ('/place/P1/index.html', Place('P1', [LocalizedName('Place 1')])), ('/file/F1/index.html', File('F1', '/tmp')), ('/source/S1/index.html', Source('S1', 'Source 1')), ('/citation/C1/index.html', Citation('C1', Source('S1', 'Source 1'))), ]) def test_generate(self, expected: str, resource: Any): configuration = Configuration('/tmp', 'https://example.com') sut = SiteUrlGenerator(configuration) self.assertEquals(expected, sut.generate(resource, 'text/html')) def test_generate_with_invalid_value(self): configuration = Configuration('/tmp', 'https://example.com') sut = SiteUrlGenerator(configuration) with self.assertRaises(ValueError): sut.generate(9, 'text/html')
def test_person_with_individual_and_affiliation_names( self, expected: str, locale: str): with TemporaryDirectory() as output_directory_path: configuration = Configuration(output_directory_path, 'https://example.com') configuration.locales['en-US'] = LocaleConfiguration('en-US', 'en') configuration.locales['nl-NL'] = LocaleConfiguration('nl-NL', 'nl') site = Site(configuration) environment = create_environment(site, locale) person_id = 'P1' individual_name = 'Jane' affiliation_name = 'Doughnut' person = Person(person_id) person.names.append(PersonName(individual_name, affiliation_name)) site.ancestry.people[person_id] = person indexed = list(index(site, environment)) self.assertEquals('jane doughnut', indexed[0]['text']) self.assertIn(expected, indexed[0]['result'])
def test_clean(self) -> None: ancestry = Ancestry() onymous_event = IdentifiableEvent('E0', Birth()) Presence(Person('P0'), Subject(), onymous_event) ancestry.events[onymous_event.id] = onymous_event anonymous_event = IdentifiableEvent('E1', Birth()) ancestry.events[anonymous_event.id] = anonymous_event onymous_place = Place('P0', [PlaceName('Amsterdam')]) onymous_place.events.append(onymous_event) ancestry.places[onymous_place.id] = onymous_place anonymous_place = Place('P1', [PlaceName('Almelo')]) ancestry.places[anonymous_place.id] = anonymous_place onmyous_place_because_encloses_onmyous_places = Place( 'P3', [PlaceName('Netherlands')]) Enclosure(onymous_place, onmyous_place_because_encloses_onmyous_places) Enclosure(anonymous_place, onmyous_place_because_encloses_onmyous_places) ancestry.places[onmyous_place_because_encloses_onmyous_places. id] = onmyous_place_because_encloses_onmyous_places clean(ancestry) self.assertDictEqual({ onymous_event.id: onymous_event, }, ancestry.events) self.assertDictEqual( { onymous_place.id: onymous_place, onmyous_place_because_encloses_onmyous_places.id: onmyous_place_because_encloses_onmyous_places, }, ancestry.places) self.assertNotIn( anonymous_place, onmyous_place_because_encloses_onmyous_places.encloses)
async def test_derive_create_comes_after_derivable_event( self, expected_datey: Optional[Datey], after_datey: Optional[Datey]): expected_creations = 0 if expected_datey is None else 1 person = Person('P0') Presence(person, Subject(), Event(Ignored(), Date(0, 0, 0))) Presence(person, Subject(), Event(ComesAfterReference(), after_datey)) created, updated = derive(person, ComesAfterCreatableDerivable) derived_presences = [ presence for presence in person.presences if isinstance(presence.event.type, ComesAfterCreatableDerivable) ] self.assertEquals(expected_creations, len(derived_presences)) if expected_creations: derived_presence = derived_presences[0] self.assertIsInstance(derived_presence.role, Subject) self.assertEquals(expected_datey, derived_presence.event.date) self.assertEquals(expected_creations, created) self.assertEquals(0, updated) self.assertEquals(2 + expected_creations, len(person.presences))
def test_file_should_encode_full(self): with NamedTemporaryFile() as f: note = Note('the_note', 'The Note') file = File('the_file', f.name) file.media_type = MediaType('text/plain') file.notes.append(note) Person('the_person').files.append(file) expected = { '$schema': '/schema.json#/definitions/file', 'id': 'the_file', 'mediaType': 'text/plain', 'resources': [ '/en/person/the_person/index.json', ], 'notes': [ '/en/note/the_note/index.json', ], 'links': [ { 'url': '/en/file/the_file/index.json', 'relationship': 'canonical', 'mediaType': 'application/json', }, { 'url': '/nl/file/the_file/index.json', 'relationship': 'alternate', 'locale': 'nl-NL', }, { 'url': '/en/file/the_file/index.html', 'relationship': 'alternate', 'mediaType': 'text/html', }, ], } self.assert_encodes(expected, file, 'file')
def test_person_should_encode_minimal(self): person_id = 'the_person' person = Person(person_id) expected = { '$schema': '/schema.json#/definitions/person', '@context': { 'parents': 'https://schema.org/parent', 'children': 'https://schema.org/child', 'siblings': 'https://schema.org/sibling', }, '@type': 'https://schema.org/Person', 'id': person_id, 'names': [], 'parents': [], 'children': [], 'siblings': [], 'private': None, 'presences': [], 'citations': [], 'links': [], } self.assert_encodes(expected, person, 'person')
def test_privatize_event_should_privatize_if_private(self): source_file = File('F0', __file__) source = Source('The Source') source.files.append(source_file) citation_file = File('F1', __file__) citation = IdentifiableCitation('C0', source) citation.files.append(citation_file) event_file = File('F1', __file__) event = Event(Birth()) event.private = True event.citations.append(citation) event.files.append(event_file) person = Person('P0') Presence(person, Subject(), event) privatize_event(event) self.assertTrue(event.private) self.assertTrue(event_file.private) self.assertTrue(citation.private) self.assertTrue(source.private) self.assertTrue(citation_file.private) self.assertTrue(source_file.private) self.assertIsNone(person.private)
def test_person_should_encode_minimal(self): person_id = 'the_person' person = Person(person_id) expected = { '$schema': '/schema.json#/definitions/person', '@context': { 'parents': 'https://schema.org/parent', 'children': 'https://schema.org/child', 'siblings': 'https://schema.org/sibling', }, '@type': 'https://schema.org/Person', 'id': person_id, 'names': [], 'parents': [], 'children': [], 'siblings': [], 'private': None, 'presences': [], 'citations': [], 'links': [ { 'url': '/en/person/the_person/index.json', 'relationship': 'canonical', 'mediaType': 'application/json', }, { 'url': '/nl/person/the_person/index.json', 'relationship': 'alternate', 'locale': 'nl-NL', }, { 'url': '/en/person/the_person/index.html', 'relationship': 'alternate', 'mediaType': 'text/html', }, ], } self.assert_encodes(expected, person, 'person')
def _parse_person(ancestry: _IntermediateAncestry, element: Element): handle = _xpath1(element, './@handle') person = Person(str(_xpath1(element, './@id'))) individual_name_element = _xpath1( element, './ns:name[@type="Birth Name"]/ns:first') if individual_name_element is not None: person.individual_name = individual_name_element.text family_name_element = _xpath1(element, './ns:name[@type="Birth Name"]/ns:surname') if family_name_element is not None: person.family_name = family_name_element.text person.presences = _parse_eventrefs(ancestry, element) if str(_xpath1(element, './@priv')) == '1': person.private = True citation_handles = _xpath(element, './ns:citationref/@hlink') for citation_handle in citation_handles: person.citations.add(ancestry.citations[citation_handle]) _parse_objref(ancestry, person, element) _parse_urls(person, element) ancestry.people[handle] = person
def test_privatize_event_should_not_privatize_if_public(self): source_file = File('F0', __file__) source = Source('The Source') source.files.append(source_file) citation_file = File('F1', __file__) citation = IdentifiableCitation('C0', source) citation.files.append(citation_file) event_file = File('F1', __file__) event = IdentifiableEvent('E1', Birth()) event.private = False event.citations.append(citation) event.files.append(event_file) person = Person('P0') Presence(person, Subject(), event) ancestry = Ancestry() ancestry.events[event.id] = event privatize(ancestry) self.assertEqual(False, event.private) self.assertIsNone(event_file.private) self.assertIsNone(citation.private) self.assertIsNone(source.private) self.assertIsNone(citation_file.private) self.assertIsNone(source_file.private) self.assertIsNone(person.private)
def test_start(self) -> None: start = Event(Birth()) sut = Person('P1') Presence(sut, Subject(), start) self.assertEquals(start, sut.start)
def test_end(self) -> None: end = Event(Burial()) sut = Person('P1') Presence(sut, Subject(), end) self.assertEquals(end, sut.end)
def test_name_without_names(self) -> None: self.assertIsNone(Person('P1').name)
def test_alternative_names(self) -> None: sut = Person('P1') name = PersonName('Janet', 'Not a Girl') alternative_name = PersonName('Janet', 'Still not a Girl') sut.names = [name, alternative_name] self.assertEquals([alternative_name], sut.alternative_names)
def test_should_remove_presences(self) -> None: event = Event(Event.Type.BIRTH) person = Person('P1') Presence(person, Presence.Role.SUBJECT, event) anonymize_event(event) self.assertEquals(0, len(event.presences))
def test_name_with_names(self) -> None: sut = Person('P1') name = PersonName() sut.names = [name, PersonName()] self.assertEquals(name, sut.name)
def test_event_should_encode_full(self): event = IdentifiableEvent('the_event', Birth()) event.date = DateRange(Date(2000, 1, 1), Date(2019, 12, 31)) event.place = Place('the_place', [PlaceName('The Place')]) Presence(Person('the_person'), Subject(), event) event.citations.append( IdentifiableCitation('the_citation', Source('The Source'))) expected = { '$schema': '/schema.json#/definitions/event', '@context': { 'place': 'https://schema.org/location', }, '@type': 'https://schema.org/Event', 'id': 'the_event', 'type': 'birth', 'presences': [ { '@context': { 'person': 'https://schema.org/actor', }, 'role': 'subject', 'person': '/en/person/the_person/index.json', }, ], 'citations': [ '/en/citation/the_citation/index.json', ], 'date': { 'start': { 'year': 2000, 'month': 1, 'day': 1, }, 'end': { 'year': 2019, 'month': 12, 'day': 31, }, }, 'place': '/en/place/the_place/index.json', 'links': [ { 'url': '/en/event/the_event/index.json', 'relationship': 'canonical', 'mediaType': 'application/json', }, { 'url': '/nl/event/the_event/index.json', 'relationship': 'alternate', 'locale': 'nl-NL', }, { 'url': '/en/event/the_event/index.html', 'relationship': 'alternate', 'mediaType': 'text/html', }, ], } self.assert_encodes(expected, event, 'event')
async def load(self) -> None: amsterdam = Place('betty-demo-amsterdam', [PlaceName('Amsterdam')]) amsterdam.coordinates = Point(52.366667, 4.9) amsterdam.links.add(Link('https://nl.wikipedia.org/wiki/Amsterdam')) self._ancestry.places[amsterdam.id] = amsterdam ilpendam = Place('betty-demo-ilpendam', [PlaceName('Ilpendam')]) ilpendam.coordinates = Point(52.465556, 4.951111) ilpendam.links.add(Link('https://nl.wikipedia.org/wiki/Ilpendam')) self._ancestry.places[ilpendam.id] = ilpendam personal_accounts = IdentifiableSource('betty-demo-personal-accounts', 'Personal accounts') self._ancestry.sources[personal_accounts.id] = personal_accounts cite_first_person_account = IdentifiableCitation( 'betty-demo-first-person-account', personal_accounts) self._ancestry.citations[ cite_first_person_account.id] = cite_first_person_account bevolkingsregister_amsterdam = IdentifiableSource( 'betty-demo-bevolkingsregister-amsterdam', 'Bevolkingsregister Amsterdam') bevolkingsregister_amsterdam.author = 'Gemeente Amsterdam' bevolkingsregister_amsterdam.publisher = 'Gemeente Amsterdam' self._ancestry.sources[ bevolkingsregister_amsterdam.id] = bevolkingsregister_amsterdam david_marinus_lankester = Person('betty-demo-david-marinus-lankester') david_marinus_lankester.names.append( PersonName('David Marinus', 'Lankester')) self._ancestry.people[ david_marinus_lankester.id] = david_marinus_lankester geertruida_van_ling = Person('betty-demo-geertruida-van-ling') geertruida_van_ling.names.append(PersonName('Geertruida', 'Van Ling')) self._ancestry.people[geertruida_van_ling.id] = geertruida_van_ling marriage_of_dirk_jacobus_lankester_and_jannigje_palsen = IdentifiableEvent( 'betty-demo-marriage-of-dirk-jacobus-lankester-and-jannigje-palsen', Marriage(), Date(1922, 7, 4)) marriage_of_dirk_jacobus_lankester_and_jannigje_palsen.place = ilpendam self._ancestry.events[ marriage_of_dirk_jacobus_lankester_and_jannigje_palsen. id] = marriage_of_dirk_jacobus_lankester_and_jannigje_palsen birth_of_dirk_jacobus_lankester = IdentifiableEvent( 'betty-demo-birth-of-dirk-jacobus-lankester', Birth(), Date(1897, 8, 25)) birth_of_dirk_jacobus_lankester.place = amsterdam self._ancestry.events[birth_of_dirk_jacobus_lankester. id] = birth_of_dirk_jacobus_lankester death_of_dirk_jacobus_lankester = IdentifiableEvent( 'betty-demo-death-of-dirk-jacobus-lankester', Death(), Date(1986, 8, 18)) death_of_dirk_jacobus_lankester.place = amsterdam self._ancestry.events[death_of_dirk_jacobus_lankester. id] = death_of_dirk_jacobus_lankester dirk_jacobus_lankester = Person('betty-demo-dirk-jacobus-lankester') dirk_jacobus_lankester.names.append( PersonName('Dirk Jacobus', 'Lankester')) Presence(dirk_jacobus_lankester, Subject(), birth_of_dirk_jacobus_lankester) Presence(dirk_jacobus_lankester, Subject(), death_of_dirk_jacobus_lankester) Presence(dirk_jacobus_lankester, Subject(), marriage_of_dirk_jacobus_lankester_and_jannigje_palsen) dirk_jacobus_lankester.parents.append(david_marinus_lankester, geertruida_van_ling) self._ancestry.people[ dirk_jacobus_lankester.id] = dirk_jacobus_lankester birth_of_marinus_david_lankester = IdentifiableEvent( 'betty-demo-birth-of-marinus-david', Birth(), DateRange(Date(1874, 1, 15), Date(1874, 3, 21), start_is_boundary=True, end_is_boundary=True)) birth_of_marinus_david_lankester.place = amsterdam self._ancestry.events[birth_of_marinus_david_lankester. id] = birth_of_marinus_david_lankester death_of_marinus_david_lankester = IdentifiableEvent( 'betty-demo-death-of-marinus-david', Death(), Date(1971)) death_of_marinus_david_lankester.place = amsterdam self._ancestry.events[death_of_marinus_david_lankester. id] = death_of_marinus_david_lankester marinus_david_lankester = Person('betty-demo-marinus-david-lankester') marinus_david_lankester.names.append( PersonName('Marinus David', 'Lankester')) Presence(marinus_david_lankester, Subject(), birth_of_marinus_david_lankester) Presence(marinus_david_lankester, Subject(), death_of_marinus_david_lankester) marinus_david_lankester.parents.append(david_marinus_lankester, geertruida_van_ling) self._ancestry.people[ marinus_david_lankester.id] = marinus_david_lankester birth_of_jacoba_gesina_lankester = IdentifiableEvent( 'betty-demo-birth-of-jacoba-gesina', Birth(), Date(1900, 3, 14)) birth_of_jacoba_gesina_lankester.place = amsterdam self._ancestry.events[birth_of_jacoba_gesina_lankester. id] = birth_of_jacoba_gesina_lankester jacoba_gesina_lankester = Person('betty-demo-jacoba-gesina-lankester') jacoba_gesina_lankester.names.append( PersonName('Jacoba Gesina', 'Lankester')) Presence(jacoba_gesina_lankester, Subject(), birth_of_jacoba_gesina_lankester) jacoba_gesina_lankester.parents.append(david_marinus_lankester, geertruida_van_ling) self._ancestry.people[ jacoba_gesina_lankester.id] = jacoba_gesina_lankester jannigje_palsen = Person('betty-demo-jannigje-palsen') jannigje_palsen.names.append(PersonName('Jannigje', 'Palsen')) Presence(jannigje_palsen, Subject(), marriage_of_dirk_jacobus_lankester_and_jannigje_palsen) self._ancestry.people[jannigje_palsen.id] = jannigje_palsen marriage_of_johan_de_boer_and_liberta_lankester = IdentifiableEvent( 'betty-demo-marriage-of-johan-de-boer-and-liberta-lankester', Marriage(), Date(1953, 6, 19)) marriage_of_johan_de_boer_and_liberta_lankester.place = amsterdam self._ancestry.events[ marriage_of_johan_de_boer_and_liberta_lankester. id] = marriage_of_johan_de_boer_and_liberta_lankester cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam = IdentifiableCitation( 'betty-demo-birth-of-liberta-lankester-from-bevolkingsregister-amsterdam', bevolkingsregister_amsterdam) cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam.location = 'Amsterdam' self._ancestry.citations[ cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam. id] = cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam birth_of_liberta_lankester = IdentifiableEvent( 'betty-demo-birth-of-liberta-lankester', Birth(), Date(1929, 12, 22)) birth_of_liberta_lankester.place = amsterdam birth_of_liberta_lankester.citations.append( cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam) self._ancestry.events[ birth_of_liberta_lankester.id] = birth_of_liberta_lankester death_of_liberta_lankester = IdentifiableEvent( 'betty-demo-death-of-liberta-lankester', Death(), Date(2015, 1, 17)) death_of_liberta_lankester.place = amsterdam death_of_liberta_lankester.citations.append(cite_first_person_account) self._ancestry.events[ death_of_liberta_lankester.id] = death_of_liberta_lankester liberta_lankester = Person('betty-demo-liberta-lankester') liberta_lankester.names.append(PersonName('Liberta', 'Lankester')) liberta_lankester.names.append(PersonName('Betty')) Presence(liberta_lankester, Subject(), birth_of_liberta_lankester) Presence(liberta_lankester, Subject(), death_of_liberta_lankester) Presence(liberta_lankester, Subject(), marriage_of_johan_de_boer_and_liberta_lankester) liberta_lankester.parents.append(dirk_jacobus_lankester, jannigje_palsen) self._ancestry.people[liberta_lankester.id] = liberta_lankester birth_of_johan_de_boer = IdentifiableEvent( 'betty-demo-birth-of-johan-de-boer', Birth(), Date(1930, 6, 20)) birth_of_johan_de_boer.place = amsterdam self._ancestry.events[ birth_of_johan_de_boer.id] = birth_of_johan_de_boer death_of_johan_de_boer = IdentifiableEvent( 'betty-demo-death-of-johan-de-boer', Death(), Date(1999, 3, 10)) death_of_johan_de_boer.place = amsterdam death_of_johan_de_boer.citations.append(cite_first_person_account) self._ancestry.events[ death_of_johan_de_boer.id] = death_of_johan_de_boer johan_de_boer = Person('betty-demo-johan-de-boer') johan_de_boer.names.append(PersonName('Johan', 'De Boer')) johan_de_boer.names.append(PersonName('Hans')) Presence(johan_de_boer, Subject(), birth_of_johan_de_boer) Presence(johan_de_boer, Subject(), death_of_johan_de_boer) Presence(johan_de_boer, Subject(), marriage_of_johan_de_boer_and_liberta_lankester) self._ancestry.people[johan_de_boer.id] = johan_de_boer parent_of_bart_feenstra_child_of_liberta_lankester = Person( 'betty-demo-parent-of-bart-feenstra-child-of-liberta-lankester') parent_of_bart_feenstra_child_of_liberta_lankester.names.append( PersonName('Bart\'s parent')) parent_of_bart_feenstra_child_of_liberta_lankester.parents.append( johan_de_boer, liberta_lankester) self._ancestry.people[ parent_of_bart_feenstra_child_of_liberta_lankester. id] = parent_of_bart_feenstra_child_of_liberta_lankester bart_feenstra = Person('betty-demo-bart-feenstra') bart_feenstra.names.append(PersonName('Bart', 'Feenstra')) bart_feenstra.parents.append( parent_of_bart_feenstra_child_of_liberta_lankester) self._ancestry.people[bart_feenstra.id] = bart_feenstra
def test_person_should_encode_full(self): parent_id = 'the_parent' parent = Person(parent_id) child_id = 'the_child' child = Person(child_id) sibling_id = 'the_sibling' sibling = Person(sibling_id) sibling.parents.append(parent) person_id = 'the_person' person_affiliation_name = 'Person' person_individual_name = 'The' person = Person(person_id) person.names.append( PersonName(person_individual_name, person_affiliation_name)) person.parents.append(parent) person.children.append(child) person.private = False link = Link('https://example.com/the-person') link.label = 'The Person Online' person.links.add(link) person.citations.append( IdentifiableCitation('the_citation', Source('The Source'))) Presence(person, Subject(), IdentifiableEvent('the_event', Birth())) expected = { '$schema': '/schema.json#/definitions/person', '@context': { 'parents': 'https://schema.org/parent', 'children': 'https://schema.org/child', 'siblings': 'https://schema.org/sibling', }, '@type': 'https://schema.org/Person', 'id': person_id, 'names': [ { '@context': { 'individual': 'https://schema.org/givenName', 'affiliation': 'https://schema.org/familyName', }, 'individual': person_individual_name, 'affiliation': person_affiliation_name, }, ], 'parents': [ '/en/person/the_parent/index.json', ], 'children': [ '/en/person/the_child/index.json', ], 'siblings': [ '/en/person/the_sibling/index.json', ], 'private': False, 'presences': [ { '@context': { 'event': 'https://schema.org/performerIn', }, 'role': 'subject', 'event': '/en/event/the_event/index.json', }, ], 'citations': [ '/en/citation/the_citation/index.json', ], 'links': [ { 'url': '/en/person/the_person/index.json', 'relationship': 'canonical', 'mediaType': 'application/json', }, { 'url': '/nl/person/the_person/index.json', 'relationship': 'alternate', 'locale': 'nl-NL', }, { 'url': '/en/person/the_person/index.html', 'relationship': 'alternate', 'mediaType': 'text/html', }, { 'url': 'https://example.com/the-person', 'label': 'The Person Online', }, ], } self.assert_encodes(expected, person, 'person')
def test_should_remove_presences(self) -> None: event = Event(Birth()) person = Person('P1') Presence(person, Subject(), event) anonymize_event(event) self.assertEquals(0, len(event.presences))
def test_should_remove_files(self) -> None: person = Person('P0') person.files.append(File('F0', __file__)) anonymize_person(person) self.assertEquals(0, len(person.files))
def test_should_remove_names(self) -> None: person = Person('P0') person.names.append(PersonName('Jane', 'Doughh')) anonymize_person(person) self.assertEquals(0, len(person.names))
def test_should_remove_presences(self) -> None: person = Person('P0') Presence(person, Presence.Role.SUBJECT, Event(Event.Type.BIRTH)) anonymize_person(person) self.assertEquals(0, len(person.presences))
def test_siblings_without_parents(self) -> None: sut = Person('person') self.assertCountEqual([], sut.siblings)
async def test_person(self): person = Person('PERSON1') self.site.ancestry.people[person.id] = person await generate(self.site) self.assert_betty_html('/person/%s/index.html' % person.id) self.assert_betty_json('/person/%s/index.json' % person.id, 'person')
def test_siblings_with_multiple_common_parents(self) -> None: sut = Person('1') sibling = Person('2') parent = Person('3') parent.children = [sut, sibling] self.assertCountEqual([sibling], sut.siblings)
def test_id(self) -> None: person_id = 'P1' sut = Person(person_id) self.assertEquals(person_id, sut.id)
def test_person_should_encode_full(self): parent_id = 'the_parent' parent = Person(parent_id) child_id = 'the_child' child = Person(child_id) sibling_id = 'the_sibling' sibling = Person(sibling_id) sibling.parents.append(parent) person_id = 'the_person' person_affiliation_name = 'Person' person_individual_name = 'The' person = Person(person_id) person.names.append( PersonName(person_individual_name, person_affiliation_name)) person.parents.append(parent) person.children.append(child) person.private = False person.links.add( Link('https://example.com/the-person', 'The Person Online')) person.citations.append( Citation('the_citation', Source('the_source', 'The Source'))) Presence(person, Presence.Role.SUBJECT, IdentifiableEvent('the_event', Event.Type.BIRTH)) expected = { '$schema': '/schema.json#/definitions/person', '@context': { 'parents': 'https://schema.org/parent', 'children': 'https://schema.org/child', 'siblings': 'https://schema.org/sibling', }, '@type': 'https://schema.org/Person', 'id': person_id, 'names': [ { '@context': { 'individual': 'https://schema.org/givenName', 'affiliation': 'https://schema.org/familyName', }, 'individual': person_individual_name, 'affiliation': person_affiliation_name, }, ], 'parents': [ '/person/the_parent/index.json', ], 'children': [ '/person/the_child/index.json', ], 'siblings': [ '/person/the_sibling/index.json', ], 'private': False, 'presences': [ { '@context': { 'event': 'https://schema.org/performerIn', }, 'role': Presence.Role.SUBJECT.value, 'event': '/event/the_event/index.json', }, ], 'citations': [ '/citation/the_citation/index.json', ], 'links': [ { 'url': 'https://example.com/the-person', 'label': 'The Person Online', }, ], } self.assert_encodes(expected, person, 'person')
def test_should_remove_resources(self) -> None: file = File('F0', __file__) file.resources.append(Person('P0')) anonymize_file(file) self.assertEquals(0, len(file.resources))