Ejemplo n.º 1
0
    async def test_derive_update_comes_after_derivable_event(
            self, expected_datey: Optional[Datey],
            after_datey: Optional[Datey], derivable_datey: Optional[Datey]):
        expected_updates = 0 if expected_datey == derivable_datey else 1
        person = Person('P0')
        Presence(person, Subject(), Event(Ignored(), Date(0, 0, 0)))
        Presence(person, Subject(), Event(ComesAfterReference(), after_datey))
        derivable_event = Event(ComesAfterDerivable(), derivable_datey)
        Presence(person, Subject(), derivable_event)

        created, updated = derive(person, ComesAfterDerivable)

        self.assertEquals(expected_datey, derivable_event.date)
        self.assertEquals(0, created)
        self.assertEquals(expected_updates, updated)
        self.assertEquals(3, len(person.presences))
Ejemplo n.º 2
0
 def test_should_remove_citations(self) -> None:
     event = Event(Birth())
     source = Source('The Source')
     citation = Citation(source)
     event.citations.append(citation)
     anonymize_event(event)
     self.assertEquals(0, len(event.citations))
Ejemplo n.º 3
0
 async def test_with_resource(self):
     event = Event(Birth())
     expected = 'Birth'
     async with self._render(data={
             'resource': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Ejemplo n.º 4
0
 async def test_without_meta(self):
     event = Event(Birth())
     expected = ''
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Ejemplo n.º 5
0
 def test_should_remove_citations(self) -> None:
     event = Event(Event.Type.BIRTH)
     source = Source('S0', 'The Source')
     citation = Citation('C0', source)
     event.citations.append(citation)
     anonymize_event(event)
     self.assertEquals(0, len(event.citations))
Ejemplo n.º 6
0
    async def test_post_parse(self):
        person = Person('P0')
        Presence(person, Subject(), Event(Birth()))

        source_file = File('F0', __file__)
        source = IdentifiableSource('S0', 'The Source')
        source.private = True
        source.files.append(source_file)

        citation_file = File('F0', __file__)
        citation_source = Source('The Source')
        citation = IdentifiableCitation('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.plugins[Privatizer] = None
            async with Site(configuration) as site:
                site.ancestry.people[person.id] = person
                site.ancestry.sources[source.id] = source
                site.ancestry.citations[citation.id] = citation
                await parse(site)

            self.assertTrue(person.private)
            self.assertTrue(source_file.private)
            self.assertTrue(citation_file.private)
Ejemplo n.º 7
0
 def test_should_remove_presences(self) -> None:
     person = Person('P0')
     event = Event(Birth())
     Presence(person, Subject(), event)
     anonymize_person(person)
     self.assertEquals(0, len(person.presences))
     self.assertEquals(0, len(event.presences))
Ejemplo n.º 8
0
class DelegatingUrlGeneratorTest(TestCase):
    @parameterized.expand([
        ('/index.html', '/index.html'),
        ('/index.html', '<front>'),
        ('/person/index.html', '<person>'),
        ('/person/P1/index.html', Person('P1')),
        ('/event/index.html', '<event>'),
        ('/event/E1/index.html', Event('E1', Event.Type.DEATH)),
        ('/place/index.html', '<place>'),
        ('/place/P1/index.html', Place('P1', 'Place 1')),
        ('/file/index.html', '<file>'),
        ('/file/F1/index.html', File('F1', '/tmp')),
        ('/source/index.html', '<source>'),
        ('/source/S1/index.html', Source('S1', 'Source 1')),
        ('/citation/index.html', '<citation>'),
        ('/citation/C1/index.html', Citation('C1')),
    ])
    def test_generate(self, expected: str, resource: Any):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = DelegatingUrlGenerator(configuration)
        self.assertEquals(expected, sut.generate(resource))

    def test_generate_with_invalid_value(self):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = DelegatingUrlGenerator(configuration)
        with self.assertRaises(ValueError):
            sut.generate(9)
 async def test_with_citation(self):
     event = Event(Birth())
     event.citations.append(Citation(Source('The Source')))
     expected = '<a href="#reference-1" class="citation">[1]</a>'
     async with self._render(data={
         'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Ejemplo n.º 10
0
 async def test_with_end(self):
     person = Person('P0')
     Presence(person, Subject(), Event(Death(), Date(1970)))
     expected = '<div class="meta"><dl><dt>Death</dt><dd>1970</dd></dl></div>'
     async with self._render(data={
             'person': person,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Ejemplo n.º 11
0
 async def test_with_witnesses(self):
     event = Event(Birth())
     Presence(Person('P0'), Witness(), event)
     expected = 'Birth'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Ejemplo n.º 12
0
 def test_presence_should_sync_references(self):
     presence = Presence(Presence.Role.SUBJECT)
     sut = Event('1', Event.Type.BIRTH)
     sut.presences.add(presence)
     self.assertCountEqual([presence], sut.presences)
     self.assertEquals(sut, presence.event)
     sut.presences.remove(presence)
     self.assertCountEqual([], sut.presences)
     self.assertIsNone(presence.event)
Ejemplo n.º 13
0
 def test_events_should_sync_references(self):
     sut = Place('1', 'one')
     event = Event('1', Event.Type.BIRTH)
     sut.events.add(event)
     self.assertIn(event, sut.events)
     self.assertEquals(sut, event.place)
     sut.events.remove(event)
     self.assertCountEqual([], sut.events)
     self.assertEquals(None, event.place)
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
    def test_clean(self):
        ancestry = Ancestry()

        onymous_event = Event('E0', Event.Type.BIRTH)
        onymous_event_presence = Presence(Presence.Role.SUBJECT)
        onymous_event_presence.person = Person('P0')
        onymous_event.presences.add(onymous_event_presence)
        ancestry.events[onymous_event.id] = onymous_event

        anonymous_event = Event('E1', Event.Type.BIRTH)
        ancestry.events[anonymous_event.id] = anonymous_event

        onymous_place = Place('P0', 'Amsterdam')
        onymous_place.events.add(onymous_event)
        ancestry.places[onymous_place.id] = onymous_place

        anonymous_place = Place('P1', 'Almelo')
        ancestry.places[anonymous_place.id] = anonymous_place

        onmyous_place_because_encloses_onmyous_places = Place(
            'P3', 'Netherlands')
        onmyous_place_because_encloses_onmyous_places.encloses.add(
            onymous_place)
        onmyous_place_because_encloses_onmyous_places.encloses.add(
            anonymous_place)
        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)
Ejemplo n.º 16
0
 def test_post_parse(self):
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.plugins[Cleaner] = {}
         site = Site(configuration)
         event = Event('E0', Event.Type.BIRTH)
         site.ancestry.events[event.id] = event
         parse(site)
         self.assertEquals({}, site.ancestry.events)
Ejemplo n.º 17
0
 async def test_with_person_context_as_subject(self):
     event = Event(Birth())
     person = Person('P0')
     Presence(person, Subject(), event)
     expected = 'Birth'
     async with self._render(data={
             'event': event,
             'person_context': person,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Ejemplo n.º 18
0
 def test_presences(self) -> None:
     person = Person('P1')
     sut = Event(Mock(EventType))
     presence = Presence(person, Subject(), sut)
     sut.presences.append(presence)
     self.assertCountEqual([presence], sut.presences)
     self.assertEquals(sut, presence.event)
     sut.presences.remove(presence)
     self.assertCountEqual([], sut.presences)
     self.assertIsNone(presence.event)
Ejemplo n.º 19
0
 def test_presences(self) -> None:
     event = Event(Birth())
     sut = Person('1')
     presence = Presence(sut, Subject(), event)
     sut.presences.append(presence)
     self.assertCountEqual([presence], sut.presences)
     self.assertEquals(sut, presence.person)
     sut.presences.remove(presence)
     self.assertCountEqual([], sut.presences)
     self.assertIsNone(presence.person)
Ejemplo n.º 20
0
 def test_anonymize_should_anonymize_private_person(self):
     with NamedTemporaryFile() as file_f:
         person = Person('P0', 'Janet', 'Dough')
         person.private = True
         partner = Person('P1', 'Jenny', 'Donut')
         person_presence = Presence(Presence.Role.SUBJECT)
         person_presence.person = person
         partner_presence = Presence(Presence.Role.SUBJECT)
         partner_presence.person = partner
         event = Event('E0', Event.Type.MARRIAGE)
         event.presences = [person_presence, partner_presence]
         file = File('D0', file_f.name)
         file.entities.add(person, partner)
         ancestry = Ancestry()
         ancestry.people[person.id] = person
         anonymize(ancestry)
         self.assert_anonymized(person)
         self.assertCountEqual([], event.presences)
         self.assertCountEqual([], file.entities)
Ejemplo n.º 21
0
 def test_presence_should_sync_references(self):
     event = Event(Event.Type.BIRTH)
     sut = Person('1')
     presence = Presence(sut, Presence.Role.SUBJECT, event)
     sut.presences.append(presence)
     self.assertCountEqual([presence], sut.presences)
     self.assertEquals(sut, presence.person)
     sut.presences.remove(presence)
     self.assertCountEqual([], sut.presences)
     self.assertIsNone(presence.person)
Ejemplo n.º 22
0
def _parse_event(ancestry: _IntermediateAncestry, element: Element):
    handle = str(_xpath1(element, './@handle'))
    gramps_type = _xpath1(element, './ns:type')

    event = Event(_xpath1(element, './@id'), _EVENT_TYPE_MAP[gramps_type.text])

    event.date = _parse_date(element)

    # Parse the event place.
    place_handle = _xpath1(element, './ns:place/@hlink')
    if place_handle:
        event.place = ancestry.places[place_handle]

    _parse_objref(ancestry, event, element)

    citation_handles = _xpath(element, './ns:citationref/@hlink')
    for citation_handle in citation_handles:
        event.citations.add(ancestry.citations[citation_handle])
    ancestry.events[handle] = event
Ejemplo n.º 23
0
 def test_anonymize_should_not_anonymize_public_person(self):
     with NamedTemporaryFile() as file_f:
         person = Person('P0', 'Janet', 'Dough')
         presence = Presence(Presence.Role.SUBJECT)
         presence.event = Event('E0', Event.Type.BIRTH)
         person.presences.add(presence)
         person.files.add(File('D0', file_f.name))
         ancestry = Ancestry()
         ancestry.people[person.id] = person
         anonymize(ancestry)
         self.assert_not_anonymized(person)
Ejemplo n.º 24
0
 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)
Ejemplo n.º 25
0
    async def test_derive_create_derivable_events_without_reference_events(
            self, event_type_type: Type[DerivableEventType]):
        person = Person('P0')
        derivable_event = Event(Ignored())
        Presence(person, Subject(), derivable_event)

        created, updated = derive(person, event_type_type)

        self.assertEquals(0, created)
        self.assertEquals(0, updated)
        self.assertEquals(1, len(person.presences))
        self.assertIsNone(derivable_event.date)
Ejemplo n.º 26
0
 async def test_embedded(self):
     person = Person('P0')
     Presence(person, Subject(), Event(Birth(), Date(1970)))
     person.names.append(PersonName('Jane', 'Dough'))
     name = PersonName('Janet', 'Doughnut')
     name.citations.append(Citation(Source('The Source')))
     person.names.append(name)
     expected = '<div class="meta"><span class="aka">Also known as <span class="person-label" typeof="foaf:Person"><span property="foaf:individualName">Janet</span> <span property="foaf:familyName">Doughnut</span></span></span><dl><dt>Birth</dt><dd>1970</dd></dl></div>'
     async with self._render(data={
             'person': person,
             'embedded': True,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Ejemplo n.º 27
0
 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)
Ejemplo n.º 28
0
 def test_post_parse(self):
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.plugins[Privatizer] = {}
         site = Site(configuration)
         person = Person('P0')
         presence = Presence(Presence.Role.SUBJECT)
         presence.event = Event('E0', Event.Type.BIRTH)
         person.presences.add(presence)
         site.ancestry.people[person.id] = person
         parse(site)
         self.assertTrue(person.private)
Ejemplo n.º 29
0
    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))
Ejemplo n.º 30
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)