Files
chore/backend/tests/conftest.py
T
ryan 59adf22d42
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 2m22s
feat: implement MongoDB test database reset for clean test sessions
2026-07-31 17:47:06 -04:00

32 lines
1.3 KiB
Python

import os
os.environ['DB_ENV'] = 'test'
os.environ['USE_MONGODB'] = 'true'
os.environ['MONGO_URI'] = 'mongomock'
os.environ.setdefault('SECRET_KEY', 'test-secret-key')
os.environ.setdefault('REFRESH_TOKEN_EXPIRY_DAYS', '90')
os.environ.setdefault('DIGEST_TOKEN_SECRET', 'test-digest-secret')
os.environ.setdefault('VAPID_PUBLIC_KEY', 'test-vapid-public-key')
os.environ.setdefault('VAPID_PRIVATE_KEY', 'test-vapid-private-key')
import sys
import pytest
# Ensure backend root is in sys.path for imports like 'config.paths'
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
# Shared test constants — import these in test files instead of hardcoding
TEST_SECRET_KEY = 'test-secret-key'
TEST_REFRESH_TOKEN_EXPIRY_DAYS = 90
@pytest.fixture(scope="session", autouse=True)
def set_test_db_env():
os.environ['DB_ENV'] = 'test'
os.environ['USE_MONGODB'] = 'true'
os.environ['MONGO_URI'] = 'mongomock'
os.environ['SECRET_KEY'] = TEST_SECRET_KEY
os.environ['REFRESH_TOKEN_EXPIRY_DAYS'] = str(TEST_REFRESH_TOKEN_EXPIRY_DAYS)
# Drop the MongoDB test database once at the start of the session so every
# test begins from a clean slate. Indexes are recreated afterward.
from db.db import reset_mongo_db, ensure_mongodb_indexes
reset_mongo_db()
ensure_mongodb_indexes()