standardize packaging, tooling, docs, CI, and licensing
This commit is contained in:
63
tests/test_loader.py
Normal file
63
tests/test_loader.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""Smoke tests for openapi_first.loader."""
|
||||
|
||||
import pytest
|
||||
|
||||
from openapi_first.loader import OpenAPISpecLoadError, load_openapi
|
||||
|
||||
|
||||
def test_load_openapi_json(spec_file, minimal_spec):
|
||||
path = spec_file("openapi.json")
|
||||
spec = load_openapi(path)
|
||||
assert spec == minimal_spec
|
||||
|
||||
|
||||
def test_load_openapi_yaml(spec_file, minimal_spec):
|
||||
path = spec_file("openapi.yaml")
|
||||
spec = load_openapi(path)
|
||||
assert spec == minimal_spec
|
||||
|
||||
|
||||
def test_load_missing_file(tmp_path):
|
||||
with pytest.raises(OpenAPISpecLoadError):
|
||||
load_openapi(tmp_path / "missing.json")
|
||||
|
||||
|
||||
def test_load_unsupported_extension(tmp_path):
|
||||
path = tmp_path / "openapi.txt"
|
||||
path.write_text("{}", encoding="utf-8")
|
||||
with pytest.raises(OpenAPISpecLoadError):
|
||||
load_openapi(path)
|
||||
|
||||
|
||||
def test_load_invalid_spec(tmp_path):
|
||||
path = tmp_path / "invalid.yaml"
|
||||
path.write_text("not: [valid: openapi", encoding="utf-8")
|
||||
with pytest.raises(OpenAPISpecLoadError):
|
||||
load_openapi(path)
|
||||
|
||||
|
||||
def test_load_validation_failure(tmp_path):
|
||||
path = tmp_path / "bad.yaml"
|
||||
path.write_text("openapi: 3.0.3\ninfo: {}\n", encoding="utf-8")
|
||||
with pytest.raises(OpenAPISpecLoadError):
|
||||
load_openapi(path)
|
||||
|
||||
|
||||
def test_env_var_resolution(spec_file, monkeypatch):
|
||||
monkeypatch.setenv("AUTH_HOST", "http://auth.internal")
|
||||
spec = {
|
||||
"openapi": "3.0.3",
|
||||
"info": {"title": "Env API", "version": "1.0.0"},
|
||||
"servers": [{"url": "{AUTH_HOST}/v1"}],
|
||||
"paths": {
|
||||
"/ping": {
|
||||
"get": {
|
||||
"operationId": "get_ping",
|
||||
"responses": {"200": {"description": "OK"}},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
path = spec_file("env.yaml", spec)
|
||||
loaded = load_openapi(path)
|
||||
assert loaded["servers"][0]["url"] == "{AUTH_HOST}/v1"
|
||||
Reference in New Issue
Block a user