#11 Added extra functional tests for admin endpoints

This commit is contained in:
Luke Else 2024-02-19 08:14:35 +00:00
parent 263bea92f4
commit d056146a44
2 changed files with 28 additions and 14 deletions

View File

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

View File

@ -1,19 +1,6 @@
from app import app
from flask.testing import FlaskClient from flask.testing import FlaskClient
from tests.functional import test_client
import pytest 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): def test_homepage(test_client: FlaskClient):
@ -39,3 +26,14 @@ def test_products(test_client: FlaskClient):
response = test_client.get('/products/Books') response = test_client.get('/products/Books')
assert response.status_code == 200 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