July 3rd - Review and optimize codes

This commit is contained in:
2026-07-03 14:38:49 -04:00
parent d0b1b7ae23
commit 4c275fc0e5
16 changed files with 353 additions and 136 deletions
+38
View File
@@ -0,0 +1,38 @@
"""
tests/conftest.py
-----------------
Shared pytest fixtures + import-time environment setup.
`config.py` calls `_require_env('SECRET_KEY')` and `_require_env('DATABASE_URL')`
at *import* time, so those must be present in os.environ before `app` is
imported anywhere. We set safe, throwaway values here (SQLite in-memory) so the
whole suite can run with no MySQL, no Redis, no Stripe, and no real secrets.
The pure-logic tests (SLA math, webhook helpers) never touch the DB. The
routing-inertness test uses the in-memory SQLite engine only.
"""
import os
# ── Import-time env (must be set BEFORE `import app`) ────────────────────────
os.environ.setdefault('SECRET_KEY', 'test-secret-key')
os.environ.setdefault('DATABASE_URL', 'sqlite:///:memory:')
os.environ.setdefault('MULTI_TENANT_ENABLED', 'false')
os.environ.setdefault('BILLING_ENABLED', 'false')
import pytest # noqa: E402
@pytest.fixture(scope='session')
def app():
"""A minimal single-tenant app on in-memory SQLite (multi-tenancy inert)."""
from app import create_app
application = create_app('default')
application.config.update(TESTING=True, WTF_CSRF_ENABLED=False, SQLALCHEMY_ECHO=False)
return application
@pytest.fixture
def app_ctx(app):
with app.app_context():
yield app