From 104fcd8e752b28f2b85493e424216073f851ad7a Mon Sep 17 00:00:00 2001 From: audit-orchestrator Date: Thu, 21 May 2026 05:07:33 -0500 Subject: [PATCH] test(integration): align with v2.4.0 client-side limit validation + V1 batch typed responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two distinct breakages on the nightly run against demo: 1. test_malformed_params_returns_validation_error + test_validation_error_details_attribute used limit=-1 to trigger a server 400. W1-B (#214) added client-side _validate_limit which raises ValueError before the request reaches the server. Switched the trigger to a malformed cursor — the SDK forwards it verbatim and the server still returns 400. 2. test_batch_create_cancel (sync + async) asserted isinstance(orders, list). W1-B (#194) made batch_create return BatchCreateOrdersResponse. Tests now iterate response.orders[i].order, treat None .order as a failed leg, and reduce to successful order_ids for cleanup. Closes #237 --- tests/integration/test_errors.py | 12 ++++++++---- tests/integration/test_orders.py | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/integration/test_errors.py b/tests/integration/test_errors.py index a3317e49..fec109e7 100644 --- a/tests/integration/test_errors.py +++ b/tests/integration/test_errors.py @@ -40,10 +40,14 @@ def test_invalid_ticker_returns_not_found( def test_malformed_params_returns_validation_error( self, sync_client: KalshiClient ) -> None: - """Malformed request params should raise KalshiValidationError (400).""" - # Use an obviously invalid limit value + """Malformed request params should raise KalshiValidationError (400). + + Uses a malformed cursor — the SDK passes it verbatim to the server, + which rejects it with a 400. (Numeric range checks like negative + limit are now enforced client-side via ValueError per #214.) + """ with pytest.raises(KalshiValidationError) as exc_info: - sync_client.markets.list(limit=-1) + sync_client.markets.list(cursor="!!!not-a-valid-cursor!!!") exc = exc_info.value assert exc.status_code == 400 @@ -98,7 +102,7 @@ def test_validation_error_details_attribute( ) -> None: """KalshiValidationError should have a details attribute (may be None or dict).""" with pytest.raises(KalshiValidationError) as exc_info: - sync_client.markets.list(limit=-1) + sync_client.markets.list(cursor="!!!not-a-valid-cursor!!!") exc = exc_info.value assert hasattr(exc, "details") diff --git a/tests/integration/test_orders.py b/tests/integration/test_orders.py index f9e176f2..d27dafcf 100644 --- a/tests/integration/test_orders.py +++ b/tests/integration/test_orders.py @@ -193,14 +193,15 @@ def test_batch_create_cancel( for i in range(2) ] - orders = sync_client.orders.batch_create(requests) - assert isinstance(orders, list) - assert len(orders) > 0 - for o in orders: + response = sync_client.orders.batch_create(requests) + assert len(response.orders) > 0 + successful = [e.order for e in response.orders if e.order is not None] + assert successful, f"All legs failed: {response.orders}" + for o in successful: assert isinstance(o, Order) assert_model_fields(o) - order_ids = [o.order_id for o in orders] + order_ids = [o.order_id for o in successful] try: sync_client.orders.batch_cancel(order_ids) except Exception: @@ -306,14 +307,15 @@ async def test_batch_create_cancel( for i in range(2) ] - orders = await async_client.orders.batch_create(requests) - assert isinstance(orders, list) - assert len(orders) > 0 - for o in orders: + response = await async_client.orders.batch_create(requests) + assert len(response.orders) > 0 + successful = [e.order for e in response.orders if e.order is not None] + assert successful, f"All legs failed: {response.orders}" + for o in successful: assert isinstance(o, Order) assert_model_fields(o) - order_ids = [o.order_id for o in orders] + order_ids = [o.order_id for o in successful] try: await async_client.orders.batch_cancel(order_ids) except Exception: