Initial commit - Mold Cost Calculator Application (Security Fixed)

This commit is contained in:
Gan, Jimmy
2025-06-24 10:28:55 +08:00
commit 9b84cee5be
108 changed files with 15886 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
import os
import pytest
from app import create_app, db
from app.config import Config
class TestConfig(Config):
"""Test configuration that overrides the base configuration."""
TESTING = True
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
WTF_CSRF_ENABLED = False
LOG_LEVEL = 'DEBUG'
# Override required settings for testing
SECRET_KEY = 'testing-secret-key-not-used-in-production'
MAIL_SUPPRESS_SEND = True
RATELIMIT_ENABLED = False
# Testing-specific settings
RATELIMIT_DEFAULT = "1000 per day;100 per hour;20 per minute"
CACHE_TYPE = "SimpleCache"
def get_test_config():
"""Get test configuration."""
return TestConfig()
@pytest.fixture(scope='session')
def app():
"""Create and configure a Flask app for testing."""
app = create_app('testing')
app.config.update(get_test_config())
# Create the database and load test data
with app.app_context():
db.create_all()
yield app
db.session.remove()
db.drop_all()
@pytest.fixture(scope='session')
def client(app):
"""A test client for the app."""
return app.test_client()
@pytest.fixture(scope='session')
def runner(app):
"""A test CLI runner for the app."""
return app.test_cli_runner()
@pytest.fixture(scope='function')
def test_db(app):
"""Create a fresh database for each test."""
with app.app_context():
db.create_all()
yield db
db.session.remove()
db.drop_all()