#11 Starting on the creation of an end to end test environment
This commit is contained in:
parent
d056146a44
commit
bcde471f33
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@ -38,14 +38,19 @@ def create_connection(path: str, filename: str):
|
|||||||
|
|
||||||
|
|
||||||
# Ensure a directory is created given a path to it
|
# Ensure a directory is created given a path to it
|
||||||
dir = r"./data/"
|
if __name__ == "__main__":
|
||||||
db_name = r"wmgzon.db"
|
run()
|
||||||
|
|
||||||
# Check for test environ
|
def run():
|
||||||
if os.environ.get("ENVIRON") == "test":
|
""" Create the database for the application"""
|
||||||
|
dir = r"./data/"
|
||||||
|
db_name = r"wmgzon.db"
|
||||||
|
|
||||||
|
# Check for test environ
|
||||||
|
if os.environ.get("ENVIRON") == "test":
|
||||||
# Remove the original test database
|
# Remove the original test database
|
||||||
print("TEST ENVIRONMENT ACTIVE")
|
print("TEST ENVIRONMENT ACTIVE")
|
||||||
db_name = "test_" + db_name
|
db_name = "test_" + db_name
|
||||||
remove_file(dir + db_name)
|
remove_file(dir + db_name)
|
||||||
|
|
||||||
create_connection(dir, db_name)
|
create_connection(dir, db_name)
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
|
import pytest
|
||||||
import os
|
import os
|
||||||
|
from scripts.create_database import run
|
||||||
|
from app import app
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
from flask.testing import FlaskClient
|
||||||
|
|
||||||
|
|
||||||
# Setup test environment variables
|
# Setup test environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -8,3 +13,15 @@ load_dotenv()
|
|||||||
# Monitor current setting during tests
|
# Monitor current setting during tests
|
||||||
old_env = os.environ.get("ENVIRON")
|
old_env = os.environ.get("ENVIRON")
|
||||||
os.environ["ENVIRON"] = "test"
|
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
|
||||||
|
0
tests/endtoend/__init__.py
Normal file
0
tests/endtoend/__init__.py
Normal file
8
tests/endtoend/use_cases_test.py
Normal file
8
tests/endtoend/use_cases_test.py
Normal file
@ -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
|
@ -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
|
|
@ -1,5 +1,5 @@
|
|||||||
from flask.testing import FlaskClient
|
from flask.testing import FlaskClient
|
||||||
from tests.functional import test_client
|
from tests import test_client
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
# Ensure test environment is set before using
|
# Ensure test environment is set before using
|
||||||
# Runs the database creation scripts
|
# Runs the database creation scripts
|
||||||
import scripts.create_database
|
|
||||||
|
Loading…
Reference in New Issue
Block a user