Esempio n. 1
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. 2
0
 def test_should_remove_source(self) -> None:
     source = Source('The Source')
     citation = Citation('C0', source)
     anonymous_source = AnonymousSource()
     anonymous_citation = AnonymousCitation(anonymous_source)
     anonymize_citation(citation, anonymous_citation)
     self.assertIsNone(citation.source)
Esempio n. 3
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. 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
 async def test_citation_should_encode_minimal(self):
     citation = Citation('the_citation', Source(None, 'The Source'))
     expected = {
         '$schema':
         '/schema.json#/definitions/citation',
         '@type':
         'https://schema.org/Thing',
         'id':
         'the_citation',
         'facts': [],
         '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. 6
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))
Esempio n. 7
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. 8
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. 9
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. 10
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. 11
0
 def test_should_remove_citations(self) -> None:
     source = Source('S0', 'The Source')
     citation = Citation(None, source)
     source.citations.append(citation)
     anonymous_source = AnonymousSource()
     anonymize_source(source, anonymous_source)
     self.assertEquals(0, len(source.citations))
     self.assertIn(citation, anonymous_source.citations)
Esempio n. 12
0
 def test_should_remove_names(self) -> None:
     person = Person('P0')
     name = PersonName(person, 'Jane', 'Dough')
     source = Source('The Source')
     citation = Citation(None, source)
     name.citations.append(citation)
     anonymize_person(person)
     self.assertEquals(0, len(person.names))
     self.assertEquals(0, len(citation.facts))
Esempio n. 13
0
 def test_with_private_citation_should_anonymize(
         self, m_anonymize_citation) -> None:
     source = Source('The Source')
     citation = Citation('C0', source)
     citation.private = True
     ancestry = Ancestry()
     ancestry.entities.append(citation)
     anonymize(ancestry, AnonymousCitation(AnonymousSource()))
     m_anonymize_citation.assert_called_once_with(citation, ANY)
Esempio n. 14
0
 def test_with_public_citation_should_not_anonymize(
         self, m_anonymize_citation) -> None:
     source = Source('The Source')
     citation = Citation('C0', source)
     citation.private = False
     ancestry = Ancestry()
     ancestry.entities.append(citation)
     anonymize(ancestry, AnonymousCitation(AnonymousSource()))
     m_anonymize_citation.assert_not_called()
Esempio n. 15
0
    def test_facts(self) -> None:
        class _HasCitations(Entity, HasCitations):
            pass

        fact = _HasCitations()
        sut = Citation(None, Mock(Source))
        self.assertCountEqual([], sut.facts)
        sut.facts = [fact]
        self.assertCountEqual([fact], sut.facts)
