From 9b64eea97b534e44da500222173046b8ddba21d7 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Sun, 6 Dec 2020 15:24:21 -0600 Subject: [PATCH] Some route prefix integration tests --- setup.py | 3 ++ tests/test_pgwui_server_integration.py | 62 ++++++++++++++++++++++++++ tox.ini | 4 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a8ab059..27e68ec 100644 --- a/setup.py +++ b/setup.py @@ -62,6 +62,9 @@ tests_require = [ 'pytest>=3.7.4', 'pytest-cov', 'pgwui_testing==' + version, + # Integration test with other modules + 'pgwui_logout==' + version, + 'pgwui_menu==' + version, ] setup( diff --git a/tests/test_pgwui_server_integration.py b/tests/test_pgwui_server_integration.py index 058f0e6..c1a5e4e 100644 --- a/tests/test_pgwui_server_integration.py +++ b/tests/test_pgwui_server_integration.py @@ -22,6 +22,9 @@ import pytest +import pgwui_logout +import pgwui_menu + import pgwui_server.pgwui_server as pgwui_server @@ -35,8 +38,67 @@ TEST_SETTINGS = { 'pgwui.dry_run': 'False', } +REFERENCE_SETTINGS = { + 'pgwui.pg_host': '', + 'pgwui.pg_port': '5432', + 'pgwui.default_db': 'template1', + 'pgwui.autoconfigure': 'True', + 'pgwui.dry_run': 'False', + 'pgwui.validate_hmac': 'False', + # 'pgwui.home_page': { # The default + # 'type': 'URL', + # 'source': '/'}, + # 'pgwui.menu_page': { # An example + # 'type': 'URL', + # 'source': '/'}, + # 'pgwui.route_prefix': '', # The default + # 'pgwui.routes': { # An example + # 'pgwui_logout': '/logout', + # 'pgwui_upload': '/upload'} + # 'pgwui.pgwui_menu': { # An example + # 'order': ['pgwui_upload', + # 'pgwui_logout'], + # 'pgwui_upload': { # The defaults + # 'literal_column_headings': 'off', + # 'menu_label': 'upload -- Upload File Into Database'}, +} + # Integration tests def test_main_integrated(): '''Does not raise errors or warnings''' pgwui_server.main({}, **TEST_SETTINGS) + + +# Helper functions + +def check_route(config, name, expected): + route_i = config.introspector.get('routes', name) + assert route_i['pattern'] == expected + + +def updated_dict(old, new): + updated = old.copy() + updated.update(new) + return updated + + +@pytest.mark.parametrize( + ('settings', 'logout_path', 'menu_path'), [ + (REFERENCE_SETTINGS, + pgwui_logout.pgwui_logout.DEFAULT_LOGOUT_ROUTE, + pgwui_menu.pgwui_menu.DEFAULT_MENU_ROUTE), + (updated_dict(REFERENCE_SETTINGS, + {'pgwui.route_prefix': '/foo'}), + 'foo' + pgwui_logout.pgwui_logout.DEFAULT_LOGOUT_ROUTE, + 'foo' + pgwui_menu.pgwui_menu.DEFAULT_MENU_ROUTE)]) +def test_pgwui_server_config_no_route_prefix( + settings, logout_path, menu_path): + '''The given route_prefix is applied to the routes + ''' + config = pgwui_server.pgwui_server_config(settings) + config.commit() + config.end() + + check_route(config, 'pgwui_logout', logout_path) + check_route(config, 'pgwui_menu', menu_path) diff --git a/tox.ini b/tox.ini index d134125..090067a 100644 --- a/tox.ini +++ b/tox.ini @@ -15,9 +15,11 @@ deps = pytest-cov twine # coverage - # This is a bug, because we'd like to specify the pgwui_testing + # This is a bug, because we'd like to specify the pgwui_* # version to be equal to the pgwui_server version being tested. pgwui_testing + pgwui_logout + pgwui_menu commands = check-manifest python setup.py sdist -- 2.34.1