Files
POTE/tests/conftest.py
T
ilia 5df21d82f4
CI / skip-ci-check (pull_request) Successful in 19s
CI / secret-scan (pull_request) Successful in 19s
CI / python-ci (pull_request) Successful in 2m38s
Fix lint debt and make CI gates honest
- ruff: fix all 328 errors (autofix + manual); move config to [tool.ruff.lint]
- mypy: fix all errors (annotations, nullable-column guards, stale kwargs
  in weekly report caller)
- black: reformat src/tests so black --check passes
- CI: remove `|| true` from ruff/black/mypy/pytest steps in both
  .gitea and .github workflows; install project deps and add mypy
  step in gitea python-ci so gates actually run
- docs: move 14 root status/guide markdown files into docs/, update links
2026-07-26 15:41:07 -04:00

106 lines
2.7 KiB
Python

"""
Pytest fixtures and test configuration.
"""
from datetime import date
from decimal import Decimal
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, sessionmaker
from pote.db import Base
from pote.db.models import Official, Price, Security, Trade
@pytest.fixture(scope="function")
def test_db_session() -> Session:
"""
Create an in-memory SQLite database for testing.
Each test gets a fresh database.
"""
engine = create_engine("sqlite:///:memory:", echo=False)
Base.metadata.create_all(engine)
session_factory = sessionmaker(bind=engine)
session = session_factory()
yield session
session.close()
engine.dispose()
@pytest.fixture
def sample_official(test_db_session: Session) -> Official:
"""Create a sample official for testing."""
official = Official(
name="Jane Doe",
chamber="Senate",
party="Independent",
state="CA",
bioguide_id="D000123",
)
test_db_session.add(official)
test_db_session.commit()
test_db_session.refresh(official)
return official
@pytest.fixture
def sample_security(test_db_session: Session) -> Security:
"""Create a sample security for testing."""
security = Security(
ticker="AAPL",
name="Apple Inc.",
exchange="NASDAQ",
sector="Technology",
asset_type="stock",
)
test_db_session.add(security)
test_db_session.commit()
test_db_session.refresh(security)
return security
@pytest.fixture
def sample_trade(
test_db_session: Session, sample_official: Official, sample_security: Security
) -> Trade:
"""Create a sample trade for testing."""
trade = Trade(
official_id=sample_official.id,
security_id=sample_security.id,
source="test",
external_id="test-001",
transaction_date=date(2024, 1, 15),
filing_date=date(2024, 2, 1),
side="buy",
value_min=Decimal("15000.00"),
value_max=Decimal("50000.00"),
currency="USD",
)
test_db_session.add(trade)
test_db_session.commit()
test_db_session.refresh(trade)
return trade
@pytest.fixture
def sample_price(test_db_session: Session, sample_security: Security) -> Price:
"""Create a sample price record for testing."""
price = Price(
security_id=sample_security.id,
date=date(2024, 1, 15),
open=Decimal("180.50"),
high=Decimal("182.75"),
low=Decimal("179.00"),
close=Decimal("181.25"),
volume=50000000,
source="yfinance",
)
test_db_session.add(price)
test_db_session.commit()
test_db_session.refresh(price)
return price