Exemplo n.º 1
0
 def test_enclosed_by_should_sync_references(self):
     sut = Place('1', [LocalizedName('one')])
     enclosing_place = Place('2', [LocalizedName('two')])
     sut.enclosed_by = enclosing_place
     self.assertEquals(enclosing_place, sut.enclosed_by)
     self.assertIn(sut, enclosing_place.encloses)
     sut.enclosed_by = None
     self.assertIsNone(sut.enclosed_by)
     self.assertCountEqual([], enclosing_place.encloses)
Exemplo n.º 2
0
 def test_encloses_should_sync_references(self):
     sut = Place('1', [LocalizedName('one')])
     enclosed_place = Place('2', [LocalizedName('two')])
     sut.encloses.append(enclosed_place)
     self.assertIn(enclosed_place, sut.encloses)
     self.assertEquals(sut, enclosed_place.enclosed_by)
     sut.encloses.remove(enclosed_place)
     self.assertCountEqual([], sut.encloses)
     self.assertEquals(None, enclosed_place.enclosed_by)
Exemplo n.º 3
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)
Exemplo n.º 4
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])
Exemplo n.º 5
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, [LocalizedName(name, locale)])
     place.coordinates = coordinates
     place.enclosed_by = Place('the_enclosing_place', [])
     place.encloses.append(Place('the_enclosed_place', []))
     place.links.add(
         Link('https://example.com/the-place', 'The Place Online'))
     place.events.append(IdentifiableEvent('E1', Event.Type.BIRTH))
     expected = {
         '$schema':
         '/schema.json#/definitions/place',
         '@context': {
             'encloses': 'https://schema.org/containsPlace',
             'events': 'https://schema.org/event',
             'enclosedBy': 'https://schema.org/containedInPlace',
             'coordinates': 'https://schema.org/geo',
         },
         '@type':
         'https://schema.org/Place',
         'id':
         place_id,
         'names': [
             {
                 'name': name,
                 'locale': 'nl-NL',
             },
         ],
         'events': [
             '/event/E1/index.json',
         ],
         'links': [
             {
                 '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': [
             '/place/the_enclosed_place/index.json',
         ],
         'enclosedBy':
         '/place/the_enclosing_place/index.json',
     }
     self.assert_encodes(expected, place, 'place')
Exemplo n.º 6
0
 def test_events_should_sync_references(self):
     sut = Place('1', [LocalizedName('one')])
     event = IdentifiableEvent('1', Event.Type.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)
Exemplo n.º 7
0
 def test_place_should_sync_references(self):
     place = Place('1', [LocalizedName('one')])
     sut = IdentifiableEvent('1', Event.Type.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)
Exemplo n.º 8
0
    def test_place(self, expected: str, locale: str):
        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(output_directory_path,
                                          'https://example.com')
            configuration.locales['en-US'] = LocaleConfiguration('en-US', 'en')
            configuration.locales['nl-NL'] = LocaleConfiguration('nl-NL', 'nl')
            site = Site(configuration)
            environment = create_environment(site, locale)
            place_id = 'P1'
            place = Place(place_id, [
                LocalizedName('Netherlands', 'en'),
                LocalizedName('Nederland', 'nl')
            ])
            site.ancestry.places[place_id] = place

            indexed = list(index(site, environment))

            self.assertEquals('netherlands nederland', indexed[0]['text'])
            self.assertIn(expected, indexed[0]['result'])
Exemplo n.º 9
0
    def test_clean(self) -> None:
        ancestry = Ancestry()

        onymous_event = IdentifiableEvent('E0', Event.Type.BIRTH)
        Presence(Person('P0'), Presence.Role.SUBJECT, onymous_event)
        ancestry.events[onymous_event.id] = onymous_event

        anonymous_event = IdentifiableEvent('E1', Event.Type.BIRTH)
        ancestry.events[anonymous_event.id] = anonymous_event

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

        anonymous_place = Place('P1', [LocalizedName('Almelo')])
        ancestry.places[anonymous_place.id] = anonymous_place

        onmyous_place_because_encloses_onmyous_places = Place(
            'P3', [LocalizedName('Netherlands')])
        onmyous_place_because_encloses_onmyous_places.encloses.append(
            onymous_place)
        onmyous_place_because_encloses_onmyous_places.encloses.append(
            anonymous_place)
        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)
Exemplo n.º 10
0
class LocalizedNameTest(TestCase):
    @parameterized.expand([
        (True, LocalizedName('Ikke'), LocalizedName('Ikke')),
        (True, LocalizedName('Ikke', 'nl-NL'), LocalizedName('Ikke', 'nl-NL')),
        (False, LocalizedName('Ikke', 'nl-NL'), LocalizedName('Ikke', 'nl-BE')),
        (False, LocalizedName('Ikke', 'nl-NL'), LocalizedName('Ik', 'nl-NL')),
        (False, LocalizedName('Ikke'), LocalizedName('Ik')),
    ])
    def test_eq(self, expected, a, b):
        self.assertEquals(expected, a == b)

    def test_str(self):
        name = 'Ikke'
        sut = LocalizedName(name)
        self.assertEquals(name, str(sut))

    def test_name(self):
        name = 'Ikke'
        sut = LocalizedName(name)
        self.assertEquals(name, sut.name)
Exemplo n.º 11
0
 def test(self):
     with TemporaryDirectory() as www_directory_path:
         configuration = Configuration(www_directory_path,
                                       'https://example.com')
         environment = create_environment(Site(configuration))
         template = '{{ data | sort_localizeds(localized_attribute="names", sort_attribute="name") }}'
         data = [
             self.WithLocalizedNames('third', [
                 LocalizedName('3', 'nl-NL'),
             ]),
             self.WithLocalizedNames('second', [
                 LocalizedName('2', 'en'),
                 LocalizedName('1', 'nl-NL'),
             ]),
             self.WithLocalizedNames('first', [
                 LocalizedName('2', 'nl-NL'),
                 LocalizedName('1', 'en-US'),
             ]),
         ]
         self.assertEquals(
             '[first, second, third]',
             environment.from_string(template).render(data=data))
Exemplo n.º 12
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')
Exemplo n.º 13
0
class SiteUrlGeneratorTest(TestCase):
    @parameterized.expand([
        ('/index.html', '/index.html'),
        ('/person/P1/index.html', Person('P1')),
        ('/event/E1/index.html', IdentifiableEvent('E1', Event.Type.DEATH)),
        ('/place/P1/index.html', Place('P1', [LocalizedName('Place 1')])),
        ('/file/F1/index.html', File('F1', '/tmp')),
        ('/source/S1/index.html', Source('S1', 'Source 1')),
        ('/citation/C1/index.html', Citation('C1', Source('S1', 'Source 1'))),
    ])
    def test_generate(self, expected: str, resource: Any):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = SiteUrlGenerator(configuration)
        self.assertEquals(expected, sut.generate(resource, 'text/html'))

    def test_generate_with_invalid_value(self):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = SiteUrlGenerator(configuration)
        with self.assertRaises(ValueError):
            sut.generate(9, 'text/html')
Exemplo n.º 14
0
def _parse_place(element: Element) -> Tuple[str, _IntermediatePlace]:
    handle = _xpath1(element, './@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 = _xpath1(name_element, './@lang')
        names.append(
            LocalizedName(str(_xpath1(name_element, './@value')), language))

    place = Place(_xpath1(element, './@id'), names)

    coordinates = _parse_coordinates(element)
    if coordinates:
        place.coordinates = coordinates

    # Set the first place reference as the place that encloses this place.
    enclosed_by_handle = _xpath1(element, './ns:placeref/@hlink')

    _parse_urls(place, element)

    return handle, _IntermediatePlace(place, enclosed_by_handle)
Exemplo n.º 15
0
 def test_place_should_encode_minimal(self):
     place_id = 'the_place'
     name = 'The Place'
     place = Place(place_id, [LocalizedName(name)])
     expected = {
         '$schema': '/schema.json#/definitions/place',
         '@context': {
             'encloses': 'https://schema.org/containsPlace',
             'events': 'https://schema.org/event'
         },
         '@type': 'https://schema.org/Place',
         'id': place_id,
         'names': [
             {
                 'name': name,
             },
         ],
         'encloses': [],
         'events': [],
         'links': [],
     }
     self.assert_encodes(expected, place, 'place')
Exemplo n.º 16
0
 def test_name(self):
     name = 'Ikke'
     sut = LocalizedName(name)
     self.assertEquals(name, sut.name)
Exemplo n.º 17
0
 def test_str(self):
     name = 'Ikke'
     sut = LocalizedName(name)
     self.assertEquals(name, str(sut))