Esempio n. 1
0
def _load_event(loader: _Loader, element: ElementTree.Element):
    event_handle = element.get('handle')
    event_id = element.get('id')
    gramps_type = _xpath1(element, './ns:type')

    try:
        event_type = _EVENT_TYPE_MAP[gramps_type.text]
    except KeyError:
        event_type = UnknownEventType()
        getLogger().warning(
            'Betty is unfamiliar with Gramps event "%s"\'s type of "%s". The event was imported, but its type was set to "%s".'
            % (event_id, gramps_type.text, event_type.label))

    event = Event(event_id, event_type)

    event.date = _load_date(element)

    # Load the event place.
    place_handle = _load_handle('place', element)
    if place_handle is not None:
        loader.add_association(Event, event_handle, 'place', Place,
                               place_handle)

    # Load the description.
    description_element = _xpath1(element, './ns:description')
    if description_element is not None:
        event.description = description_element.text

    _load_attribute_privacy(event, element, 'attribute')

    flattened_event = FlattenedEntity(event, event_handle)
    _load_objref(loader, flattened_event, element)
    _load_citationref(loader, flattened_event, element)
    loader.add_entity(flattened_event)
Esempio n. 2
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])
Esempio n. 3
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)
Esempio n. 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 = 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)
Esempio n. 5
0
    def test_clean_should_clean_event(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)

        event = Event('E0', Birth())
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.entities.append(event)

        clean(ancestry)

        self.assertNotIn(event.id, ancestry.entities[Event])
        self.assertIsNone(event.place)
        self.assertNotIn(event, place.events)
        self.assertNotIn(place.id, ancestry.entities[Place])
        self.assertNotIn(event, citation.facts)
        self.assertNotIn(citation.id, ancestry.entities[Citation])
        self.assertNotIn(event, file.entities)
        self.assertNotIn(file.id, ancestry.entities[File])
Esempio n. 6
0
 async def test_with_description(self):
     event = Event(None, Birth())
     event.description = 'Something happened!'
     expected = 'Birth (Something happened!)'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 7
0
 async def test_with_place(self):
     event = Event(None, Birth())
     event.place = Place('P0', [PlaceName('The Place')])
     expected = 'in <address><a href="/place/P0/index.html"><span>The Place</span></a></address>'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 8
0
 async def test_with_date(self):
     event = Event(None, Birth())
     event.date = Date(1970)
     expected = '1970'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 9
0
 def test_with_private_event_should_anonymize(self,
                                              m_anonymize_event) -> None:
     event = Event('E0', Birth())
     event.private = True
     ancestry = Ancestry()
     ancestry.entities.append(event)
     anonymize(ancestry, AnonymousCitation(AnonymousSource()))
     m_anonymize_event.assert_called_once_with(event)
Esempio n. 10
0
 def test_place(self) -> None:
     place = Place('1', [PlaceName('one')])
     sut = Event(None, Mock(EventType))
     sut.place = place
     self.assertEquals(place, sut.place)
     self.assertIn(sut, place.events)
     sut.place = None
     self.assertEquals(None, sut.place)
     self.assertNotIn(sut, place.events)
