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