From 00e89146f273710b95c604c4be8fd9049efd5aff Mon Sep 17 00:00:00 2001 From: Al Crowley Date: Fri, 11 Feb 2022 09:14:58 -0500 Subject: [PATCH] Adding test to verify code coverage * Adding test_get_return_envelope * Modified JsonFormatter setup because existing code was generating an error * Adding PYTHONPATH to CircleCI job pytest call to resolve testing imports * Simplify call of pytest in the CI job now that we have a test to run * Upgrading Flaks and Flask-API to be compatibile with Werkzeug 2.0.2 * Werkzeug can't be downgraded due to security issues with older packages. --- .circleci/config.yml | 10 +--------- requirements.txt | 4 ++-- routes/src/log.py | 5 +---- routes/src/tests/conftest.py | 0 routes/src/tests/test_common.py | 12 ++++++++++++ 5 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 routes/src/tests/conftest.py create mode 100644 routes/src/tests/test_common.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 6c085b4..1a0b6bb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,15 +38,7 @@ jobs: - run: name: Run tests, save a coverage report, and save coverage percentage command: | - pytest --cov=. --cov-report=xml --cov-report=html --cov-report=term || EXIT_CODE=$? - if [ $EXIT_CODE == "0" ]; then - echo "Tests ran successfully" - elif [ $EXIT_CODE == "5" ]; then - echo "No tests found. Continuing." - else - echo "Unit test errors. pytest exited with $EXIT_CODE." - exit 1 - fi + PYTHONPATH=. pytest --cov=. --cov-report=xml --cov-report=html --cov-report=term - store_artifacts: path: htmlcov diff --git a/requirements.txt b/requirements.txt index 9aa9272..eeabeb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ certifi==2018.10.15 chardet==3.0.4 Click==7.0 cx-Oracle==7.0.0 -Flask==1.0.2 +Flask==2.0.2 Flask-Cors==3.0.9 Flask-HTTPAuth==3.2.4 idna==2.7 @@ -21,7 +21,7 @@ ipdb==0.12.3 pypdftk==0.4 boto3==1.14.60 botocore==1.17.60 -Flask-API==1.1 +Flask-API==3.0.post1 PyPDF2==1.26.0 pdfkit==0.6.1 beautifulsoup4==4.7.1 diff --git a/routes/src/log.py b/routes/src/log.py index f104017..0e723e1 100644 --- a/routes/src/log.py +++ b/routes/src/log.py @@ -12,10 +12,7 @@ def log_init(): formatter = jsonlogger.JsonFormatter( - '{"timestamp":%(asctime),"message":%(message),' - '"function_name":%(funcName),"logger_name":%(name),' - '"logger_level":%(levelname),"filename":%(filename),' - '"line_number":%(lineno)' + '%(timestamp)s %(messages)s %(funcName)s %(name)s %(levelname)s %(filename)s %(lineno)s' ) logHandler = logging.StreamHandler(sys.stdout) diff --git a/routes/src/tests/conftest.py b/routes/src/tests/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/routes/src/tests/test_common.py b/routes/src/tests/test_common.py new file mode 100644 index 0000000..81d7795 --- /dev/null +++ b/routes/src/tests/test_common.py @@ -0,0 +1,12 @@ +from unittest import TestCase +from routes.src.common import get_return_envelope + +class TestCommon(TestCase): + + def test_get_return_envelope(self): + msg = "Test message 1" + data = [1,2,3] + envelope = get_return_envelope(success=True, message=msg, data=data) + self.assertTrue(envelope['success']) + self.assertEqual(msg, envelope['message']) + self.assertEqual(data, envelope['results'])