Exemple #1
0
 def test_with_private_citation_should_anonymize(
         self, m_anonymize_citation) -> None:
     source = Source('S0', 'The Source')
     citation = Citation('C0', source)
     citation.private = True
     ancestry = Ancestry()
     ancestry.citations[citation.id] = citation
     anonymize(ancestry)
     m_anonymize_citation.assert_called_once_with(citation)
Exemple #2
0
 def test_with_public_citation_should_not_anonymize(
         self, m_anonymize_citation) -> None:
     source = Source('S0', 'The Source')
     citation = Citation('C0', source)
     citation.private = False
     ancestry = Ancestry()
     ancestry.citations[citation.id] = citation
     anonymize(ancestry)
     m_anonymize_citation.assert_not_called()
Exemple #3
0
 def test_citation_should_encode_full(self):
     citation = Citation('the_citation', Source('the_source', 'The Source'))
     citation.description = 'The Source Description'
     citation.facts.append(IdentifiableEvent('the_event', Event.Type.BIRTH))
     expected = {
         '$schema': '/schema.json#/definitions/citation',
         '@type': 'https://schema.org/Thing',
         'id': 'the_citation',
         'source': '/source/the_source/index.json',
         'facts': ['/event/the_event/index.json'],
     }
     self.assert_encodes(expected, citation, 'citation')
Exemple #4
0
def _parse_citation(ancestry: _IntermediateAncestry, element: Element) -> None:
    handle = _xpath1(element, './@handle')

    citation = Citation(_xpath1(element, './@id'))

    _parse_objref(ancestry, citation, element)

    page = _xpath1(element, './ns:page')
    if page is not None:
        citation.description = page.text

    source_handle = _xpath1(element, './ns:sourceref/@hlink')
    if source_handle is not None:
        citation.source = ancestry.sources[source_handle]

    ancestry.citations[handle] = citation
Exemple #5
0
def _parse_citation(ancestry: _IntermediateAncestry, element: Element) -> None:
    handle = _xpath1(element, './@handle')
    source_handle = _xpath1(element, './ns:sourceref/@hlink')

    citation = Citation(_xpath1(element, './@id'),
                        ancestry.sources[source_handle])

    citation.date = _parse_date(element)
    _parse_objref(ancestry, citation, element)
    _parse_attribute_privacy(citation, element)

    page = _xpath1(element, './ns:page')
    if page is not None:
        citation.location = page.text

    ancestry.citations[handle] = citation
Exemple #6
0
 def test_should_remove_citations(self) -> None:
     person = Person('P0')
     source = Source('S0', 'The Source')
     citation = Citation('C0', source)
     person.citations.append(citation)
     anonymize_person(person)
     self.assertEquals(0, len(person.citations))
Exemple #7
0
    def test_clean_should_not_clean_event_with_presences_with_people(
            self) -> None:
        ancestry = Ancestry()

        source = Source('S1', 'The Source')
        ancestry.sources[source.id] = source

        citation = Citation('C1', source)
        ancestry.citations[citation.id] = citation

        file = File('F1', __file__)
        ancestry.files[file.id] = file

        place = Place('P0', [LocalizedName('The Place')])
        ancestry.places[place.id] = place

        person = Person('P0')

        event = IdentifiableEvent('E0', Event.Type.BIRTH)
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.events[event.id] = event

        Presence(person, Presence.Role.SUBJECT, event)

        clean(ancestry)

        self.assertEqual(event, ancestry.events[event.id])
        self.assertIn(event, place.events)
        self.assertEqual(place, ancestry.places[place.id])
        self.assertIn(event, citation.facts)
        self.assertEqual(citation, ancestry.citations[citation.id])
        self.assertIn(event, file.resources)
        self.assertEqual(file, ancestry.files[file.id])
