84 lines
2.3 KiB
Python
84 lines
2.3 KiB
Python
"""Tests for the 6 new GET endpoints."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from cyclone.api import app
|
|
from cyclone.store import store as global_store
|
|
|
|
FIXTURE_837 = Path(__file__).parent / "fixtures" / "co_medicaid_837p.txt"
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def clear_store():
|
|
with global_store._lock:
|
|
global_store._batches.clear()
|
|
yield
|
|
with global_store._lock:
|
|
global_store._batches.clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def client() -> TestClient:
|
|
return TestClient(app)
|
|
|
|
|
|
@pytest.fixture
|
|
def seeded_store():
|
|
"""One parsed 837P fixture batch."""
|
|
text = FIXTURE_837.read_text()
|
|
client = TestClient(app)
|
|
client.post(
|
|
"/api/parse-837",
|
|
files={"file": ("x.txt", text, "text/plain")},
|
|
headers={"Accept": "application/json"},
|
|
)
|
|
return client
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# /api/batches
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
|
|
def test_batches_returns_empty_list_when_no_parses(client: TestClient):
|
|
resp = client.get("/api/batches")
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert body == {"items": [], "total": 0, "returned": 0, "has_more": False}
|
|
|
|
|
|
def test_batches_returns_summary_after_parse(seeded_store):
|
|
resp = seeded_store.get("/api/batches")
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert body["total"] == 1
|
|
assert body["returned"] == 1
|
|
assert body["items"][0]["kind"] == "837p"
|
|
assert body["items"][0]["inputFilename"] == "x.txt"
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# /api/batches/{id}
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
|
|
def test_get_batch_by_id_returns_full_result(seeded_store):
|
|
batches = seeded_store.get("/api/batches").json()["items"]
|
|
bid = batches[0]["id"]
|
|
resp = seeded_store.get(f"/api/batches/{bid}")
|
|
assert resp.status_code == 200
|
|
body = resp.json()
|
|
assert "envelope" in body
|
|
assert "claims" in body
|
|
assert len(body["claims"]) == 2
|
|
|
|
|
|
def test_get_batch_404_when_missing(client: TestClient):
|
|
resp = client.get("/api/batches/does-not-exist")
|
|
assert resp.status_code == 404
|