Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tests/integration/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
22 changes: 12 additions & 10 deletions tests/integration/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Loading