import json import pytest from ontorefactor_governance.service import GovernanceError from ontorefactor_governance.source_upload import MAX_SOURCE_BYTES, prepare_uploaded_source def test_auto_detects_openapi_yaml_and_inventory_json(): openapi = prepare_uploaded_source( "contract.yaml", b"openapi: 3.0.3\npaths:\n /health:\n get:\n operationId: health\n", ) assert openapi["source_type"] == "openapi" assert openapi["detected"]["apis"] == 1 inventory_content = json.dumps({"tables": [{"schema": "crm", "name": "customer", "columns": []}]}) inventory = prepare_uploaded_source("assets.json", inventory_content.encode()) assert inventory["source_type"] == "inventory" assert inventory["detected"]["tables"] == 1 def test_inventory_yaml_and_upload_limits_are_supported(): inventory = prepare_uploaded_source( "assets.yml", b"tables:\n - schema: crm\n name: customer\n columns: []\napis: []\nschemas: []\n", ) assert inventory["source_type"] == "inventory" with pytest.raises(GovernanceError) as exc: prepare_uploaded_source("too-large.sql", b"x" * (MAX_SOURCE_BYTES + 1), "ddl") assert exc.value.code == "SOURCE_TOO_LARGE"