Exemple #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))
Exemple #9
0
    def test_clean_should_clean_event(self) -> None:
        ancestry = Ancestry()

        source = Source('S1', 'The Source')
        ancestry.sources[source.id] = source

        citation = Citation('C1', source)
        ancestry.citations[citation.id] = citation

        file = File('F1', __file__)
        ancestry.files[file.id] = file

        place = Place('P0', [LocalizedName('The Place')])
        ancestry.places[place.id] = place

        event = IdentifiableEvent('E0', Event.Type.BIRTH)
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.events[event.id] = event

        clean(ancestry)

        self.assertNotIn(event.id, ancestry.events)
        self.assertIsNone(event.place)
        self.assertNotIn(event, place.events)
        self.assertNotIn(place.id, ancestry.places)
        self.assertNotIn(event, citation.facts)
        self.assertNotIn(citation.id, ancestry.citations)
        self.assertNotIn(event, file.resources)
        self.assertNotIn(file.id, ancestry.files)
Exemple #10
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)
Exemple #11
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))
 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)
Exemple #13
0
 def test_should_remove_citations(self) -> None:
     source = IdentifiableSource('S0', 'The Source')
     citation = Citation(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)
 async def test_with_citation(self):
     name = PersonName('Jane')
     source = Source()
     citation = Citation(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)
Exemple #15
0
 def test_citation_should_encode_minimal(self):
     citation = Citation('the_citation', Source('the_source', 'The Source'))
     expected = {
         '$schema': '/schema.json#/definitions/citation',
         '@type': 'https://schema.org/Thing',
         'id': 'the_citation',
         'source': '/source/the_source/index.json',
         'facts': [],
     }
     self.assert_encodes(expected, citation, 'citation')
Exemple #16
0
 def test_should_remove_names(self) -> None:
     person = Person('P0')
     name = PersonName('Jane', 'Dough')
     source = Source('The Source')
     citation = Citation(source)
     name.citations.append(citation)
     person.names.append(name)
     anonymize_person(person)
     self.assertEquals(0, len(person.names))
     self.assertEquals(0, len(citation.facts))
Exemple #17
0
 def test_sources(self) -> None:
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     self.assertCountEqual([], sut.resources)
     source = Mock(Source)
     citation_source = Mock(Source)
     citation = Citation(citation_source)
     resources = [citation, source, Mock(HasFiles)]
     sut.resources = resources
     self.assertCountEqual([citation_source, source], sut.sources)
Exemple #18
0
 def test_privatize_file_should_privatize_if_private(self):
     source = Source('The Source')
     citation = Citation(source)
     file = File('F0', __file__)
     file.private = True
     file.citations.append(citation)
     ancestry = Ancestry()
     ancestry.files[file.id] = file
     privatize(ancestry)
     self.assertTrue(True, file.private)
     self.assertTrue(citation.private)
Exemple #19
0
 def test_privatize_file_should_not_privatize_if_public(self):
     source = Source('The Source')
     citation = Citation(source)
     file = File('F0', __file__)
     file.private = False
     file.citations.append(citation)
     ancestry = Ancestry()
     ancestry.files[file.id] = file
     privatize(ancestry)
     self.assertEqual(False, file.private)
     self.assertIsNone(citation.private)
Exemple #20
0
 async def test_with_one_alternative_name(self):
     person = Person('P0')
     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><a href="#reference-1" class="citation">[1]</a></span></div>'
     async with self._render(data={
             'person': person,
     }) as (actual, _):
         self.assertEqual(expected, actual)
 async def test_embedded(self):
     event = Event(Birth())
     event.date = Date(1970)
     event.place = Place('P0', [PlaceName('The Place')])
     event.citations.append(Citation(Source('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)
 async def test_embedded(self):
     name = PersonName('Jane', 'Dough')
     source = Source()
     citation = Citation(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)
Exemple #23
0
    def test_clean_should_clean_citation(self) -> None:
        ancestry = Ancestry()

        source = Source('S0', 'The source')
        ancestry.sources[source.id] = source

        citation = Citation('C0', source)
        ancestry.citations[citation.id] = citation

        clean(ancestry)

        self.assertNotIn(citation.id, ancestry.citations)
Exemple #24
0
 def test_replace(self):
     citations = [Citation(Source())]
     contains = [Source()]
     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))
Exemple #25
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)
Exemple #26
0
 def test_source_should_encode_full(self):
     source = Source('the_source', 'The Source')
     source.author = 'The Author'
     source.publisher = 'The Publisher'
     source.date = Date(2000, 1, 1)
     source.contained_by = Source('the_containing_source',
                                  'The Containing Source')
     source.links.add(
         Link('https://example.com/the-person', 'The Person Online'))
     source.contains.append(
         Source('the_contained_source', 'The Contained Source'))
     source.citations.append(
         Citation('the_citation', Source('the_source', 'The Source')))
     expected = {
         '$schema':
         '/schema.json#/definitions/source',
         '@context': {
             'name': 'https://schema.org/name',
         },
         '@type':
         'https://schema.org/Thing',
         'id':
         'the_source',
         'name':
         'The Source',
         'author':
         'The Author',
         'publisher':
         'The Publisher',
         'contains': [
             '/source/the_contained_source/index.json',
         ],
         'citations': [
             '/citation/the_citation/index.json',
         ],
         'containedBy':
         '/source/the_containing_source/index.json',
         'date': {
             'year': 2000,
             'month': 1,
             'day': 1,
         },
         'links': [
             {
                 'url': 'https://example.com/the-person',
                 'label': 'The Person Online',
             },
         ],
     }
     self.assert_encodes(expected, source, 'source')
