refactor: improve code formatting and organization across multiple files
This commit is contained in:
@@ -35,9 +35,7 @@ def test_me_endpoint_returns_current_user() -> None:
|
||||
)
|
||||
token = login.json()["accessToken"]
|
||||
|
||||
response = client.get(
|
||||
"/api/auth/me", headers={"Authorization": f"Bearer {token}"}
|
||||
)
|
||||
response = client.get("/api/auth/me", headers={"Authorization": f"Bearer {token}"})
|
||||
assert response.status_code == 200
|
||||
assert response.json()["username"] == "demo"
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ def test_network_snapshot_requires_authentication() -> None:
|
||||
|
||||
def test_network_snapshot_endpoint_returns_collections() -> None:
|
||||
token = _authenticate()
|
||||
response = client.get(
|
||||
"/api/network", headers={"Authorization": f"Bearer {token}"}
|
||||
)
|
||||
response = client.get("/api/network", headers={"Authorization": f"Bearer {token}"})
|
||||
assert response.status_code == 200
|
||||
|
||||
payload = response.json()
|
||||
|
||||
@@ -40,7 +40,9 @@ def sample_entities() -> dict[str, SimpleNamespace]:
|
||||
return {"station": station, "track": track, "train": train}
|
||||
|
||||
|
||||
def test_network_snapshot_prefers_repository_data(monkeypatch: pytest.MonkeyPatch, sample_entities: dict[str, SimpleNamespace]) -> None:
|
||||
def test_network_snapshot_prefers_repository_data(
|
||||
monkeypatch: pytest.MonkeyPatch, sample_entities: dict[str, SimpleNamespace]
|
||||
) -> None:
|
||||
station = sample_entities["station"]
|
||||
track = sample_entities["track"]
|
||||
train = sample_entities["train"]
|
||||
@@ -58,7 +60,9 @@ def test_network_snapshot_prefers_repository_data(monkeypatch: pytest.MonkeyPatc
|
||||
assert snapshot["trains"][0]["operatingTrackIds"] == []
|
||||
|
||||
|
||||
def test_network_snapshot_falls_back_when_repositories_empty(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_network_snapshot_falls_back_when_repositories_empty(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(StationRepository, "list_active", lambda self: [])
|
||||
monkeypatch.setattr(TrackRepository, "list_all", lambda self: [])
|
||||
monkeypatch.setattr(TrainRepository, "list_all", lambda self: [])
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import Any, List, cast
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from backend.app.db.models import TrainSchedule, User
|
||||
from backend.app.db.unit_of_work import SqlAlchemyUnitOfWork
|
||||
@@ -23,7 +24,6 @@ from backend.app.repositories import (
|
||||
TrainScheduleRepository,
|
||||
UserRepository,
|
||||
)
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -50,7 +50,9 @@ class DummySession:
|
||||
self.statements.append(statement)
|
||||
return self.scalar_result
|
||||
|
||||
def flush(self, _objects: list[Any] | None = None) -> None: # pragma: no cover - optional
|
||||
def flush(
|
||||
self, _objects: list[Any] | None = None
|
||||
) -> None: # pragma: no cover - optional
|
||||
return None
|
||||
|
||||
def commit(self) -> None: # pragma: no cover - optional
|
||||
@@ -215,9 +217,7 @@ def test_unit_of_work_commits_and_closes_session() -> None:
|
||||
uow = SqlAlchemyUnitOfWork(lambda: cast(Session, session))
|
||||
|
||||
with uow as active:
|
||||
active.users.create(
|
||||
UserCreate(username="demo", password_hash="hashed")
|
||||
)
|
||||
active.users.create(UserCreate(username="demo", password_hash="hashed"))
|
||||
active.commit()
|
||||
|
||||
assert session.committed
|
||||
|
||||
Reference in New Issue
Block a user