Esempio n. 16
0
 async def test_with_one_alternative_name(self):
     person = Person('P0')
     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><a href="#reference-1" class="citation">[1]</a></span></div>'
     async with self._render(data={
             'person': person,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 17
0
 def test_should_remove_facts(self) -> None:
     source = Source('The Source')
     citation = Citation('C0', source)
     fact = PersonName(Person(None), 'Jane')
     citation.facts.append(fact)
     anonymous_source = AnonymousSource()
     anonymous_citation = AnonymousCitation(anonymous_source)
     anonymize_citation(citation, anonymous_citation)
     self.assertEquals(0, len(citation.facts))
     self.assertIn(fact, anonymous_citation.facts)
Esempio n. 18
0
 def test_should_remove_files(self) -> None:
     source = Source('The Source')
     citation = Citation('C0', source)
     file = File('F0', __file__)
     citation.files.append(file)
     anonymous_source = AnonymousSource()
     anonymous_citation = AnonymousCitation(anonymous_source)
     anonymize_citation(citation, anonymous_citation)
     self.assertEquals(0, len(citation.files))
     self.assertIn(file, anonymous_citation.files)
Esempio n. 19
0
 async def test_citation(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     citation = Citation('CITATION1', Source('A Little Birdie'))
     app.ancestry.entities.append(citation)
     async with app:
         await generate(app)
     self.assert_betty_html(app, '/citation/%s/index.html' % citation.id)
     self.assert_betty_json(app, '/citation/%s/index.json' % citation.id,
                            'citation')
Esempio n. 20
0
 async def test_with_citation(self):
     person = Person(None)
     name = PersonName(person, 'Jane')
     source = Source(None)
     citation = Citation(None, source)
     name.citations.append(citation)
     expected = '<span class="person-label" typeof="foaf:Person"><span property="foaf:individualName">Jane</span></span><a href="#reference-1" class="citation">[1]</a>'
     async with self._render(data={
         'name': name,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 21
0
 def test_privatize_file_should_privatize_if_private(self):
     source = Source(None, 'The Source')
     citation = Citation(None, source)
     file = File('F0', __file__)
     file.private = True
     file.citations.append(citation)
     ancestry = Ancestry()
     ancestry.entities.append(file)
     privatize(ancestry)
     self.assertTrue(True, file.private)
     self.assertTrue(citation.private)
Esempio n. 22
0
 def test_privatize_file_should_not_privatize_if_public(self):
     source = Source(None, 'The Source')
     citation = Citation(None, source)
     file = File('F0', __file__)
     file.private = False
     file.citations.append(citation)
     ancestry = Ancestry()
     ancestry.entities.append(file)
     privatize(ancestry)
     self.assertEqual(False, file.private)
     self.assertIsNone(citation.private)
Esempio n. 23
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. 24
0
 async def test_populate_should_ignore_resource_without_link_support(self, m_retriever) -> None:
     source = Source('The Source')
     resource = Citation('the_citation', source)
     with TemporaryDirectory() as output_directory_path:
         with TemporaryDirectory() as cache_directory_path:
             configuration = Configuration(
                 output_directory_path, 'https://example.com')
             configuration.cache_directory_path = cache_directory_path
             async with App(configuration) as app:
                 app.ancestry.entities.append(resource)
                 sut = _Populator(app, m_retriever)
                 await sut.populate()
Esempio n. 25
0
 async def test_embedded(self):
     person = Person(None)
     name = PersonName(person, 'Jane', 'Dough')
     source = Source(None)
     citation = Citation(None, source)
     name.citations.append(citation)
     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,
         'embedded': True,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Esempio n. 26
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)
Esempio n. 27
0
    def test_clean_should_clean_citation(self) -> None:
        ancestry = Ancestry()

        source = Source('S0', 'The source')
        ancestry.entities.append(source)

        citation = Citation('C0', source)
        ancestry.entities.append(citation)

        clean(ancestry)

        self.assertNotIn(citation.id, ancestry.entities[Citation])
        self.assertNotIn(citation, source.citations)
Esempio n. 28
0
 def test_replace(self):
     citations = [Citation(None, Source(None))]
     contains = [Source(None)]
     files = [Mock(File)]
     sut = AnonymousSource()
     other = AnonymousSource()
     other.citations = citations
     other.contains = contains
     other.files = files
     sut.replace(other)
     self.assertEquals(citations, list(sut.citations))
     self.assertEquals(contains, list(sut.contains))
     self.assertEquals(files, list(sut.files))
Esempio n. 29
0
 def test_privatize_citation_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.private = True
     citation.files.append(citation_file)
     ancestry = Ancestry()
     ancestry.entities.append(citation)
     privatize(ancestry)
     self.assertTrue(citation.private)
     self.assertTrue(source.private)
     self.assertTrue(citation_file.private)
     self.assertTrue(source_file.private)
Esempio n. 30
0
 def test_privatize_citation_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 = Citation('C0', source)
     citation.private = False
     citation.files.append(citation_file)
     ancestry = Ancestry()
     ancestry.entities.append(citation)
     privatize(ancestry)
     self.assertEqual(False, citation.private)
     self.assertIsNone(source.private)
     self.assertIsNone(citation_file.private)
     self.assertIsNone(source_file.private)