#11 Starting on the creation of an end to end test environment

This commit is contained in:
Luke Else 2024-02-23 18:24:57 +00:00
parent d056146a44
commit bcde471f33
8 changed files with 41 additions and 28 deletions

Binary file not shown.

View File

@ -38,6 +38,11 @@ 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
if __name__ == "__main__":
run()
def run():
""" Create the database for the application"""
dir = r"./data/" dir = r"./data/"
db_name = r"wmgzon.db" db_name = r"wmgzon.db"

View File

@ -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

View File

View 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

View File

@ -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

View File

@ -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

View File

@ -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