Exemple #27
0
    def test_clean_should_not_clean_source_with_citations(self) -> None:
        ancestry = Ancestry()

        source = Source('S0', 'The Source')
        ancestry.sources[source.id] = source

        citation = Citation('C0', source)
        citation.facts.append(PersonName('Jane'))
        ancestry.citations[citation.id] = citation

        clean(ancestry)

        self.assertEqual(source, ancestry.sources[source.id])
        self.assertEqual(source, citation.source)
        self.assertEqual(citation, ancestry.citations[citation.id])
Exemple #28
0
 def test_event_should_encode_full(self):
     event = IdentifiableEvent('the_event', Event.Type.BIRTH)
     event.date = DateRange(Date(2000, 1, 1), Date(2019, 12, 31))
     event.place = Place('the_place', [LocalizedName('The Place')])
     Presence(Person('the_person'), Presence.Role.SUBJECT, event)
     event.citations.append(
         Citation('the_citation', Source('the_source', 'The Source')))
     expected = {
         '$schema':
         '/schema.json#/definitions/event',
         '@context': {
             'place': 'https://schema.org/location',
         },
         '@type':
         'https://schema.org/Event',
         'id':
         'the_event',
         'type':
         Event.Type.BIRTH.value,
         'presences': [
             {
                 '@context': {
                     'person': 'https://schema.org/actor',
                 },
                 'role': Presence.Role.SUBJECT.value,
                 'person': '/person/the_person/index.json',
             },
         ],
         'citations': [
             '/citation/the_citation/index.json',
         ],
         'date': {
             'start': {
                 'year': 2000,
                 'month': 1,
                 'day': 1,
             },
             'end': {
                 'year': 2019,
                 'month': 12,
                 'day': 31,
             },
         },
         'place':
         '/place/the_place/index.json',
     }
     self.assert_encodes(expected, event, 'event')
Exemple #29
0
    def test_clean_should_not_clean_citation_with_files(self) -> None:
        ancestry = Ancestry()

        source = Source('S0', 'The Source')
        ancestry.sources[source.id] = source

        citation = Citation('C0', source)
        ancestry.citations[citation.id] = citation

        file = File('F0', __file__)
        file.resources.append(citation)
        ancestry.files[file.id] = file

        clean(ancestry)

        self.assertEqual(source, ancestry.sources[source.id])
        self.assertIn(source, file.sources)
        self.assertEqual(file, ancestry.files[file.id])
Exemple #30
0
    def test_clean_should_not_clean_citation_with_facts(self) -> None:
        ancestry = Ancestry()

        source = Source('S0', 'The Source')
        ancestry.sources[source.id] = source

        citation = Citation('C0', source)
        citation.facts.append(PersonName('Jane'))
        ancestry.citations[citation.id] = citation

        fact = Person('P0')
        fact.citations.append(citation)
        ancestry.people[fact.id] = fact

        clean(ancestry)

        self.assertEqual(citation, ancestry.citations[citation.id])
        self.assertIn(citation, fact.citations)
        self.assertEqual(fact, ancestry.people[fact.id])