diff --git a/vasl_templates/webapp/tests/conftest.py b/conftest.py similarity index 69% rename from vasl_templates/webapp/tests/conftest.py rename to conftest.py index 5366863..fa65659 100644 --- a/vasl_templates/webapp/tests/conftest.py +++ b/conftest.py @@ -5,6 +5,7 @@ import threading import logging import tempfile import urllib.request +from urllib.error import URLError import pytest from flask import url_for @@ -17,6 +18,17 @@ FLASK_WEBAPP_PORT = 5001 # --------------------------------------------------------------------- +def pytest_addoption( parser ): + """Configure pytest options.""" + # add an option to control checking of vehicle/ordnance reports + # NOTE: This file needs to be in the project root for this to work :-/ + parser.addoption( + "--vo-reports", action="store_true", dest="check_vo_reports", default=False, + help="Check the vehicle/ordnance reports." +) + +# --------------------------------------------------------------------- + @pytest.fixture def webapp(): """Launch the webapp.""" @@ -32,7 +44,7 @@ def webapp(): # configure the webapp to use our test data # NOTE: Can't seem to change constants.DATA_DIR (probably some pytest funkiness :-/) - app.config["DATA_DIR"] = os.path.join( os.path.split(__file__)[0], "fixtures/data" ) + app.config["DATA_DIR"] = os.path.join( os.path.split(__file__)[0], "vasl_templates/webapp/tests/fixtures/data" ) # start the webapp server (in a background thread) logging.disable( logging.CRITICAL ) @@ -40,6 +52,21 @@ def webapp(): target = lambda: app.run( host="0.0.0.0", port=FLASK_WEBAPP_PORT, use_reloader=False ) ) thread.start() + + # wait for the server to start up + def is_ready(): + """Try to connect to the webapp server.""" + try: + resp = urllib.request.urlopen( app.url_for("ping") ).read() + assert resp == b"pong" + return True + except URLError: + return False + except Exception as ex: #pylint: disable=broad-except + assert False, "Unexpected exception: {}".format(ex) + utils.wait_for( 5, is_ready ) + + # return the server to the caller yield app # shutdown the webapp server diff --git a/setup.py b/setup.py index f41083d..fca6988 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,7 @@ setup( extras_require = { "dev": [ "pytest==3.6.0", + "tabulate==0.8.2", "selenium==3.12.0", "pylint==1.9.2", "pytest-pylint==0.9.0", diff --git a/vasl_templates/webapp/__init__.py b/vasl_templates/webapp/__init__.py index d881a95..a4cde39 100644 --- a/vasl_templates/webapp/__init__.py +++ b/vasl_templates/webapp/__init__.py @@ -41,6 +41,7 @@ if os.path.isfile( _fname ): # load the application import vasl_templates.webapp.main #pylint: disable=cyclic-import +import vasl_templates.webapp.vehicles_ordnance #pylint: disable=cyclic-import import vasl_templates.webapp.snippets #pylint: disable=cyclic-import # initialize the application diff --git a/vasl_templates/webapp/data/default-template-pack/baz.j2 b/vasl_templates/webapp/data/default-template-pack/baz.j2 index 07f1168..74237cf 100644 --- a/vasl_templates/webapp/data/default-template-pack/baz.j2 +++ b/vasl_templates/webapp/data/default-template-pack/baz.j2 @@ -74,6 +74,6 @@ td.r { text-align: right ; }