Started on making functional unit tests for endpoints

This commit is contained in:
Luke Else 2024-02-05 19:19:29 +00:00
parent e45ec4b217
commit ee33965baf
9 changed files with 199 additions and 159 deletions

3
app.py
View File

@ -8,7 +8,7 @@ from controllers.web.endpoints import blueprint
Database manager...
'''
app = Flask(__name__)
app: Flask = Flask(__name__)
# Set app secret key to sign session cookies
secret_key = environ.get("APPSECRET")
@ -24,4 +24,3 @@ app.register_blueprint(blueprint)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=8080)

View File

View File

@ -0,0 +1,41 @@
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
def test_homepage(test_client: FlaskClient):
""" Tests that the main homepage loads correctly
once the '/' endpoint is hit
"""
response = test_client.get('/')
assert response.status_code == 302
response = test_client.get('/products')
assert response.status_code == 308
def test_products(test_client: FlaskClient):
""" Tests that a product page is displayed when
hitting one of the product endpoints
"""
response = test_client.get('/products/2')
assert response.status_code == 200
response = test_client.get('/products/50')
assert response.status_code == 302
response = test_client.get('/products/Books')
assert response.status_code == 200

0
tests/unit/__init__.py Normal file
View File