Esempio n. 11
0
 async def test_with_place_is_place_context(self):
     event = Event(None, Birth())
     place = Place('P0', [PlaceName('The Place')])
     event.place = place
     expected = ''
     async with self._render(data={
             'event': event,
             'place_context': place,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 12
0
 async def test_embedded(self):
     event = Event(None, Birth())
     event.date = Date(1970)
     event.place = Place('P0', [PlaceName('The Place')])
     event.citations.append(Citation(None, Source(None, 'The Source')))
     expected = '1970 in <address><span>The Place</span></address>'
     async with self._render(data={
             'event': event,
             'embedded': True,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 13
0
 def test_associated_files(self) -> None:
     file1 = Mock(File)
     file2 = Mock(File)
     file3 = Mock(File)
     file4 = Mock(File)
     sut = Event(None, Mock(EventType))
     sut.files = [file1, file2, file1]
     citation = Mock(Citation)
     citation.associated_files = [file3, file4, file2]
     sut.citations = [citation]
     self.assertEquals([file1, file2, file3, file4],
                       list(sut.associated_files))
Esempio n. 14
0
    async def test_derive_update_derivable_event_without_reference_events(
            self, event_type_type: Type[DerivableEventType]):
        person = Person('P0')
        Presence(person, Subject(), Event(None, Ignored()))
        derivable_event = Event(None, event_type_type())
        Presence(person, Subject(), derivable_event)

        created, updated = derive(person, event_type_type)

        self.assertEquals(0, created)
        self.assertEquals(0, updated)
        self.assertEquals(2, len(person.presences))
        self.assertIsNone(derivable_event.date)
Esempio n. 15
0
 def test_should_remove_citations(self) -> None:
     event = Event(None, Birth())
     source = Source(None, 'The Source')
     citation = Citation(None, source)
     event.citations.append(citation)
     anonymize_event(event)
     self.assertEquals(0, len(event.citations))
Esempio 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))
Esempio n. 17
0
 async def test_citation_should_encode_full(self):
     citation = Citation('the_citation', Source('the_source', 'The Source'))
     citation.description = 'The Source Description'
     citation.facts.append(Event('the_event', Birth()))
     expected = {
         '$schema':
         '/schema.json#/definitions/citation',
         '@type':
         'https://schema.org/Thing',
         'id':
         'the_citation',
         'source':
         '/en/source/the_source/index.json',
         'facts': ['/en/event/the_event/index.json'],
         'links': [
             {
                 'url': '/en/citation/the_citation/index.json',
                 'relationship': 'canonical',
                 'mediaType': 'application/json',
             },
             {
                 'url': '/nl/citation/the_citation/index.json',
                 'relationship': 'alternate',
                 'locale': 'nl-NL',
             },
             {
                 'url': '/en/citation/the_citation/index.html',
                 'relationship': 'alternate',
                 'mediaType': 'text/html',
             },
         ],
     }
     await self.assert_encodes(expected, citation, 'citation')
Esempio n. 18
0
 async def test_minimal(self):
     event = Event(None, Birth())
     expected = 'Birth'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 19
0
 async def test_with_identifiable(self):
     event = Event('E0', Birth())
     expected = '<a href="/event/E0/index.html">Birth</a>'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 20
0
 async def test_event_should_encode_minimal(self):
     event = Event('the_event', Birth())
     expected = {
         '$schema':
         '/schema.json#/definitions/event',
         '@type':
         'https://schema.org/Event',
         'id':
         'the_event',
         'type':
         'birth',
         'presences': [],
         'citations': [],
         'links': [
             {
                 'url': '/en/event/the_event/index.json',
                 'relationship': 'canonical',
                 'mediaType': 'application/json',
             },
             {
                 'url': '/nl/event/the_event/index.json',
                 'relationship': 'alternate',
                 'locale': 'nl-NL',
             },
             {
                 'url': '/en/event/the_event/index.html',
                 'relationship': 'alternate',
                 'mediaType': 'text/html',
             },
         ],
     }
     await self.assert_encodes(expected, event, 'event')
Esempio n. 21
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)
Esempio n. 22
0
    def derive(cls, person: Person, derivable_event: Event,
               reference_event_type_types: Set[Type[EventType]]) -> bool:
        if not reference_event_type_types:
            return False

        reference_events = _get_reference_events(person,
                                                 reference_event_type_types)
        reference_events_dates = cls._get_events_dates(reference_events)
        reference_events_dates = filter(lambda x: x[1].comparable,
                                        reference_events_dates)
        if derivable_event.date is not None:
            reference_events_dates = filter(
                lambda x: cls._compare(derivable_event.date, x[1]),
                reference_events_dates)
        reference_events_dates = cls._sort(reference_events_dates)
        try:
            reference_event, reference_date = reference_events_dates[0]
        except IndexError:
            return False

        if derivable_event.date is None:
            derivable_event.date = DateRange()
        cls._set(derivable_event, DerivedDate.derive(reference_date))
        derivable_event.citations.append(*reference_event.citations)

        return True
Esempio n. 23
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)
Esempio n. 24
0
 async def test_with_citation(self):
     event = Event(None, Birth())
     event.citations.append(Citation(None, Source(None, 'The Source')))
     expected = '<a href="#reference-1" class="citation">[1]</a>'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 25
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)
Esempio n. 26
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(None, Ignored(), Date(0, 0, 0)))
        Presence(person, Subject(),
                 Event(None, ComesAfterReference(), after_datey))
        derivable_event = Event(None, 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))
Esempio n. 27
0
 def test_events(self) -> None:
     sut = Place('P1', [PlaceName('The Place')])
     event = Event('1', Birth())
     sut.events.append(event)
     self.assertIn(event, sut.events)
     self.assertEquals(sut, event.place)
     sut.events.remove(event)
     self.assertCountEqual([], sut.events)
     self.assertEquals(None, event.place)
Esempio n. 28
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)
Esempio n. 29
0
 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)
Esempio n. 30
0
 def test_presences(self) -> None:
     event = Event(None, 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)