Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
def _load_places(loader: _Loader, database: ElementTree.Element):
    intermediate_places = {handle: intermediate_place for handle, intermediate_place in
                           [_load_place(element) for element in _xpath(database, './ns:places/ns:placeobj')]}
    for intermediate_place in intermediate_places.values():
        for enclosed_by_handle in intermediate_place.enclosed_by_handles:
            Enclosure(intermediate_place.place, intermediate_places[enclosed_by_handle].place)
    loader._places = {handle: intermediate_place.place for handle, intermediate_place in
                      intermediate_places.items()}
Example #5
0
 def test_enclosed_by_should_sync_references(self):
     sut = Place('1', [PlaceName('one')])
     enclosing_place = Place('2', [PlaceName('two')])
     enclosure = Enclosure(sut, enclosing_place)
     self.assertIn(enclosure, sut.enclosed_by)
     self.assertEquals(sut, enclosure.encloses)
     sut.enclosed_by.remove(enclosure)
     self.assertCountEqual([], sut.enclosed_by)
     self.assertIsNone(enclosure.encloses)
Example #6
0
 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)
Example #7
0
    def test_clean(self) -> None:
        ancestry = Ancestry()

        onymous_event = IdentifiableEvent('E0', Birth())
        Presence(Person('P0'), Subject(), onymous_event)
        ancestry.events[onymous_event.id] = onymous_event

        anonymous_event = IdentifiableEvent('E1', Birth())
        ancestry.events[anonymous_event.id] = anonymous_event

        onymous_place = Place('P0', [PlaceName('Amsterdam')])
        onymous_place.events.append(onymous_event)
        ancestry.places[onymous_place.id] = onymous_place

        anonymous_place = Place('P1', [PlaceName('Almelo')])
        ancestry.places[anonymous_place.id] = 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.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)
Example #8
0
def _parse_places(ancestry: _IntermediateAncestry, database: Element):
    intermediate_places = {
        handle: intermediate_place
        for handle, intermediate_place in [
            _parse_place(element)
            for element in database.xpath('.//*[local-name()="placeobj"]')
        ]
    }
    for intermediate_place in intermediate_places.values():
        for enclosed_by_handle in intermediate_place.enclosed_by_handles:
            Enclosure(intermediate_place.place,
                      intermediate_places[enclosed_by_handle].place)
    ancestry.places = {
        handle: intermediate_place.place
        for handle, intermediate_place in intermediate_places.items()
    }
Example #9
0
 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)
Example #10
0
 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(IdentifiableEvent('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',
         ],
     }
     self.assert_encodes(expected, place, 'place')