From fedc4efc8d2ca80dd08b00fce3c8dac0e6f78679 Mon Sep 17 00:00:00 2001 From: Jackie Muya Date: Wed, 18 Nov 2026 11:20:44 +0300 Subject: [PATCH] test: cover malformed export responses --- tests/test_http.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_http.py b/tests/test_http.py index c9c4a2de..a4c45e1b 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -1643,6 +1643,38 @@ def respond(request: Request, index: int) -> Reply: assert caught.value.status == 404 +@MODES +async def test_malformed_export_response_raises_invalid_response(mode: str) -> None: + def respond(request: Request, index: int) -> Reply: + assert request.path.startswith( + f"/api/v1/organizations/{ORG}/exports/findings?" + ) + return Reply( + body=b'{"dataset_version": 1, "claim": ', + headers={ + "Content-Type": "application/x-ndjson", + "X-Proofline-Export-Version": "1", + "X-Proofline-Export-Settled-Until": "2026-10-25T00:00:00Z", + }, + ) + + with Server(respond) as server: + async with session(mode, server.url) as client: + with pytest.raises(ProoflineError) as raised: + await call( + client, + "export_reviews", + ORG, + "findings", + from_time="2026-10-01T00:00:00Z", + to_time="2026-10-25T00:00:00Z", + format="ndjson", + ) + + assert raised.value.status == 200 + assert raised.value.type == "urn:proofline:sdk:invalid-response" + + @MODES @pytest.mark.parametrize("format", ["csv", "ndjson"]) async def test_review_export_retains_every_recorded_kind(mode: str, format: str) -> None: