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)
def test_citations(self) -> None: encloses = Mock(Place) enclosed_by = Mock(Place) sut = Enclosure(encloses, enclosed_by) citation = Mock(Citation) self.assertIsNone(sut.date) sut.citations = [citation] self.assertCountEqual([citation], sut.citations)
def test_date(self) -> None: encloses = Mock(Place) enclosed_by = Mock(Place) sut = Enclosure(encloses, enclosed_by) date = Date() self.assertIsNone(sut.date) sut.date = date self.assertEquals(date, sut.date)
async def test_with_enclosing_place_without_place_context(self): place = Place('P0', [PlaceName('The Place')]) enclosing_place = Place('P1', [PlaceName('The Enclosing Place')]) Enclosure(place, enclosing_place) all_enclosing_place = Place('P2', [PlaceName('The All-enclosing Place')]) Enclosure(enclosing_place, all_enclosing_place) expected = '<div class="meta">in <address><a href="/place/P1/index.html"><span>The Enclosing Place</span></a></address>, <address><a href="/place/P2/index.html"><span>The All-enclosing Place</span></a></address></div>' async with self._render(data={ 'place': place, }) as (actual, _): self.assertEqual(expected, actual)
def _load_place(loader: _Loader, element: ElementTree.Element) -> None: place_handle = element.get('handle') names = [] for name_element in _xpath(element, './ns:pname'): # The Gramps language is a single ISO language code, which is a valid BCP 47 locale. language = name_element.get('lang') date = _load_date(name_element) name = PlaceName(name_element.get('value'), locale=language, date=date) names.append(name) place = Place(element.get('id'), names) coordinates = _load_coordinates(element) if coordinates: place.coordinates = coordinates _load_urls(place, element) loader.add_entity(FlattenedEntity(place, place_handle)) for enclosed_by_handle in _load_handles('placeref', element): identifiable_enclosure = FlattenedEntity(Enclosure(None, None)) loader.add_entity(identifiable_enclosure) loader.add_association(Enclosure, identifiable_enclosure.id, 'encloses', Place, place_handle) loader.add_association(Enclosure, identifiable_enclosure.id, 'enclosed_by', Place, enclosed_by_handle)
def test_encloses(self) -> None: sut = Place('P1', [PlaceName('The Place')]) self.assertCountEqual([], sut.encloses) enclosed_place = Place('P2', [PlaceName('The Other Place')]) enclosure = Enclosure(enclosed_place, sut) self.assertIn(enclosure, sut.encloses) self.assertEquals(sut, enclosure.enclosed_by) sut.encloses.remove(enclosure) self.assertCountEqual([], sut.encloses) self.assertIsNone(enclosure.enclosed_by)
def test_enclosed_by(self) -> None: encloses = Mock(Place) enclosed_by = Mock(Place) sut = Enclosure(encloses, enclosed_by) self.assertEquals(enclosed_by, sut.enclosed_by)
async def test_place_should_encode_full(self): place_id = 'the_place' name = 'The Place' locale = 'nl-NL' latitude = 12.345 longitude = -54.321 coordinates = Point(latitude, longitude) place = Place(place_id, [PlaceName(name, locale)]) place.coordinates = coordinates Enclosure(place, Place('the_enclosing_place', [])) Enclosure(Place('the_enclosed_place', []), place) link = Link('https://example.com/the-place') link.label = 'The Place Online' place.links.add(link) place.events.append(Event('E1', Birth())) expected = { '$schema': '/schema.json#/definitions/place', '@context': { 'enclosedBy': 'https://schema.org/containedInPlace', 'encloses': 'https://schema.org/containsPlace', 'events': 'https://schema.org/event', 'coordinates': 'https://schema.org/geo', }, '@type': 'https://schema.org/Place', 'id': place_id, 'names': [ { 'name': name, 'locale': 'nl-NL', }, ], 'events': [ '/en/event/E1/index.json', ], 'links': [ { 'url': '/en/place/the_place/index.json', 'relationship': 'canonical', 'mediaType': 'application/json', }, { 'url': '/nl/place/the_place/index.json', 'relationship': 'alternate', 'locale': 'nl-NL', }, { 'url': '/en/place/the_place/index.html', 'relationship': 'alternate', 'mediaType': 'text/html', }, { 'url': 'https://example.com/the-place', 'label': 'The Place Online', }, ], 'coordinates': { '@context': { 'latitude': 'https://schema.org/latitude', 'longitude': 'https://schema.org/longitude', }, '@type': 'https://schema.org/GeoCoordinates', 'latitude': latitude, 'longitude': longitude, }, 'encloses': [ '/en/place/the_enclosed_place/index.json', ], 'enclosedBy': [ '/en/place/the_enclosing_place/index.json', ], } await self.assert_encodes(expected, place, 'place')