def test_children(self) -> None: sut = Person('1') child = Person('2') sut.children.append(child) self.assertCountEqual([child], sut.children) self.assertCountEqual([sut], child.parents) sut.children.remove(child) self.assertCountEqual([], sut.children) self.assertCountEqual([], child.parents)
def test_parents(self) -> None: sut = Person('1') parent = Person('2') sut.parents.append(parent) self.assertCountEqual([parent], sut.parents) self.assertCountEqual([sut], parent.children) sut.parents.remove(parent) self.assertCountEqual([], sut.parents) self.assertCountEqual([], parent.children)
async def test_with_subjects(self): event = Event(None, Birth()) Presence(Person('P0'), Subject(), event) Presence(Person('P1'), Subject(), event) expected = 'Birth of <a href="/person/P0/index.html"><span class="nn" title="This person\'s name is unknown.">n.n.</span></a>, <a href="/person/P1/index.html"><span class="nn" title="This person\'s name is unknown.">n.n.</span></a>' async with self._render(data={ 'event': event, }) as (actual, _): self.assertEqual(expected, actual)
def test_privatize_person_with_parent(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private parent = Person('P1') if event is not None: Presence(parent, Subject(), event) person.parents.append(parent) ancestry = Ancestry() ancestry.entities.append(person) privatize(ancestry) self.assertEquals(expected, person.private)
async def test_with_person_context_and_other_as_subject(self): event = Event(None, Marriage()) person = Person('P0') other_person = Person('P1') Presence(person, Subject(), event) Presence(other_person, Subject(), event) expected = 'Marriage with <a href="/person/P1/index.html"><span class="nn" title="This person\'s name is unknown.">n.n.</span></a>' async with self._render(data={ 'event': event, 'person_context': person, }) as (actual, _): self.assertEqual(expected, actual)
def test_should_not_remove_parents_with_public_descendants(self) -> None: person = Person('P0') person.private = True child = Person('P1') child.private = False person.children.append(child) parent = Person('P2') parent.private = True person.parents.append(parent) anonymize_person(person) self.assertCountEqual([parent], person.parents)
def test_privatize_person_with_grandchild(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private child = Person('P1') person.children.append(child) grandchild = Person('P2') if event is not None: Presence(grandchild, Subject(), event) child.children.append(grandchild) ancestry = Ancestry() ancestry.entities.append(person) privatize(ancestry) self.assertEquals(expected, person.private)
def test_privatize_person_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 = Citation('C0', source) citation.files.append(citation_file) event_as_subject = Event(None, Birth()) event_as_attendee = Event(None, Marriage()) person_file = File('F2', __file__) person = Person('P0') person.private = True person.citations.append(citation) person.files.append(person_file) Presence(person, Subject(), event_as_subject) Presence(person, Attendee(), event_as_attendee) ancestry = Ancestry() ancestry.entities.append(person) privatize(ancestry) self.assertTrue(person.private) self.assertTrue(citation.private) self.assertTrue(source.private) self.assertTrue(person_file.private) self.assertTrue(citation_file.private) self.assertTrue(source_file.private) self.assertTrue(event_as_subject.private) self.assertIsNone(event_as_attendee.private)
async def test_post_load(self): person = Person('P0') Presence(person, Subject(), Event(None, Birth())) source_file = File('F0', __file__) source = Source('S0', 'The Source') source.private = True source.files.append(source_file) citation_file = File('F0', __file__) citation_source = Source('The Source') citation = Citation('C0', citation_source) citation.private = True citation.files.append(citation_file) with TemporaryDirectory() as output_directory_path: configuration = Configuration(output_directory_path, 'https://example.com') configuration.extensions.add(ExtensionConfiguration(Privatizer)) async with App(configuration) as app: app.ancestry.entities.append(person) app.ancestry.entities.append(source) app.ancestry.entities.append(citation) await load(app) self.assertTrue(person.private) self.assertTrue(source_file.private) self.assertTrue(citation_file.private)
async def test_without_meta(self): person = Person('P0') expected = '<div class="meta person-meta"></div>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)
def test_clean_should_not_clean_event_with_presences_with_people( self) -> None: ancestry = Ancestry() source = Source('S1', 'The Source') ancestry.entities.append(source) citation = Citation('C1', source) ancestry.entities.append(citation) file = File('F1', __file__) ancestry.entities.append(file) place = Place('P0', [PlaceName('The Place')]) ancestry.entities.append(place) person = Person('P0') event = Event('E0', Birth()) event.citations.append(citation) event.files.append(file) event.place = place ancestry.entities.append(event) Presence(person, Subject(), event) clean(ancestry) self.assertEqual(event, ancestry.entities[Event][event.id]) self.assertIn(event, place.events) self.assertEqual(place, ancestry.entities[Place][place.id]) self.assertIn(event, citation.facts) self.assertEqual(citation, ancestry.entities[Citation][citation.id]) self.assertIn(event, file.entities) self.assertEqual(file, ancestry.entities[File][file.id])
def test_clean(self) -> None: ancestry = Ancestry() onymous_event = Event('E0', Birth()) Presence(Person('P0'), Subject(), onymous_event) ancestry.entities.append(onymous_event) anonymous_event = Event('E1', Birth()) ancestry.entities.append(anonymous_event) onymous_place = Place('P0', [PlaceName('Amsterdam')]) onymous_place.events.append(onymous_event) ancestry.entities.append(onymous_place) anonymous_place = Place('P1', [PlaceName('Almelo')]) ancestry.entities.append(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.entities.append(onmyous_place_because_encloses_onmyous_places) clean(ancestry) self.assertEquals([onymous_event], list(ancestry.entities[Event])) self.assertEquals( [onymous_place, onmyous_place_because_encloses_onmyous_places], list(ancestry.entities[Place])) self.assertNotIn( anonymous_place, onmyous_place_because_encloses_onmyous_places.encloses)
async def test_without_name(self): person = Person('P0') expected = '<a href="/person/P0/index.html"><span class="nn" title="This person\'s name is unknown.">n.n.</span></a>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)
def test_should_remove_presences(self) -> None: person = Person('P0') event = Event(None, Birth()) Presence(person, Subject(), event) anonymize_person(person) self.assertEquals(0, len(person.presences)) self.assertEquals(0, len(event.presences))
def test_should_remove_citations(self) -> None: person = Person('P0') source = Source('The Source') citation = Citation(None, source) person.citations.append(citation) anonymize_person(person) self.assertEquals(0, len(person.citations))
def test_with_private_person_should_anonymize(self, m_anonymize_person) -> None: person = Person('P0') person.private = True ancestry = Ancestry() ancestry.entities.append(person) anonymize(ancestry, AnonymousCitation(AnonymousSource())) m_anonymize_person.assert_called_once_with(person)
async def test_with_witnesses(self): event = Event(None, Birth()) Presence(Person('P0'), Witness(), event) expected = 'Birth' async with self._render(data={ 'event': event, }) as (actual, _): self.assertEqual(expected, actual)
class TestResourceTest(TemplateTestCase): @parameterized.expand([ ('true', Person, Person('P1')), ('false', Person, Place('P1', [PlaceName('The Place')])), ('true', Place, Place('P1', [PlaceName('The Place')])), ('false', Place, Person('P1')), ('false', Place, 999), ('false', Person, object()), ]) @sync async def test(self, expected, entity_type: Type[Entity], data) -> None: template = f'{{% if data is {camel_case_to_snake_case(get_entity_type_name(entity_type))}_entity %}}true{{% else %}}false{{% endif %}}' async with self._render(template_string=template, data={ 'data': data, }) as (actual, _): self.assertEquals(expected, actual)
async def test_with_full_name(self): person = Person(None) name = PersonName(person, 'Jane', 'Dough') expected = '<span class="person-label" typeof="foaf:Person"><span property="foaf:individualName">Jane</span> <span property="foaf:familyName">Dough</span></span>' async with self._render(data={ 'name': name, }) as (actual, _): self.assertEqual(expected, actual)
async def test_with_affiliation_name(self): person = Person(None) name = PersonName(person, None, 'Dough') expected = '<span class="person-label" typeof="foaf:Person">… <span property="foaf:familyName">Dough</span></span>' async with self._render(data={ 'name': name, }) as (actual, _): self.assertEqual(expected, actual)
async def test_private(self): person = Person('P0') person.private = True expected = '<div class="meta person-meta"><p>This person\'s details are unavailable to protect their privacy.</p></div>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)
def test_person(self) -> None: person = Person('1') sut = PersonName(person, 'Janet', 'Not a Girl') self.assertEquals(person, sut.person) self.assertCountEqual([sut], person.names) sut.person = None self.assertIsNone(sut.person) self.assertCountEqual([], person.names)
async def test_with_name(self): person = Person('P0') PersonName(person, 'Jane', 'Dough') expected = '<a href="/person/P0/index.html"><span class="person-label" typeof="foaf:Person"><span property="foaf:individualName">Jane</span> <span property="foaf:familyName">Dough</span></span></a>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)
async def test_private(self): person = Person('P0') person.private = True expected = '<a href="/person/P0/index.html"><span class="private" title="This person\'s details are unavailable to protect their privacy.">private</span></a>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)
async def test_with_end(self): person = Person('P0') Presence(person, Subject(), Event(None, Death(), Date(1970))) expected = '<div class="meta person-meta"><dl><div><dt>Death</dt><dd>1970</dd></div></dl></div>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)
async def test_person_is_context(self): person = Person('P0') expected = '<span class="nn" title="This person\'s name is unknown.">n.n.</span>' async with self._render(data={ 'person': person, 'person_context': person, }) as (actual, _): self.assertEqual(expected, actual)
def test_names(self) -> None: sut = Person('1') name = PersonName(sut, 'Janet', 'Not a Girl') self.assertCountEqual([name], sut.names) self.assertEquals(sut, name.person) sut.names.remove(name) self.assertCountEqual([], sut.names) self.assertIsNone(name.person)
def test_should_remove_names(self) -> None: person = Person('P0') name = PersonName(person, 'Jane', 'Dough') source = Source('The Source') citation = Citation(None, source) name.citations.append(citation) anonymize_person(person) self.assertEquals(0, len(person.names)) self.assertEquals(0, len(citation.facts))
async def test_derive_without_events( self, event_type_type: Type[DerivableEventType]): person = Person('P0') created, updated = derive(person, event_type_type) self.assertEquals(0, created) self.assertEquals(0, updated) self.assertEquals(0, len(person.presences))
async def test_embedded_with_identifiable(self): event = Event('E0', Birth()) Presence(Person('P0'), Subject(), event) expected = 'Birth of <span class="nn" title="This person\'s name is unknown.">n.n.</span>' async with self._render(data={ 'event': event, 'embedded': True, }) as (actual, _): self.assertEqual(expected, actual)