58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
import pytest
|
|
from app import create_app
|
|
from models import db
|
|
|
|
|
|
class TestAppFactory:
|
|
def test_create_app_default_config(self):
|
|
app = create_app()
|
|
assert app is not None
|
|
assert app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] is False
|
|
|
|
def test_create_app_testing_config(self):
|
|
app = create_app('testing')
|
|
assert app is not None
|
|
assert app.config['TESTING'] is True
|
|
assert app.config['SQLALCHEMY_DATABASE_URI'] == 'sqlite:///:memory:'
|
|
|
|
def test_create_app_development_config(self):
|
|
app = create_app('development')
|
|
assert app is not None
|
|
assert app.config['DEBUG'] is True
|
|
|
|
|
|
class TestAppRoutes:
|
|
def test_index_route(self, client):
|
|
response = client.get('/')
|
|
assert response.status_code == 200
|
|
|
|
def test_assessments_route_exists(self, client):
|
|
response = client.get('/assessments/')
|
|
assert response.status_code == 200
|
|
|
|
def test_exercises_route_prefix_exists(self, client):
|
|
response = client.get('/exercises/')
|
|
assert response.status_code in [200, 404] # Route exists but may need parameters
|
|
|
|
def test_grading_route_prefix_exists(self, client):
|
|
response = client.get('/grading/')
|
|
assert response.status_code in [200, 404] # Route exists but may need parameters
|
|
|
|
|
|
class TestDatabase:
|
|
def test_database_creation(self, app):
|
|
with app.app_context():
|
|
db.create_all()
|
|
# Use inspector to get table names in SQLAlchemy 2.0+
|
|
from sqlalchemy import inspect
|
|
inspector = inspect(db.engine)
|
|
tables = inspector.get_table_names()
|
|
expected_tables = ['class_group', 'student', 'assessment', 'exercise', 'grading_element', 'grade']
|
|
for table in expected_tables:
|
|
assert table in tables
|
|
|
|
def test_database_initialization(self, app):
|
|
with app.app_context():
|
|
assert db is not None
|
|
assert hasattr(db, 'session')
|
|
assert hasattr(db, 'Model') |