d582f15681
- Implemented tests for import polling functionality, ensuring correct behavior for active and terminal import statuses. - Created tests for the login page, validating user interactions and error handling. - Added unit tests for money utility functions, covering parsing, formatting, and summation of monetary values. - Developed tests for query keys, ensuring proper scoping and invalidation roots. chore: setup testing environment and configuration - Added setup file for testing with Vitest and Testing Library. - Configured TypeScript and Vite for the frontend project. - Created Docker and Nginx configurations for local development and production environments. - Established a PostgreSQL initialization script for setting up application roles. docs: add README and environment configuration for infra - Included README for the infra directory, detailing local development setup and service descriptions. - Created an example environment configuration file for local development with placeholders for sensitive information.
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
import os
|
|
from collections.abc import Iterator
|
|
|
|
os.environ.setdefault("ADMIN_BOOTSTRAP_TOKEN", "test-admin-token")
|
|
os.environ.setdefault("COOKIE_SECURE", "false")
|
|
os.environ.setdefault("IMPORTS_KEK_B64", "MDAxMTIyMzM0NDU1NjY3Nzg4ODlhYWJiY2NkZGVlZg==")
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy import create_engine, event
|
|
from sqlalchemy.orm import Session, sessionmaker
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
from app.db import models as _models # noqa: F401
|
|
from app.db.base import Base
|
|
from app.db.session import get_db
|
|
from app.main import app
|
|
|
|
|
|
@pytest.fixture
|
|
def db_factory() -> Iterator[sessionmaker[Session]]:
|
|
engine = create_engine(
|
|
"sqlite://",
|
|
connect_args={"check_same_thread": False},
|
|
poolclass=StaticPool,
|
|
)
|
|
|
|
@event.listens_for(engine, "connect")
|
|
def foreign_keys(connection, _record) -> None:
|
|
connection.execute("PRAGMA foreign_keys=ON")
|
|
|
|
Base.metadata.create_all(engine)
|
|
factory = sessionmaker(bind=engine, expire_on_commit=False)
|
|
yield factory
|
|
Base.metadata.drop_all(engine)
|
|
engine.dispose()
|
|
|
|
|
|
@pytest.fixture
|
|
def db(db_factory: sessionmaker[Session]) -> Iterator[Session]:
|
|
with db_factory() as session:
|
|
yield session
|
|
session.rollback()
|
|
|
|
|
|
@pytest.fixture
|
|
def client(db_factory: sessionmaker[Session]) -> Iterator[TestClient]:
|
|
def override_db() -> Iterator[Session]:
|
|
with db_factory() as session:
|
|
try:
|
|
yield session
|
|
session.commit()
|
|
except Exception:
|
|
session.rollback()
|
|
raise
|
|
|
|
app.dependency_overrides[get_db] = override_db
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
app.dependency_overrides.clear()
|