Set CRM order status to PACKED after Checkbox accepts the receipt
- ExoCrmClient.set_status: live SetStatus needs {Orders: [id], Status} and
replies per order, unlike the documented {ID, Status}
- receipts.crm_status_set_at (migration 0006); set right after creation,
retried by cron, row-locked to avoid a repeat PACKED overwriting a newer status
- CRM errors under capitalized 'Errors' and non-JSON replies are reported
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -106,3 +106,43 @@ class TestExoCrmClientGetOrders:
|
||||
|
||||
with pytest.raises(CrmError, match="Checksum Error"):
|
||||
await client.get_orders(status="APPROVED")
|
||||
|
||||
|
||||
class TestExoCrmClientSetStatus:
|
||||
@respx.mock
|
||||
async def test_sends_order_list_and_parses_per_order_result(self) -> None:
|
||||
import json
|
||||
|
||||
route = respx.post(BASE_URL).mock(
|
||||
return_value=Response(
|
||||
200,
|
||||
json={
|
||||
"<": "<",
|
||||
"123901": {"Status": "Success", "ChangeStatus": "Success"},
|
||||
">": ">",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
await ExoCrmClient(_settings()).set_status(order_id="123901", status="PACKED")
|
||||
|
||||
body = json.loads(route.calls.last.request.content)
|
||||
assert body["object"] == "Orders"
|
||||
assert body["method"] == "SetStatus"
|
||||
# Не {"ID": ...} из документации — боевая CRM принимает только список в Orders.
|
||||
assert body["params"] == {"Orders": ["123901"], "Status": "PACKED"}
|
||||
assert "md5sum" in body
|
||||
|
||||
@respx.mock
|
||||
async def test_raises_on_capitalized_errors(self) -> None:
|
||||
respx.post(BASE_URL).mock(
|
||||
return_value=Response(200, json={"<": "<", "Errors": ["Undefined order list."]})
|
||||
)
|
||||
with pytest.raises(CrmError, match="Undefined order list"):
|
||||
await ExoCrmClient(_settings()).set_status(order_id="1", status="PACKED")
|
||||
|
||||
@respx.mock
|
||||
async def test_raises_on_non_json_reply(self) -> None:
|
||||
respx.post(BASE_URL).mock(return_value=Response(200, text="<b>Notice</b>: ..."))
|
||||
with pytest.raises(CrmError, match="не JSON"):
|
||||
await ExoCrmClient(_settings()).set_status(order_id="1", status="PACKED")
|
||||
|
||||
Reference in New Issue
Block a user