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
@@ -2,7 +2,6 @@ import uuid
from datetime import UTC, datetime, timedelta
import asyncio
from fastapi.testclient import TestClient
import pytest
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
@@ -14,18 +13,6 @@ from src.models.project import Project
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_test_db() -> None:
async def _run() -> None:
engine = create_async_engine(
@@ -132,8 +119,7 @@ def _insert_project(project_id: str, owner_id: str, name: str = "Test Project")
asyncio.run(_run())
n@pytest.mark.integration
@pytest.mark.integration
def test_create_project_requires_authentication() -> None:
_prepare_test_db()
app = _load_app()
@@ -144,8 +130,7 @@ def test_create_project_requires_authentication() -> None:
assert response.status_code == 401
n@pytest.mark.integration
@pytest.mark.integration
def test_create_project_successfully() -> None:
_prepare_test_db()
user_id = "11111111-1111-1111-1111-111111111111"
@@ -165,8 +150,7 @@ def test_create_project_successfully() -> None:
assert "id" in data
n@pytest.mark.integration
@pytest.mark.integration
def test_list_projects_returns_only_owned_projects() -> None:
_prepare_test_db()
user1_id = "11111111-1111-1111-1111-111111111111"
@@ -188,8 +172,7 @@ def test_list_projects_returns_only_owned_projects() -> None:
assert data[0]["name"] == "User1 Project"
n@pytest.mark.integration
@pytest.mark.integration
def test_update_project_requires_ownership() -> None:
_prepare_test_db()
owner_id = "11111111-1111-1111-1111-111111111111"
@@ -208,8 +191,7 @@ def test_update_project_requires_ownership() -> None:
assert response.status_code == 403
n@pytest.mark.integration
@pytest.mark.integration
def test_update_project_successfully() -> None:
_prepare_test_db()
owner_id = "11111111-1111-1111-1111-111111111111"
@@ -228,8 +210,7 @@ def test_update_project_successfully() -> None:
assert data["name"] == "Updated Name"
n@pytest.mark.integration
@pytest.mark.integration
def test_delete_project_requires_ownership() -> None:
_prepare_test_db()
owner_id = "11111111-1111-1111-1111-111111111111"
@@ -248,8 +229,7 @@ def test_delete_project_requires_ownership() -> None:
assert response.status_code == 403
n@pytest.mark.integration
@pytest.mark.integration
def test_delete_project_successfully() -> None:
_prepare_test_db()
owner_id = "11111111-1111-1111-1111-111111111111"
@@ -266,8 +246,7 @@ def test_delete_project_successfully() -> None:
assert response.status_code == 204
n@pytest.mark.integration
@pytest.mark.integration
def test_set_default_ssh_key_requires_ownership() -> None:
_prepare_test_db()
owner_id = "11111111-1111-1111-1111-111111111111"