From d056146a449c6d7e295039b25cba981d5eb6eea7 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Mon, 19 Feb 2024 08:14:35 +0000 Subject: [PATCH] #11 Added extra functional tests for admin endpoints --- tests/functional/__init__.py | 16 ++++++++++++++++ tests/functional/test_homepage.py | 26 ++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py index e69de29..06bf919 100644 --- a/tests/functional/__init__.py +++ b/tests/functional/__init__.py @@ -0,0 +1,16 @@ +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 b66d439..d570fc2 100644 --- a/tests/functional/test_homepage.py +++ b/tests/functional/test_homepage.py @@ -1,19 +1,6 @@ -from app import app from flask.testing import FlaskClient +from tests.functional import test_client 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): @@ -39,3 +26,14 @@ def test_products(test_client: FlaskClient): response = test_client.get('/products/Books') assert response.status_code == 200 + + +def test_admin(test_client: FlaskClient): + """ Tests that the admin pages can be reached and redirect + upon reaching + """ + response = test_client.get('/admin/users/') + assert response.status_code == 302 + + response = test_client.get('/admin/products/') + assert response.status_code == 302