Exemplo n.º 1
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)
Exemplo n.º 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 = 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)
Exemplo n.º 3
0
    async def test_derive_update_derivable_event_without_reference_events(
            self, event_type_type: Type[DerivableEventType]):
        person = Person('P0')
        Presence(person, Subject(), Event(Ignored()))
        derivable_event = Event(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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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))
Exemplo n.º 7
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)
Exemplo n.º 8
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))
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 11
0
 async def test_minimal(self):
     event = Event(Birth())
     expected = 'Birth'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Exemplo n.º 12
0
 def test_person_deletion_upon_event_set_to_none(self) -> None:
     person = Person('P1')
     event = Event(Birth())
     sut = Presence(person, Subject(), event)
     sut.event = None
     self.assertIsNone(sut.person)
     self.assertNotIn(sut, person.presences)
Exemplo n.º 13
0
    def setUpClass(cls):
        cls._outputDirectory = TemporaryDirectory()
        configuration = Configuration(cls._outputDirectory.name,
                                      'https://ancestry.example.com')
        cls.site = Site(configuration)

        place1 = Place('PLACE1', 'one')

        event1 = Event('EVENT1', Event.Type.BIRTH)
        event1.place = place1

        event1_person_1_presence = Presence(Presence.Role.SUBJECT)
        event1_person_1_presence.event = event1

        person1 = Person('PERSON1', 'Janet', 'Dough')
        person1.presences.add(event1_person_1_presence)

        source1 = Source('SOURCE1', 'A Little Birdie')

        places = [place1]
        cls.site.ancestry.places.update({place.id: place for place in places})
        events = [event1]
        cls.site.ancestry.events.update({event.id: event for event in events})
        people = [person1]
        cls.site.ancestry.people.update(
            {person.id: person
             for person in people})
        sources = [source1]
        cls.site.ancestry.sources.update(
            {source.id: source
             for source in sources})

        render(cls.site)
 async def test_with_place(self):
     event = Event(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)
 async def test_with_date(self):
     event = Event(Birth())
     event.date = Date(1970)
     expected = '1970'
     async with self._render(data={
         'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
 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)
Exemplo n.º 17
0
 async def test_with_description(self):
     event = Event(Birth())
     event.description = 'Something happened!'
     expected = 'Birth (Something happened!)'
     async with self._render(data={
             'event': event,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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)
Exemplo n.º 21
0
 def test_place(self) -> None:
     place = Place('1', [PlaceName('one')])
     sut = Event(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)
Exemplo n.º 22
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)
Exemplo n.º 23
0
 def test_place_should_sync_references(self):
     place = Place('1', 'one')
     sut = Event('1', Event.Type.BIRTH)
     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)
Exemplo n.º 24
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)
Exemplo n.º 25
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)
 async def test_with_place_is_place_context(self):
     event = Event(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)
Exemplo n.º 27
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)
Exemplo n.º 28
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)
Exemplo n.º 29
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)
Exemplo n.º 30
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)