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))
def test_event_should_encode_minimal(self): event = IdentifiableEvent('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', }, ], } self.assert_encodes(expected, event, 'event')
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)
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)
async def test_with_identifiable(self): event = IdentifiableEvent('E0', Birth()) expected = '<a href="/event/E0/index.html">Birth</a>' async with self._render(data={ 'event': event, }) as (actual, _): self.assertEqual(expected, actual)
async def test_minimal(self): event = Event(Birth()) expected = 'Birth' async with self._render(data={ 'event': event, }) as (actual, _): self.assertEqual(expected, actual)
async def test_with_resource(self): event = Event(Birth()) expected = 'Birth' async with self._render(data={ 'resource': event, }) as (actual, _): self.assertEqual(expected, actual)
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))
def test_citation_should_encode_full(self): citation = IdentifiableCitation( 'the_citation', IdentifiableSource('the_source', 'The Source')) citation.description = 'The Source Description' citation.facts.append(IdentifiableEvent('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', }, ], } self.assert_encodes(expected, citation, 'citation')
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)
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)
def test_clean_should_not_clean_event_with_presences_with_people( self) -> None: ancestry = Ancestry() source = IdentifiableSource('S1', 'The Source') ancestry.sources[source.id] = source citation = IdentifiableCitation('C1', source) ancestry.citations[citation.id] = citation file = File('F1', __file__) ancestry.files[file.id] = file place = Place('P0', [PlaceName('The Place')]) ancestry.places[place.id] = place person = Person('P0') event = IdentifiableEvent('E0', Birth()) event.citations.append(citation) event.files.append(file) event.place = place ancestry.events[event.id] = event Presence(person, 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])
def test_clean_should_clean_event(self) -> None: ancestry = Ancestry() source = IdentifiableSource('S1', 'The Source') ancestry.sources[source.id] = source citation = IdentifiableCitation('C1', source) ancestry.citations[citation.id] = citation file = File('F1', __file__) ancestry.files[file.id] = file place = Place('P0', [PlaceName('The Place')]) ancestry.places[place.id] = place event = IdentifiableEvent('E0', 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)
def test_event_should_encode_full(self): event = IdentifiableEvent('the_event', Birth()) event.date = DateRange(Date(2000, 1, 1), Date(2019, 12, 31)) event.place = Place('the_place', [PlaceName('The Place')]) Presence(Person('the_person'), Subject(), event) event.citations.append( IdentifiableCitation('the_citation', Source('The Source'))) expected = { '$schema': '/schema.json#/definitions/event', '@context': { 'place': 'https://schema.org/location', }, '@type': 'https://schema.org/Event', 'id': 'the_event', 'type': 'birth', 'presences': [ { '@context': { 'person': 'https://schema.org/actor', }, 'role': 'subject', 'person': '/en/person/the_person/index.json', }, ], 'citations': [ '/en/citation/the_citation/index.json', ], 'date': { 'start': { 'year': 2000, 'month': 1, 'day': 1, }, 'end': { 'year': 2019, 'month': 12, 'day': 31, }, }, 'place': '/en/place/the_place/index.json', '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', }, ], } self.assert_encodes(expected, event, 'event')
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)
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)
def test_with_private_event_should_anonymize(self, m_anonymize_event) -> None: event = IdentifiableEvent('E0', Birth()) event.private = True ancestry = Ancestry() ancestry.events[event.id] = event anonymize(ancestry) m_anonymize_event.assert_called_once_with(event)
async def test_with_start(self): person = Person('P0') Presence(person, Subject(), Event(Birth(), Date(1970))) expected = '<div class="meta"><dl><dt>Birth</dt><dd>1970</dd></dl></div>' async with self._render(data={ 'person': person, }) as (actual, _): self.assertEqual(expected, actual)
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)
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)
def test_with_public_event_should_not_anonymize(self, m_anonymize_event) -> None: event = IdentifiableEvent('E0', Birth()) event.private = False ancestry = Ancestry() ancestry.events[event.id] = event anonymize(ancestry) m_anonymize_event.assert_not_called()
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)
def test_place_should_sync_references(self): place = Place('1', [PlaceName('one')]) sut = IdentifiableEvent('1', 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)
async def test_embedded_with_identifiable(self): event = IdentifiableEvent('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)
def test_events(self) -> None: sut = Place('P1', [PlaceName('The Place')]) event = IdentifiableEvent('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)
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)
def test_events_should_sync_references(self): sut = Place('1', [PlaceName('one')]) event = IdentifiableEvent('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)
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)
def test_presence_should_sync_references(self): person = Person('P1') sut = IdentifiableEvent('1', Birth()) 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)
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)