diff --git a/requirements.txt b/requirements.txt index 361fe5c..1ea46d7 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/scripts/create_database.py b/scripts/create_database.py index 3a841eb..b8faef9 100644 --- a/scripts/create_database.py +++ b/scripts/create_database.py @@ -38,14 +38,19 @@ def create_connection(path: str, filename: str): # Ensure a directory is created given a path to it -dir = r"./data/" -db_name = r"wmgzon.db" +if __name__ == "__main__": + run() -# Check for test environ -if os.environ.get("ENVIRON") == "test": - # Remove the original test database - print("TEST ENVIRONMENT ACTIVE") - db_name = "test_" + db_name - remove_file(dir + db_name) +def run(): + """ Create the database for the application""" + dir = r"./data/" + db_name = r"wmgzon.db" -create_connection(dir, db_name) + # Check for test environ + if os.environ.get("ENVIRON") == "test": + # Remove the original test database + print("TEST ENVIRONMENT ACTIVE") + db_name = "test_" + db_name + remove_file(dir + db_name) + + create_connection(dir, db_name) diff --git a/tests/__init__.py b/tests/__init__.py index a6b29a5..59f2e74 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,10 @@ +import pytest import os +from scripts.create_database import run +from app import app from dotenv import load_dotenv +from flask.testing import FlaskClient + # Setup test environment variables load_dotenv() @@ -8,3 +13,15 @@ load_dotenv() # Monitor current setting during tests old_env = os.environ.get("ENVIRON") os.environ["ENVIRON"] = "test" + +run() + +@pytest.fixture(scope="module") +def test_client() -> FlaskClient: + """ Enables tests to create requests to the web app + """ + os.environ['CONFIG_TYPE'] = 'config.TestingConfig' + + with app.test_client() as testing_client: + with app.app_context(): + yield testing_client diff --git a/tests/endtoend/__init__.py b/tests/endtoend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/endtoend/use_cases_test.py b/tests/endtoend/use_cases_test.py new file mode 100644 index 0000000..e9f315c --- /dev/null +++ b/tests/endtoend/use_cases_test.py @@ -0,0 +1,8 @@ +import pytest +from bs4 import BeautifulSoup +from tests import test_client +from flask.testing import FlaskClient + +# def test_use_case(test_client: FlaskClient): +# response = test_client.get('/products/Car Parts') +# assert response.status_code == 200 \ No newline at end of file diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py index 06bf919..e69de29 100644 --- a/tests/functional/__init__.py +++ b/tests/functional/__init__.py @@ -1,16 +0,0 @@ -from app import app -from flask.testing import FlaskClient -import pytest -import os - - -@pytest.fixture(scope="module") -def test_client() -> FlaskClient: - """ Test that required environment variables are set - ahead of runtime - """ - os.environ['CONFIG_TYPE'] = 'config.TestingConfig' - - with app.test_client() as testing_client: - with app.app_context(): - yield testing_client diff --git a/tests/functional/test_homepage.py b/tests/functional/test_homepage.py index d570fc2..b2803cb 100644 --- a/tests/functional/test_homepage.py +++ b/tests/functional/test_homepage.py @@ -1,5 +1,5 @@ from flask.testing import FlaskClient -from tests.functional import test_client +from tests import test_client import pytest diff --git a/tests/unit/database/__init__.py b/tests/unit/database/__init__.py index 9bd5abe..2257c58 100644 --- a/tests/unit/database/__init__.py +++ b/tests/unit/database/__init__.py @@ -1,3 +1,2 @@ # Ensure test environment is set before using -# Runs the database creation scripts -import scripts.create_database +# Runs the database creation scripts \ No newline at end of file