Ejemplo n.º 1
0
 async def test(self):
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path, 'https://ancestry.example.com')
         configuration.extensions[ReDoc] = None
         async with App(configuration) as app:
             await generate(app)
         self.assertTrue(path.isfile(path.join(output_directory_path, 'www', 'api', 'index.html')))
         self.assertTrue(path.isfile(path.join(output_directory_path, 'www', 'redoc.js')))
Ejemplo n.º 2
0
 async def test_places(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     async with app:
         await generate(app)
     self.assert_betty_html(app, '/place/index.html')
     self.assert_betty_json(app, '/place/index.json', 'placeCollection')
Ejemplo n.º 3
0
 async def test_load_gpkg(self):
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         async with App(configuration) as app:
             gramps_file_path = Path(
                 __file__).parent / 'assets' / 'minimal.gpkg'
             load_gpkg(app.ancestry, gramps_file_path)
Ejemplo n.º 4
0
 async def start(self) -> None:
     self._output_directory = TemporaryDirectory()
     self._configuration.output_directory_path = self._output_directory.name
     app = App(self._configuration)
     async with app:
         await generate.generate(app)
     self._server = DockerizedNginxServer(app)
     await self._server.start()
Ejemplo n.º 5
0
 async def test_extensions_removal_from_configuration(self) -> None:
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     configuration.extensions.add(
         ExtensionConfiguration(NonConfigurableExtension))
     async with App(configuration) as sut:
         # Get the extensions before making configuration changes to warm the cache.
         sut.extensions
         del configuration.extensions[NonConfigurableExtension]
         self.assertNotIn(NonConfigurableExtension, sut.extensions)
Ejemplo n.º 6
0
 async def load(self, xml: str) -> Ancestry:
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         async with App(configuration) as app:
             with TemporaryDirectory() as tree_directory_path:
                 load_xml(app.ancestry, xml.strip(),
                          Path(tree_directory_path))
                 return app.ancestry
Ejemplo n.º 7
0
 async def test_extensions_addition_to_configuration(self) -> None:
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     async with App(configuration) as sut:
         # Get the extensions before making configuration changes to warm the cache.
         sut.extensions
         configuration.extensions.add(
             ExtensionConfiguration(NonConfigurableExtension))
         self.assertIsInstance(sut.extensions[NonConfigurableExtension],
                               NonConfigurableExtension)
Ejemplo n.º 8
0
 async def test_with_comes_after_without_other_extension(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     configuration.extensions[ComesAfterNonConfigurableExtensionExtension] = None
     async with App(configuration) as sut:
         carrier = []
         await sut.dispatcher.dispatch(Tracker, 'track')(carrier)
         self.assertEquals(1, len(carrier))
         self.assertEquals(ComesAfterNonConfigurableExtensionExtension,
                           type(carrier[0]))
Ejemplo n.º 9
0
    def __init__(self, configuration_file_path: str, *args, **kwargs):
        with open(configuration_file_path) as f:
            self._configuration = from_file(f)
        self._configuration.react.react_weakref(self._save_configuration)
        self._app = App(self._configuration)
        self._configuration_file_path = configuration_file_path

        super().__init__(*args, **kwargs)

        self._set_window_title()
        self.init()

        central_widget = QWidget()
        central_layout = QGridLayout()
        central_widget.setLayout(central_layout)
        self.setCentralWidget(central_widget)

        pane_selectors_layout = QVBoxLayout()
        central_layout.addLayout(pane_selectors_layout, 0, 0,
                                 Qt.AlignTop | Qt.AlignLeft)

        panes_layout = QStackedLayout()
        central_layout.addLayout(panes_layout, 0, 1,
                                 Qt.AlignTop | Qt.AlignRight)

        self._general_configuration_pane = _ProjectGeneralConfigurationPane(
            self._app)
        panes_layout.addWidget(self._general_configuration_pane)
        pane_selectors_layout.addWidget(
            _PaneButton(pane_selectors_layout, panes_layout,
                        self._general_configuration_pane, 'General', self))

        self._theme_configuration_pane = _ProjectThemeConfigurationPane(
            self._app)
        panes_layout.addWidget(self._theme_configuration_pane)
        pane_selectors_layout.addWidget(
            _PaneButton(pane_selectors_layout, panes_layout,
                        self._theme_configuration_pane, 'Theme', self))

        self._localization_configuration_pane = _ProjectLocalizationConfigurationPane(
            self._app)
        panes_layout.addWidget(self._localization_configuration_pane)
        pane_selectors_layout.addWidget(
            _PaneButton(pane_selectors_layout, panes_layout,
                        self._localization_configuration_pane, 'Localization',
                        self))

        for extension_type in discover_extension_types():
            if issubclass(extension_type, GuiBuilder):
                extension_pane = _ProjectExtensionConfigurationPane(
                    self._app, extension_type)
                panes_layout.addWidget(extension_pane)
                pane_selectors_layout.addWidget(
                    _PaneButton(pane_selectors_layout,
                                panes_layout, extension_pane,
                                extension_type.gui_name(), self))
Ejemplo n.º 10
0
 async def _assert_configuration_equals(self, expected: str,
                                        configuration: Configuration):
     async with App(configuration) as app:
         await generate(app)
     with open(
             join(configuration.output_directory_path, 'nginx',
                  'nginx.conf')) as f:
         actual = f.read()
     self.assertEqual(self._normalize_configuration(expected),
                      self._normalize_configuration(actual))
Ejemplo n.º 11
0
 async def test_post_parse(self) -> None:
     event = Event('E0', Birth())
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.extensions.add(ExtensionConfiguration(Cleaner))
         async with App(configuration) as app:
             app.ancestry.entities.append(event)
             await load(app)
             self.assertEquals([], list(app.ancestry.entities[Event]))
Ejemplo n.º 12
0
    async def test_empty(self):
        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')
            async with App(configuration) as app:
                indexed = [item for item in Index(app).build()]

        self.assertEquals([], indexed)
Ejemplo n.º 13
0
 async def test_post_parse(self) -> None:
     event = IdentifiableEvent('E0', Birth())
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.extensions[Cleaner] = None
         async with App(configuration) as app:
             app.ancestry.events[event.id] = event
             await load(app)
             self.assertEquals({}, app.ancestry.events)
Ejemplo n.º 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')
Ejemplo n.º 15
0
 async def test_event(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     async with app:
         event = Event('EVENT1', Birth())
         app.ancestry.entities.append(event)
         await generate(app)
     self.assert_betty_html(app, '/event/%s/index.html' % event.id)
     self.assert_betty_json(app, '/event/%s/index.json' % event.id, 'event')
Ejemplo n.º 16
0
 async def test_load_xml_with_string(self):
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         async with App(configuration) as app:
             gramps_file_path = Path(
                 __file__).parent / 'assets' / 'minimal.xml'
             with open(gramps_file_path) as f:
                 load_xml(app.ancestry, f.read(),
                          rootname(gramps_file_path))
Ejemplo n.º 17
0
 async def setUpClass(cls) -> None:
     TestCase.setUpClass()
     # @todo Convert each test method to use self._load(), so we can remove this shared XML file.
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         async with App(configuration) as app:
             cls.ancestry = app.ancestry
             xml_file_path = Path(__file__).parent / 'assets' / 'data.xml'
             with open(xml_file_path) as f:
                 load_xml(app.ancestry, f.read(), rootname(xml_file_path))
Ejemplo n.º 18
0
 async def test_source(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     source = Source('SOURCE1', 'A Little Birdie')
     app.ancestry.entities.append(source)
     async with app:
         await generate(app)
     self.assert_betty_html(app, '/source/%s/index.html' % source.id)
     self.assert_betty_json(app, '/source/%s/index.json' % source.id,
                            'source')
Ejemplo n.º 19
0
 async def test_with_one_configurable_extension(self):
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     check = 1337
     configuration.extensions[ConfigurableExtension] = {
         'check': check,
     }
     async with App(configuration) as sut:
         self.assertEquals(1, len(sut.extensions))
         self.assertIsInstance(
             sut.extensions[ConfigurableExtension], ConfigurableExtension)
         self.assertEquals(check, sut.extensions[ConfigurableExtension].check)
Ejemplo n.º 20
0
async def test_generate_window_close_button_should_close_window(assert_not_window, navigate, qtbot, tmpdir) -> None:
    configuration = Configuration(tmpdir, 'https://example.com')
    async with App(configuration) as app:
        sut = _GenerateWindow(app)
        qtbot.addWidget(sut)

        with qtbot.waitSignal(sut._thread.finished):
            sut.show()

        qtbot.mouseClick(sut._close_button, QtCore.Qt.LeftButton)
        assert_not_window(_GenerateWindow)
Ejemplo n.º 21
0
 async def test_person(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     async with app:
         person = Person('PERSON1')
         app.ancestry.entities.append(person)
         await generate(app)
     self.assert_betty_html(app, '/person/%s/index.html' % person.id)
     self.assert_betty_json(app, '/person/%s/index.json' % person.id,
                            'person')
Ejemplo n.º 22
0
 async def test_load(self):
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path, 'https://example.com')
         configuration.extensions.add(ExtensionConfiguration(Demo))
         async with App(configuration) as app:
             await load(app)
         self.assertNotEqual(0, len(app.ancestry.entities[Person]))
         self.assertNotEqual(0, len(app.ancestry.entities[Place]))
         self.assertNotEqual(0, len(app.ancestry.entities[Event]))
         self.assertNotEqual(0, len(app.ancestry.entities[Source]))
         self.assertNotEqual(0, len(app.ancestry.entities[Citation]))
Ejemplo n.º 23
0
 async def test_citation(self):
     configuration = Configuration(self._output_directory.name,
                                   'https://ancestry.example.com')
     app = App(configuration)
     citation = Citation('CITATION1', Source('A Little Birdie'))
     app.ancestry.entities.append(citation)
     async with app:
         await generate(app)
     self.assert_betty_html(app, '/citation/%s/index.html' % citation.id)
     self.assert_betty_json(app, '/citation/%s/index.json' % citation.id,
                            'citation')
Ejemplo n.º 24
0
 async def test_extensions_with_comes_before_without_other_extension(
         self) -> None:
     configuration = Configuration(**self._MINIMAL_CONFIGURATION_ARGS)
     configuration.extensions.add(
         ExtensionConfiguration(
             ComesBeforeNonConfigurableExtensionExtension))
     async with App(configuration) as sut:
         carrier = []
         await sut.dispatcher.dispatch(Tracker, 'track')(carrier)
         self.assertEquals(1, len(carrier))
         self.assertEquals(ComesBeforeNonConfigurableExtensionExtension,
                           type(carrier[0]))
Ejemplo n.º 25
0
 async def test(self, content_negotiation: str):
     with open(
             path.join(path.dirname(__file__), 'test_openapi_assets',
                       'schema.json')) as f:
         schema = stdjson.load(f)
     with TemporaryDirectory() as output_directory_path:
         configuration = Configuration(output_directory_path,
                                       'https://example.com')
         configuration.content_negotiation = content_negotiation
         async with App(configuration) as app:
             specification = build_specification(app)
     jsonschema.validate(specification, schema)
Ejemplo n.º 26
0
 async def test_populate_should_ignore_resource_without_links(self, m_retriever) -> None:
     resource = Source('the_source', 'The Source')
     with TemporaryDirectory() as output_directory_path:
         with TemporaryDirectory() as cache_directory_path:
             configuration = Configuration(
                 output_directory_path, 'https://example.com')
             configuration.cache_directory_path = cache_directory_path
             async with App(configuration) as app:
                 app.ancestry.entities.append(resource)
                 sut = _Populator(app, m_retriever)
                 await sut.populate()
     self.assertSetEqual(set(), resource.links)
Ejemplo n.º 27
0
 async def test_populate_should_ignore_resource_without_link_support(self, m_retriever) -> None:
     source = Source('The Source')
     resource = Citation('the_citation', source)
     with TemporaryDirectory() as output_directory_path:
         with TemporaryDirectory() as cache_directory_path:
             configuration = Configuration(
                 output_directory_path, 'https://example.com')
             configuration.cache_directory_path = cache_directory_path
             async with App(configuration) as app:
                 app.ancestry.entities.append(resource)
                 sut = _Populator(app, m_retriever)
                 await sut.populate()
Ejemplo n.º 28
0
 async def test_populate_link_should_set_locale(self, expected: str, entry_language: str, locale: Optional[str], m_retriever) -> None:
     link = Link('http://%s.wikipedia.org/wiki/Amsterdam' % entry_language)
     link.locale = locale
     with TemporaryDirectory() as output_directory_path:
         with TemporaryDirectory() as cache_directory_path:
             configuration = Configuration(
                 output_directory_path, 'https://example.com')
             configuration.cache_directory_path = cache_directory_path
             async with App(configuration) as app:
                 sut = _Populator(app, m_retriever)
                 await sut.populate_link(link, entry_language)
     self.assertEqual(expected, link.locale)
Ejemplo n.º 29
0
 async def test_populate_link_should_set_relationship(self, expected: str, relationship: Optional[str], m_retriever) -> None:
     link = Link('http://en.wikipedia.org/wiki/Amsterdam')
     link.relationship = relationship
     with TemporaryDirectory() as output_directory_path:
         with TemporaryDirectory() as cache_directory_path:
             configuration = Configuration(
                 output_directory_path, 'https://example.com')
             configuration.cache_directory_path = cache_directory_path
             async with App(configuration) as app:
                 sut = _Populator(app, m_retriever)
                 await sut.populate_link(link, 'en')
     self.assertEqual(expected, link.relationship)
Ejemplo n.º 30
0
 async def test_populate_link_should_convert_http_to_https(self, m_retriever) -> None:
     link = Link('http://en.wikipedia.org/wiki/Amsterdam')
     entry_language = 'nl'
     with TemporaryDirectory() as output_directory_path:
         with TemporaryDirectory() as cache_directory_path:
             configuration = Configuration(
                 output_directory_path, 'https://example.com')
             configuration.cache_directory_path = cache_directory_path
             async with App(configuration) as app:
                 sut = _Populator(app, m_retriever)
                 await sut.populate_link(link, entry_language)
     self.assertEqual('https://en.wikipedia.org/wiki/Amsterdam', link.url)