Example #1
0
    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)
Example #2
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 #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 test_clean_should_clean_event(self) -> None:
        ancestry = Ancestry()

        source = Source('S1', 'The Source')
        ancestry.entities.append(source)

        citation = Citation('C1', source)
        ancestry.entities.append(citation)

        file = File('F1', __file__)
        ancestry.entities.append(file)

        place = Place('P0', [PlaceName('The Place')])
        ancestry.entities.append(place)

        event = Event('E0', Birth())
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.entities.append(event)

        clean(ancestry)

        self.assertNotIn(event.id, ancestry.entities[Event])
        self.assertIsNone(event.place)
        self.assertNotIn(event, place.events)
        self.assertNotIn(place.id, ancestry.entities[Place])
        self.assertNotIn(event, citation.facts)
        self.assertNotIn(citation.id, ancestry.entities[Citation])
        self.assertNotIn(event, file.entities)
        self.assertNotIn(file.id, ancestry.entities[File])
Example #5
0
    def test_clean_should_not_clean_event_with_presences_with_people(
            self) -> None:
        ancestry = Ancestry()

        source = Source('S1', 'The Source')
        ancestry.entities.append(source)

        citation = Citation('C1', source)
        ancestry.entities.append(citation)

        file = File('F1', __file__)
        ancestry.entities.append(file)

        place = Place('P0', [PlaceName('The Place')])
        ancestry.entities.append(place)

        person = Person('P0')

        event = Event('E0', Birth())
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.entities.append(event)

        Presence(person, Subject(), event)

        clean(ancestry)

        self.assertEqual(event, ancestry.entities[Event][event.id])
        self.assertIn(event, place.events)
        self.assertEqual(place, ancestry.entities[Place][place.id])
        self.assertIn(event, citation.facts)
        self.assertEqual(citation, ancestry.entities[Citation][citation.id])
        self.assertIn(event, file.entities)
        self.assertEqual(file, ancestry.entities[File][file.id])
Example #6
0
 async def test_without_enclosing_places(self):
     place = Place('P0', [PlaceName('The Place')])
     expected = '<div class="meta"></div>'
     async with self._render(data={
             'place': place,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Example #7
0
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)
Example #8
0
 async def test_with_place(self):
     event = Event(None, 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)
Example #9
0
class TestResourceTest(TemplateTestCase):
    @parameterized.expand([
        ('true', Person, Person('P1')),
        ('false', Person, Place('P1', [PlaceName('The Place')])),
        ('true', Place, Place('P1', [PlaceName('The Place')])),
        ('false', Place, Person('P1')),
        ('false', Place, 999),
        ('false', Person, object()),
    ])
    @sync
    async def test(self, expected, entity_type: Type[Entity], data) -> None:
        template = f'{{% if data is {camel_case_to_snake_case(get_entity_type_name(entity_type))}_entity %}}true{{% else %}}false{{% endif %}}'
        async with self._render(template_string=template,
                                data={
                                    'data': data,
                                }) as (actual, _):
            self.assertEquals(expected, actual)
Example #10
0
class FilterSelectLocalizedsTest(TemplateTestCase):
    @parameterized.expand([
        ('', 'en', []),
        ('Apple', 'en', [PlaceName('Apple', 'en')]),
        ('Apple', 'en', [PlaceName('Apple', 'en-US')]),
        ('Apple', 'en-US', [PlaceName('Apple', 'en')]),
        ('', 'nl', [PlaceName('Apple', 'en')]),
        ('', 'nl-NL', [PlaceName('Apple', 'en')]),
    ])
    @sync
    async def test(self, expected: str, locale: str,
                   data: Iterable[Localized]):
        template = '{{ data | select_localizeds | map(attribute="name") | join(", ") }}'

        def _update_configuration(configuration: Configuration) -> None:
            configuration.locales.replace([LocaleConfiguration(locale)])

        async with self._render(
                template_string=template,
                data={
                    'data': data,
                },
                update_configuration=_update_configuration) as (actual, _):
            self.assertEquals(expected, actual)

    @sync
    async def test_include_unspecified(self):
        template = '{{ data | select_localizeds(include_unspecified=true) | map(attribute="name") | join(", ") }}'
        data = [
            PlaceName('Apple', 'zxx'),
            PlaceName('Apple', 'und'),
            PlaceName('Apple', 'mul'),
            PlaceName('Apple', 'mis'),
            PlaceName('Apple', None),
        ]

        def _update_configuration(configuration: Configuration) -> None:
            configuration.locales.replace([LocaleConfiguration('en-US')])

        async with self._render(
                template_string=template,
                data={
                    'data': data,
                },
                update_configuration=_update_configuration) as (actual, _):
            self.assertEquals('Apple, Apple, Apple, Apple, Apple', actual)
Example #11
0
 def test_place(self) -> None:
     place = Place('1', [PlaceName('one')])
     sut = Event(None, Mock(EventType))
     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)
