Beispiel #1
0
    def test_should_not_remove_parents_with_public_descendants(self) -> None:
        person = Person('P0')
        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)
Beispiel #2
0
    def test_anonymize_person_should_anonymize_parents_if_public_with_public_descendants(
            self):
        person = Person('P0')
        person.private = False
        child = Person('P1')
        child.private = False
        person.children.add(child)
        parent = Person('P2')
        parent.private = True
        person.parents.add(parent)

        anonymize_person(person)
        self.assertCountEqual([parent], person.parents)
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
 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()
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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)
Beispiel #10
0
 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)
Beispiel #11
0
 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)
Beispiel #12
0
    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])
Beispiel #13
0
    def test_clean_should_not_clean_person_with_public_children(self):
        ancestry = Ancestry()

        person = Person('P0')
        person.private = False
        ancestry.people[person.id] = person
        child = Person('P1')
        child.private = True
        ancestry.people[child.id] = child
        grandchild = Person('P2')
        grandchild.private = True
        ancestry.people[grandchild.id] = grandchild
        great_grandchild = Person('P3')
        great_grandchild.private = False
        ancestry.people[great_grandchild.id] = great_grandchild

        clean(ancestry)

        self.assertEqual(person, ancestry.people[person.id])
Beispiel #14
0
    def test_clean_should_clean_private_people(self) -> None:
        ancestry = Ancestry()

        person = Person('P0')
        person.private = False
        ancestry.people[person.id] = person
        child = Person('P1')
        child.private = True
        ancestry.people[child.id] = child
        grandchild = Person('P2')
        grandchild.private = True
        ancestry.people[grandchild.id] = grandchild
        great_grandchild = Person('P3')
        great_grandchild.private = True
        ancestry.people[great_grandchild.id] = great_grandchild

        clean(ancestry)

        self.assertEquals(1, len(ancestry.people))
Beispiel #15
0
 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)
Beispiel #16
0
 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)
Beispiel #17
0
    def test_clean_should_clean_person_with_private_children(self) -> None:
        ancestry = Ancestry()

        person = Person('P0')
        person.private = True
        ancestry.people[person.id] = person
        child = Person('P1')
        child.private = True
        ancestry.people[child.id] = child
        grandchild = Person('P2')
        grandchild.private = True
        ancestry.people[grandchild.id] = grandchild
        great_grandchild = Person('P3')
        great_grandchild.private = True
        ancestry.people[great_grandchild.id] = great_grandchild

        clean(ancestry)

        self.assertNotIn(person.id, ancestry.people)
Beispiel #18
0
 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))
Beispiel #19
0
 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)
Beispiel #20
0
 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))
Beispiel #21
0
 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)
Beispiel #22
0
 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)
Beispiel #23
0
 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)
Beispiel #24
0
 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)
Beispiel #25
0
def _privatize_person(person: Person, seen: List, lifetime_threshold: int) -> None:
    # Do not change existing explicit privacy declarations.
    if person.private is None:
        person.private = _person_is_private(person, lifetime_threshold)

    if not person.private:
        return

    for presence in person.presences:
        if isinstance(presence.role, Subject):
            _mark_private(presence.event)
            _privatize_event(presence.event, seen)

    _privatize_has_citations(person, seen)
    _privatize_has_files(person, seen)
Beispiel #26
0
    def test_anonymize_should_not_anonymize_people_with_public_descendants(
            self):
        ancestry = Ancestry()

        person = Person('P0')
        person.private = True
        ancestry.people[person.id] = person
        child = Person('P1')
        child.private = True
        person.children.add(child)
        ancestry.people[child.id] = child
        grandchild = Person('P2')
        grandchild.private = True
        child.children.add(grandchild)
        ancestry.people[grandchild.id] = grandchild
        great_grandchild = Person('P3')
        great_grandchild.private = False
        grandchild.children.add(great_grandchild)
        ancestry.people[great_grandchild.id] = great_grandchild

        anonymize(ancestry)
        self.assertCountEqual([child], person.children)
        self.assertCountEqual([grandchild], child.children)
        self.assertCountEqual([great_grandchild], grandchild.children)
Beispiel #27
0
 def test_privatize_with_child(self, expected, private,
                               event: Optional[Event]):
     person = Person('P0', 'Janet', 'Dough')
     person.private = private
     child = Person('P1')
     if event is not None:
         presence = Presence(Presence.Role.SUBJECT)
         presence.event = event
         child.presences.add(presence)
     person.children.add(child)
     ancestry = Ancestry()
     ancestry.people[person.id] = person
     ancestry.people[child.id] = child
     sut = Privatizer()
     sut.privatize(ancestry)
     self.assertEquals(expected, person.private)
Beispiel #28
0
 def test_post_parse(self):
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.plugins[Anonymizer] = {}
         site = Site(configuration)
         with NamedTemporaryFile() as file_f:
             person = Person('P0', 'Janet', 'Dough')
             person.private = True
             presence = Presence(Presence.Role.SUBJECT)
             presence.event = Event('E0', Event.Type.BIRTH)
             person.presences.add(presence)
             person.files.add(File('D0', file_f.name))
             site.ancestry.people[person.id] = person
             parse(site)
             self.assert_anonymized(person)
Beispiel #29
0
    async def test_private_person(self):
        person_id = 'P1'
        individual_name = 'Jane'
        person = Person(person_id)
        person.names.append(PersonName(individual_name))
        person.private = True

        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')
            async with Site(configuration) as site:
                site.ancestry.people[person_id] = person
                indexed = [item for item in await Index(site).build()]

        self.assertEquals([], indexed)
Beispiel #30
0
def privatize_person(person: Person, lifetime_threshold: int) -> None:
    # Do not change existing explicit privacy declarations.
    if person.private is None:
        person.private = _person_is_private(person, lifetime_threshold)

    if not person.private:
        return

    for presence in person.presences:
        if isinstance(presence.role, Subject):
            _mark_private(presence.event)
            privatize_event(presence.event)
    for file in person.files:
        _mark_private(file)
    for citation in person.citations:
        _mark_private(citation)
        privatize_citation(citation)