예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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')
예제 #7
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))
예제 #8
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))
예제 #9
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])
예제 #10
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')
예제 #11
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])
예제 #12
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)
예제 #13
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)
예제 #14
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)
예제 #15
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)
예제 #16
0
 async def test_with_start(self):
     person = Person('P0')
     Presence(person, Subject(), Event(None, Birth(), Date(1970)))
     expected = '<div class="meta person-meta"><dl><div><dt>Birth</dt><dd>1970</dd></div></dl></div>'
     async with self._render(data={
             'person': person,
     }) as (actual, _):
         self.assertEqual(expected, actual)
예제 #17
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)
예제 #18
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)
예제 #19
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)
예제 #20
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)
예제 #21
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)
예제 #22
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)
예제 #23
0
 async def test_post_parse(self) -> None:
     event = Event('E0', Birth())
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.extensions.add(ExtensionConfiguration(Cleaner))
         async with App(configuration) as app:
             app.ancestry.entities.append(event)
             await load(app)
             self.assertEquals([], list(app.ancestry.entities[Event]))
예제 #24
0
 async def test_with_person_context_as_subject(self):
     event = Event(None, 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)
예제 #25
0
 async def test_event(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     async with app:
         event = Event('EVENT1', Birth())
         app.ancestry.entities.append(event)
         await generate(app)
     self.assert_betty_html(app, '/event/%s/index.html' % event.id)
     self.assert_betty_json(app, '/event/%s/index.json' % event.id, 'event')
예제 #26
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)
예제 #27
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)
예제 #28
0
 async def test_embedded(self):
     person = Person('P0')
     Presence(person, Subject(), Event(None, Birth(), Date(1970)))
     PersonName(person, 'Jane', 'Dough')
     name = PersonName(person, 'Janet', 'Doughnut')
     name.citations.append(Citation(None, Source(None, 'The Source')))
     expected = '<div class="meta person-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><div><dt>Birth</dt><dd>1970</dd></div></dl></div>'
     async with self._render(data={
             'person': person,
             'embedded': True,
     }) as (actual, _):
         self.assertEqual(expected, actual)
예제 #29
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 = Citation('C0', source)
     citation.files.append(citation_file)
     event_file = File('F1', __file__)
     event = Event('E1', Birth())
     event.private = True
     event.citations.append(citation)
     event.files.append(event_file)
     person = Person('P0')
     Presence(person, Subject(), event)
     ancestry = Ancestry()
     ancestry.entities.append(event)
     privatize(ancestry)
     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)
예제 #30
0
 def test_comes_before(self) -> None:
     self.assertIsInstance(Birth.comes_before(), set)