Example #12
0
 def test_events(self) -> None:
     sut = Place('P1', [PlaceName('The Place')])
     event = Event('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)
Example #13
0
 async def test_with_place_is_place_context(self):
     event = Event(None, Birth())
     place = Place('P0', [PlaceName('The Place')])
     event.place = place
     expected = ''
     async with self._render(data={
             'event': event,
             'place_context': place,
     }) as (actual, _):
         self.assertEqual(expected, actual)
Example #14
0
 async def test_place(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     async with app:
         place = Place('PLACE1', [PlaceName('one')])
         app.ancestry.entities.append(place)
         await generate(app)
     self.assert_betty_html(app, '/place/%s/index.html' % place.id)
     self.assert_betty_json(app, '/place/%s/index.json' % place.id, 'place')
Example #15
0
 async def test(self):
     template = '{{ data | sort_localizeds(localized_attribute="names", sort_attribute="name") }}'
     data = [
         self.WithLocalizedNames('third', [
             PlaceName('3', 'nl-NL'),
         ]),
         self.WithLocalizedNames('second', [
             PlaceName('2', 'en'),
             PlaceName('1', 'nl-NL'),
         ]),
         self.WithLocalizedNames('first', [
             PlaceName('2', 'nl-NL'),
             PlaceName('1', 'en-US'),
         ]),
     ]
     async with self._render(template_string=template,
                             data={
                                 'data': data,
                             }) as (actual, _):
         self.assertEquals('[first, second, third]', actual)
Example #16
0
 async def test_embedded(self):
     event = Event(None, Birth())
     event.date = Date(1970)
     event.place = Place('P0', [PlaceName('The Place')])
     event.citations.append(Citation(None, Source(None, '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)
Example #17
0
    async def test_place(self, expected: str, locale: str):
        place_id = 'P1'
        place = Place(
            place_id,
            [PlaceName('Netherlands', 'en'),
             PlaceName('Nederland', 'nl')])

        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(output_directory_path,
                                          'https://example.com')
            configuration.locales.replace([
                LocaleConfiguration('en-US', 'en'),
                LocaleConfiguration('nl-NL', 'nl'),
            ])
            async with App(configuration).with_locale(locale) as app:
                app.ancestry.entities.append(place)
                indexed = [item for item in Index(app).build()]

        self.assertEquals('netherlands nederland', indexed[0]['text'])
        self.assertIn(expected, indexed[0]['result'])
Example #18
0
    async def test_include_unspecified(self):
        template = '{{ data | select_localizeds(include_unspecified=true) | map(attribute="name") | join(", ") }}'
        data = [
            PlaceName('Apple', 'zxx'),
            PlaceName('Apple', 'und'),
            PlaceName('Apple', 'mul'),
            PlaceName('Apple', 'mis'),
            PlaceName('Apple', None),
        ]

        def _update_configuration(configuration: Configuration) -> None:
            configuration.locales.replace([LocaleConfiguration('en-US')])

        async with self._render(
                template_string=template,
                data={
                    'data': data,
                },
                update_configuration=_update_configuration) as (actual, _):
            self.assertEquals('Apple, Apple, Apple, Apple, Apple', actual)
Example #19
0
class Test(TemplateTestCase):
    template_file = 'label/place.html.j2'

    @parameterized.expand([
        ('<address><a href="/place/P0/index.html"><span>The Place</span></a></address>',
         {
             'place': Place('P0', [PlaceName('The Place')]),
         }),
        ('<address><a href="/place/P0/index.html"><span lang="en">The Place</span></a></address>',
         {
             'place': Place('P0', [PlaceName('The Place', 'en')]),
         }),
        ('<address><a href="/place/P0/index.html"><span lang="nl">De Plaats</span></a></address>',
         {
             'place':
             Place(
                 'P0',
                 [PlaceName('The Place', 'en'),
                  PlaceName('De Plaats', 'nl')]),
             'locale':
             'nl',
         }),
        ('<address><span>The Place</span></address>', {
            'place': Place('P0', [PlaceName('The Place')]),
            'embedded': True,
        }),
        ('<address><a href="/place/P0/index.html"><span lang="nl">De Nieuwe Plaats</span></a></address>',
         {
             'place':
             Place('P0', [
                 PlaceName('The Old Place',
                           'en',
                           date=DateRange(None, Date(1969, 12, 31))),
                 PlaceName('De Nieuwe Plaats',
                           'nl',
                           date=DateRange(Date(1970, 1, 1)))
             ]),
             'locale':
             'nl',
             'date_context':
             Date(1970, 1, 1),
         })
    ])
    @sync
    async def test(self, expected, data):
        async with self._render(data=data) as (actual, _):
            self.assertEqual(expected, actual)
Example #20
0
 async def test_place_should_encode_minimal(self):
     place_id = 'the_place'
     name = 'The Place'
     place = Place(place_id, [PlaceName(name)])
     expected = {
         '$schema':
         '/schema.json#/definitions/place',
         '@context': {
             'enclosedBy': 'https://schema.org/containedInPlace',
             'encloses': 'https://schema.org/containsPlace',
             'events': 'https://schema.org/event'
         },
         '@type':
         'https://schema.org/Place',
         'id':
         place_id,
         'names': [
             {
                 'name': name,
             },
         ],
         'enclosedBy': [],
         'encloses': [],
         'events': [],
         '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',
             },
         ],
     }
     await self.assert_encodes(expected, place, 'place')
Example #21
0
class AppUrlGeneratorTest(TestCase):
    @parameterized.expand([
        ('/index.html', '/index.html'),
        ('/person/P1/index.html', Person('P1')),
        ('/event/E1/index.html', Event('E1', Death())),
        ('/place/P1/index.html', Place('P1', [PlaceName('Place 1')])),
        ('/file/F1/index.html', File('F1', '/tmp')),
        ('/source/S1/index.html', Source('S1', 'Source 1')),
        ('/citation/C1/index.html', Citation('C1', Source('Source 1'))),
    ])
    def test_generate(self, expected: str, resource: Any):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = AppUrlGenerator(configuration)
        self.assertEquals(expected, sut.generate(resource, 'text/html'))

    def test_generate_with_invalid_value(self):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = AppUrlGenerator(configuration)
        with self.assertRaises(ValueError):
            sut.generate(9, 'text/html')
Example #22
0
 def test_names(self) -> None:
     name = PlaceName('The Place')
     sut = Place('P1', [name])
     self.assertCountEqual([name], sut.names)
Example #23
0
 def test_coordinates(self) -> None:
     name = PlaceName('The Place')
     sut = Place('P1', [name])
     coordinates = Point()
     sut.coordinates = coordinates
     self.assertEquals(coordinates, sut.coordinates)
Example #24
0
 def test_id(self) -> None:
     place_id = 'C1'
     sut = Place(place_id, [PlaceName('one')])
     self.assertEquals(place_id, sut.id)
Example #25
0
 def test_links(self) -> None:
     sut = Place('P1', [PlaceName('The Place')])
     self.assertCountEqual([], sut.links)
Example #26
0
class PlaceNameTest(TestCase):
    @parameterized.expand([
        (True, PlaceName('Ikke'), PlaceName('Ikke')),
        (True, PlaceName('Ikke', 'nl-NL'), PlaceName('Ikke', 'nl-NL')),
        (False, PlaceName('Ikke', 'nl-NL'), PlaceName('Ikke', 'nl-BE')),
        (False, PlaceName('Ikke', 'nl-NL'), PlaceName('Ik', 'nl-NL')),
        (False, PlaceName('Ikke'), PlaceName('Ik')),
        (False, PlaceName('Ikke'), None),
        (False, PlaceName('Ikke'), 'not-a-place-name'),
    ])
    def test_eq(self, expected, a, b) -> None:
        self.assertEquals(expected, a == b)

    def test_str(self) -> None:
        name = 'Ikke'
        sut = PlaceName(name)
        self.assertEquals(name, str(sut))

    def test_name(self) -> None:
        name = 'Ikke'
        sut = PlaceName(name)
        self.assertEquals(name, sut.name)

    def test_locale(self) -> None:
        locale = 'nl-NL'
        sut = PlaceName('Ikke', locale=locale)
        self.assertEquals(locale, sut.locale)

    def test_date(self) -> None:
        date = Date()
        sut = PlaceName('Ikke', date=date)
        self.assertEquals(date, sut.date)
Example #27
0
 def test_str(self) -> None:
     name = 'Ikke'
     sut = PlaceName(name)
     self.assertEquals(name, str(sut))
Example #28
0
 def test_date(self) -> None:
     date = Date()
     sut = PlaceName('Ikke', date=date)
     self.assertEquals(date, sut.date)
Example #29
0
 def test_locale(self) -> None:
     locale = 'nl-NL'
     sut = PlaceName('Ikke', locale=locale)
     self.assertEquals(locale, sut.locale)
Example #30
0
 def test_name(self) -> None:
     name = 'Ikke'
     sut = PlaceName(name)
     self.assertEquals(name, sut.name)