From b361a61d18de7104cf493a734044474edf36661f Mon Sep 17 00:00:00 2001 From: Leigh Morresi <275001+dgtlmoon@users.noreply.github.com> Date: Tue, 16 Feb 2021 21:36:41 +0100 Subject: [PATCH] Addingmissing files --- backend/tests/__init__.py | 2 ++ backend/tests/conftest.py | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 backend/tests/__init__.py create mode 100644 backend/tests/conftest.py diff --git a/backend/tests/__init__.py b/backend/tests/__init__.py new file mode 100644 index 00000000..085b3d78 --- /dev/null +++ b/backend/tests/__init__.py @@ -0,0 +1,2 @@ +"""Tests for the app.""" + diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py new file mode 100644 index 00000000..cf7165d3 --- /dev/null +++ b/backend/tests/conftest.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +import pytest +from webtest import TestApp +from backend import changedetection_app +from backend import store +import os + + +# https://github.com/pallets/flask/blob/1.1.2/examples/tutorial/tests/test_auth.py + +# Much better boilerplate than the docs +# https://www.python-boilerplate.com/py3+flask+pytest/ + + + +@pytest.fixture(scope='session') +def app(request): + """Create application for the tests.""" + + datastore_path = "./test-datastore" + app_config = {'datastore_path': datastore_path} + datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path']) + _app = changedetection_app(app_config, datastore) + + + # Establish an application context before running the tests. + ctx = _app.app_context() + ctx.push() + + def teardown(): + ctx.pop() + + request.addfinalizer(teardown) + return _app + +@pytest.fixture(scope='function') +def session(request): + """Creates a new database session for a test.""" + + + def teardown(): + print ("teardown") + + request.addfinalizer(teardown) + return session