#11 REFACTOR: Moved all tests into test classes
This commit is contained in:
@ -1,39 +0,0 @@
|
||||
from flask.testing import FlaskClient
|
||||
from tests import test_client
|
||||
import pytest
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
41
tests/functional/test_pages.py
Normal file
41
tests/functional/test_pages.py
Normal file
@ -0,0 +1,41 @@
|
||||
from flask.testing import FlaskClient
|
||||
from tests.base_test import TestBase
|
||||
|
||||
|
||||
class TestPages(TestBase):
|
||||
""" Test class that encapsulates tests for
|
||||
the main pages on the site
|
||||
"""
|
||||
|
||||
def test_homepage(self, 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(self, 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
|
||||
|
||||
def test_admin(self, 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
|
Reference in New Issue
Block a user