Ejemplo n.º 1
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 = 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
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.entities.append(person)
     privatize(ancestry)
     self.assertEquals(expected, person.private)
Ejemplo n.º 9
0
    def test_clean_should_not_clean_person_if_public(self):
        ancestry = Ancestry()

        person = Person('P0')
        person.private = False
        ancestry.entities.append(person)

        clean(ancestry)

        self.assertEqual(person, ancestry.entities[Person][person.id])
Ejemplo n.º 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)
     ancestry = Ancestry()
     ancestry.entities.append(person)
     privatize(ancestry)
     self.assertEquals(expected, person.private)
Ejemplo n.º 11
0
 async def test_post_parse(self) -> None:
     person = Person('P0')
     person.private = True
     PersonName(person, 'Jane', 'Dough')
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.extensions.add(ExtensionConfiguration(Anonymizer))
         async with App(configuration) as app:
             app.ancestry.entities.append(person)
             await load(app)
     self.assertEquals(0, len(person.names))
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 def test_privatize_person_with_grandparent(self, expected, private,
                                            event: Optional[Event]):
     person = Person('P0')
     person.private = private
     parent = Person('P1')
     person.parents.append(parent)
     grandparent = Person('P2')
     if event is not None:
         Presence(grandparent, Subject(), event)
     parent.parents.append(grandparent)
     ancestry = Ancestry()
     ancestry.entities.append(person)
     privatize(ancestry)
     self.assertEquals(expected, person.private)
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
def _load_person(loader: _Loader, element: ElementTree.Element):
    person_handle = element.get('handle')
    person = Person(element.get('id'))

    name_elements = sorted(_xpath(element, './ns:name'),
                           key=lambda x: x.get('alt') == '1')
    names = []
    for name_element in name_elements:
        is_alternative = name_element.get('alt') == '1'
        individual_name_element = _xpath1(name_element, './ns:first')
        individual_name = None if individual_name_element is None else individual_name_element.text
        surname_elements = [
            surname_element
            for surname_element in _xpath(name_element, './ns:surname')
            if surname_element.text is not None
        ]
        if surname_elements:
            for surname_element in surname_elements:
                if not is_alternative:
                    is_alternative = surname_element.get('prim') == '0'
                affiliation_name = surname_element.text
                surname_prefix = surname_element.get('prefix')
                if surname_prefix is not None:
                    affiliation_name = '%s %s' % (surname_prefix,
                                                  affiliation_name)
                person_name = PersonName(None, individual_name,
                                         affiliation_name)
                _load_citationref(loader, person_name, name_element)
                names.append((person_name, is_alternative))
        elif individual_name is not None:
            person_name = PersonName(None, individual_name)
            _load_citationref(loader, person_name, name_element)
            names.append((person_name, is_alternative))
    for person_name, _ in sorted(names, key=lambda x: x[1]):
        loader.add_entity(person_name)
        loader.add_association(Person, person_handle, 'names', PersonName,
                               person_name.id)

    _load_eventrefs(loader, person_handle, element)
    if element.get('priv') == '1':
        person.private = True

    flattened_person = FlattenedEntity(person, person_handle)
    _load_citationref(loader, flattened_person, element)
    _load_objref(loader, flattened_person, element)
    _load_urls(person, element)
    _load_attribute_privacy(person, element, 'attribute')
    loader.add_entity(flattened_person)
Ejemplo n.º 16
0
 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))
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 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))
Ejemplo n.º 20
0
    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)
Ejemplo n.º 21
0
    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])
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 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)
Ejemplo n.º 24
0
 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)
Ejemplo n.º 25
0
 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)
Ejemplo n.º 26
0
 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)
Ejemplo n.º 27
0
 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)
Ejemplo n.º 28
0
 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)
Ejemplo n.º 29
0
 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)
Ejemplo n.º 30
0
 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)