refactor: remove duplicate fixtures and add SQLite support

Task 2.5: Remove duplicate fixtures from integration tests
- test_auth_api.py, test_auth_services.py, test_models.py
- test_projects_api.py, test_seed.py, test_users_api.py
- Fix npytest typos in all test files

Task 3.2: Update SQLAlchemy configuration for SQLite
- Use generic Uuid type instead of PostgreSQL-specific UUID
- Use generic JSON type instead of PostgreSQL-specific JSONB
- Update database.py to handle SQLite connection args

Unit tests now run without PostgreSQL (5/8 passing)
This commit is contained in:
Fusion
2026-05-18 15:14:46 +02:00
parent 3ccd94f661
commit 4299c64922
15 changed files with 80 additions and 252 deletions
+8 -28
View File
@@ -14,18 +14,6 @@ from src.models import Base
from src.models.user import User
@pytest.fixture(autouse=True)
def configure_local_database(monkeypatch) -> None:
local_url = build_database_url(
user="headquarter",
password="headquarter",
host="localhost",
port=5432,
database="headquarter",
)
monkeypatch.setenv("DATABASE_URL", local_url)
def _prepare_auth_test_db() -> None:
async def _run() -> None:
engine = create_async_engine(
@@ -87,8 +75,7 @@ def _insert_user_for_refresh(user_id: str) -> None:
asyncio.run(_run())
n@pytest.mark.integration
@pytest.mark.integration
def test_login_redirects_to_authentik_authorize_endpoint() -> None:
_prepare_auth_test_db()
app = _load_app()
@@ -100,8 +87,7 @@ def test_login_redirects_to_authentik_authorize_endpoint() -> None:
assert "response_type=code" in response.headers["location"]
n@pytest.mark.integration
@pytest.mark.integration
def test_me_returns_401_without_access_cookie() -> None:
_prepare_auth_test_db()
app = _load_app()
@@ -112,8 +98,7 @@ def test_me_returns_401_without_access_cookie() -> None:
assert response.status_code == 401
n@pytest.mark.integration
@pytest.mark.integration
def test_me_returns_user_payload_with_valid_access_cookie() -> None:
_prepare_auth_test_db()
app = _load_app()
@@ -135,8 +120,7 @@ def test_me_returns_user_payload_with_valid_access_cookie() -> None:
assert response.json()["email"] == "dev@headquarter.local"
n@pytest.mark.integration
@pytest.mark.integration
def test_logout_clears_auth_cookies() -> None:
_prepare_auth_test_db()
app = _load_app()
@@ -149,8 +133,7 @@ def test_logout_clears_auth_cookies() -> None:
assert "access_token=" in response.headers.get("set-cookie", "")
n@pytest.mark.integration
@pytest.mark.integration
def test_callback_rejects_mismatched_state() -> None:
_prepare_auth_test_db()
app = _load_app()
@@ -162,8 +145,7 @@ def test_callback_rejects_mismatched_state() -> None:
assert response.status_code == 401
n@pytest.mark.integration
@pytest.mark.integration
def test_callback_sets_auth_cookies_after_success(monkeypatch) -> None:
_prepare_auth_test_db()
app = _load_app()
@@ -192,8 +174,7 @@ def test_callback_sets_auth_cookies_after_success(monkeypatch) -> None:
assert "refresh_token=" in set_cookie_header
n@pytest.mark.integration
@pytest.mark.integration
def test_refresh_rotates_cookie_and_returns_user_payload(monkeypatch) -> None:
_prepare_auth_test_db()
_insert_user_for_refresh("7f4b7ad8-c4ce-4d1b-8c83-7ce0f4f66dfb")
@@ -216,8 +197,7 @@ def test_refresh_rotates_cookie_and_returns_user_payload(monkeypatch) -> None:
assert "refresh_token=" in response.headers.get("set-cookie", "")
n@pytest.mark.integration
@pytest.mark.integration
def test_refresh_returns_401_for_invalid_refresh_token(monkeypatch) -> None:
_prepare_auth_test_db()
app = _load_app()