22bc24b6b6
The CI failure resolving 'postgres' hostname was the symptom; the cause is that the workflow violated FabledRulebook/forgejo.md's "CI philosophy — lint + short unit tests only" rule. Integration tests against a real Postgres are supposed to run locally via docker-compose, not in CI. Changes: - Marked 8 DB-dependent test files with @pytest.mark.integration: test_tag_service, test_importer, test_gallery_service, test_api_gallery, test_api_tags, test_api_settings, test_api_import_admin, test_maintenance. - CI workflow drops the postgres/redis service containers and the alembic upgrade smoke step entirely. - Pytest invocation in CI changes to `pytest -v -m "not integration"`. - Added pytest marker registration to pyproject.toml. - DB_PASSWORD and SECRET_KEY env vars retained because config.py reads them at import time even though unit tests don't actually use them (set to placeholder values). What CI now runs: - ruff check - pytest on the 6 unit test files: test_slug, test_paths, test_migration_0002, test_thumbnailer, test_celery_smoke, test_tasks_register. - npm install + npm run build What CI no longer runs: - alembic upgrade (no live DB) - the 8 integration test files (these run locally via docker-compose) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
2.6 KiB
Python
93 lines
2.6 KiB
Python
from datetime import UTC, datetime, timedelta
|
|
|
|
import pytest
|
|
|
|
from backend.app import create_app
|
|
from backend.app.celery_app import celery
|
|
from backend.app.models import ImportBatch, ImportTask
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def eager():
|
|
celery.conf.task_always_eager = True
|
|
yield
|
|
celery.conf.task_always_eager = False
|
|
|
|
|
|
@pytest.fixture
|
|
async def app():
|
|
return create_app()
|
|
|
|
|
|
@pytest.fixture
|
|
async def client(app):
|
|
async with app.test_client() as c:
|
|
yield c
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_trigger_rejects_unknown_mode(client):
|
|
resp = await client.post("/api/import/trigger", json={"mode": "deep"})
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_status_when_idle(client):
|
|
resp = await client.get("/api/import/status")
|
|
body = await resp.get_json()
|
|
assert body["active_batch"] is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_tasks_with_status_filter(client, db):
|
|
batch = ImportBatch(triggered_by="manual", source_path="/import", scan_mode="quick")
|
|
db.add(batch)
|
|
await db.flush()
|
|
for status in ("complete", "failed", "complete"):
|
|
db.add(ImportTask(
|
|
batch_id=batch.id, source_path="/x", task_type="media", status=status,
|
|
finished_at=datetime.now(UTC),
|
|
))
|
|
await db.commit()
|
|
|
|
resp = await client.get("/api/import/tasks?status=failed")
|
|
body = await resp.get_json()
|
|
assert len(body["tasks"]) == 1
|
|
assert body["tasks"][0]["status"] == "failed"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_retry_failed(client, db):
|
|
batch = ImportBatch(triggered_by="manual", source_path="/import", scan_mode="quick")
|
|
db.add(batch)
|
|
await db.flush()
|
|
db.add(ImportTask(batch_id=batch.id, source_path="/x", task_type="media", status="failed"))
|
|
await db.commit()
|
|
|
|
resp = await client.post("/api/import/retry-failed")
|
|
body = await resp.get_json()
|
|
assert body["retried"] == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_clear_completed(client, db):
|
|
batch = ImportBatch(triggered_by="manual", source_path="/import", scan_mode="quick")
|
|
db.add(batch)
|
|
await db.flush()
|
|
long_ago = datetime.now(UTC) - timedelta(days=30)
|
|
db.add(ImportTask(
|
|
batch_id=batch.id, source_path="/x", task_type="media",
|
|
status="complete", finished_at=long_ago,
|
|
))
|
|
db.add(ImportTask(
|
|
batch_id=batch.id, source_path="/y", task_type="media",
|
|
status="complete", finished_at=datetime.now(UTC),
|
|
))
|
|
await db.commit()
|
|
|
|
resp = await client.post("/api/import/clear-completed", json={"age_days": 7})
|
|
body = await resp.get_json()
|
|
assert body["deleted"] == 1
|