Some route prefix integration tests
authorKarl O. Pinc <kop@karlpinc.com>
Sun, 6 Dec 2020 21:24:21 +0000 (15:24 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Sun, 6 Dec 2020 22:44:56 +0000 (16:44 -0600)
setup.py
tests/test_pgwui_server_integration.py
tox.ini

index a8ab059c77c793c867106a51c5333d609ca4040a..27e68ec7b970b3741052c4bf4e06a59c036c40eb 100644 (file)
--- 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(
index 058f0e6e0b3a4c58973179db963f9e4053c49338..c1a5e4e9c26e650c19d18edf5e2a997206ef3dbb 100644 (file)
@@ -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 d1341252ce805dcaa6a5f25953bb527d96ee23ea..090067ac8852b056463c285e72cc88a2d4f1e72c 100644 (file)
--- 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