sbom-nexus/tests/test_postgres_integration.py
tegwick ba535e1f8f feat: prepare postgres sbom cutover
Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a028f0-a42f-7582-89a8-ebaad7343834
2026-08-22 13:14:24 +02:00

52 lines
1.4 KiB
Python

from __future__ import annotations
import os
import pytest
from fastapi.testclient import TestClient
from sbom_nexus.api import create_app
POSTGRES_URL = os.getenv("SBOM_NEXUS_TEST_POSTGRES_URL")
pytestmark = pytest.mark.skipif(
not POSTGRES_URL,
reason="SBOM_NEXUS_TEST_POSTGRES_URL is not configured",
)
def test_migrated_postgres_runtime_contract() -> None:
assert POSTGRES_URL is not None
client = TestClient(create_app(POSTGRES_URL))
assert client.get("/state/health").json() == {
"status": "ok",
"store": "connected",
"dialect": "postgresql",
}
response = client.put(
"/repositories/postgres-contract",
json={"active": True},
)
assert response.status_code == 200
ingest = client.post(
"/sbom/ingest/",
json={
"repo_slug": "postgres-contract",
"entries": [
{
"package_name": "psycopg",
"package_version": "3.2",
"ecosystem": "python",
"license_spdx": "LGPL-3.0-only",
"is_direct": True,
"is_dev": False,
}
],
},
)
assert ingest.status_code == 200
assert ingest.json()["ingested"] == 1
assert client.get("/sbom/postgres-contract").json()["entry_count"] == 1
assert client.get("/sbom/report/licences/").json()["copyleft_direct_count"] == 1