def test_siblings_with_multiple_common_parents(self): sut = Person('1') sibling = Person('2') parent = Person('3') parent.children = [sut, sibling] self.assertCountEqual([sibling], sut.siblings)
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 = IdentifiableCitation('C0', source) citation.files.append(citation_file) event_as_subject = Event(Birth()) event_as_attendee = Event(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) privatize_person(person, 125) 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)
def test_privatize_person_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_as_subject = Event(Birth()) event_as_attendee = Event(Marriage()) person_file = File('F2', __file__) person = Person('P0') person.private = False person.citations.append(citation) person.files.append(person_file) Presence(person, Subject(), event_as_subject) Presence(person, Attendee(), event_as_attendee) ancestry = Ancestry() ancestry.people[person.id] = person privatize(ancestry) self.assertEqual(False, person.private) self.assertIsNone(citation.private) self.assertIsNone(source.private) self.assertIsNone(person_file.private) self.assertIsNone(citation_file.private) self.assertIsNone(source_file.private) self.assertIsNone(event_as_subject.private) self.assertIsNone(event_as_attendee.private)
def test_privatize_person_without_relatives(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private if event is not None: Presence(person, Subject(), event) privatize_person(person, 125) self.assertEquals(expected, person.private)
def test_with_private_person_should_anonymize(self, m_anonymize_person) -> None: person = Person('P0') person.private = True ancestry = Ancestry() ancestry.people[person.id] = person anonymize(ancestry) m_anonymize_person.assert_called_once_with(person)
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_private(self): person = Person('P0') person.private = True expected = '<div class="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_with_public_person_should_not_anonymize( self, m_anonymize_person) -> None: person = Person('P0') person.private = False ancestry = Ancestry() ancestry.people[person.id] = person anonymize(ancestry) m_anonymize_person.assert_not_called()
async def test_with_subjects(self): event = Event(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_children_should_sync_references(self): 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)
def test_privatize_person_with_child(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private child = Person('P1') if event is not None: Presence(child, Subject(), event) person.children.append(child) privatize_person(person, 125) self.assertEquals(expected, person.private)
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_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) privatize_person(person, 125) self.assertEquals(expected, person.private)
def test_parents_should_sync_references(self): 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)
def test_privatize_person_without_relatives(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private if event is not None: Presence(person, Subject(), event) ancestry = Ancestry() ancestry.people[person.id] = person privatize(ancestry) self.assertEquals(expected, person.private)
def test_clean_should_not_clean_person_if_public(self): ancestry = Ancestry() person = Person('P0') person.private = False ancestry.people[person.id] = person clean(ancestry) self.assertEqual(person, ancestry.people[person.id])
def test_privatize_without_relatives(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private if event is not None: Presence(person, Presence.Role.SUBJECT, event) ancestry = Ancestry() ancestry.people[person.id] = person sut = Privatizer() sut.privatize(ancestry) self.assertEquals(expected, person.private)
async def test_post_parse(self) -> None: person = Person('P0') person.private = True person.names.append(PersonName('Jane', 'Dough')) with TemporaryDirectory() as output_directory_path: configuration = Configuration(output_directory_path, 'https://example.com') configuration.extensions[Anonymizer] = None async with App(configuration) as app: app.ancestry.people[person.id] = person await load(app) self.assertEquals(0, len(person.names))
def test_post_parse(self) -> None: with TemporaryDirectory() as output_directory_path: configuration = Configuration(output_directory_path, 'https://example.com') configuration.plugins[Anonymizer] = {} site = Site(configuration) person = Person('P0') person.private = True person.names.append(PersonName('Jane', 'Dough')) site.ancestry.people[person.id] = person parse(site) self.assertEquals(0, len(person.names))
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.people[person.id] = person privatize(ancestry) self.assertEquals(expected, person.private)
async def test_with_person_context_and_other_as_subject(self): event = Event(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_privatize_with_parent(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private parent = Person('P1') if event is not None: Presence(parent, Presence.Role.SUBJECT, event) person.parents.append(parent) ancestry = Ancestry() ancestry.people[person.id] = person ancestry.people[parent.id] = parent sut = Privatizer() sut.privatize(ancestry) self.assertEquals(expected, person.private)
def test_privatize_with_child(self, expected, private, event: Optional[Event]): person = Person('P0') person.private = private child = Person('P1') if event is not None: Presence(child, Presence.Role.SUBJECT, event) person.children.append(child) ancestry = Ancestry() ancestry.people[person.id] = person ancestry.people[child.id] = child sut = Privatizer() sut.privatize(ancestry) self.assertEquals(expected, person.private)
def test_privatize_without_relatives(self, expected, private, event: Optional[Event]): person = Person('P0', 'Janet', 'Dough') person.private = private if event is not None: presence = Presence(Presence.Role.SUBJECT) presence.event = event person.presences.add(presence) ancestry = Ancestry() ancestry.people[person.id] = person sut = Privatizer() sut.privatize(ancestry) self.assertEquals(expected, person.private)
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.people[person.id] = person privatize(ancestry) self.assertEquals(expected, person.private)
def anonymize_person(person: Person) -> None: person.individual_name = None person.family_name = None for presence in set(person.presences): person.presences.remove(presence) event = presence.event if event is not None: for event_presence in event.presences: event_presence.person = None event.presences = [] for file in set(person.files): file.entities = [] # If a person is public themselves, or a node connecting other public persons, preserve their place in the graph. if person.private and not _has_public_descendants(person): person.parents = set()
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 setUpClass(cls): cls._outputDirectory = TemporaryDirectory() configuration = Configuration(cls._outputDirectory.name, 'https://ancestry.example.com') cls.site = Site(configuration) place1 = Place('PLACE1', 'one') event1 = Event('EVENT1', Event.Type.BIRTH) event1.place = place1 event1_person_1_presence = Presence(Presence.Role.SUBJECT) event1_person_1_presence.event = event1 person1 = Person('PERSON1', 'Janet', 'Dough') person1.presences.add(event1_person_1_presence) source1 = Source('SOURCE1', 'A Little Birdie') places = [place1] cls.site.ancestry.places.update({place.id: place for place in places}) events = [event1] cls.site.ancestry.events.update({event.id: event for event in events}) people = [person1] cls.site.ancestry.people.update( {person.id: person for person in people}) sources = [source1] cls.site.ancestry.sources.update( {source.id: source for source in sources}) render(cls.site)
async def test_without_meta(self): person = Person('P0') expected = '<div class="meta"></div>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)