fix(client-python): keepalive options, typed error mapping with status code, open-enum names, malformed-reply checks (CPY-001..004, #257)
This commit is contained in:
@@ -110,3 +110,56 @@ async def test_authenticate_user_echoed_credential_is_scrubbed(fixture: str) ->
|
||||
assert credential not in exc.raw_reply.diagnostic_message
|
||||
for status in exc.raw_reply.statuses:
|
||||
assert credential not in status.diagnostic_text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("kind", "call"),
|
||||
[
|
||||
(pb.MX_COMMAND_KIND_REGISTER, lambda s: s.register("client")),
|
||||
(pb.MX_COMMAND_KIND_ADD_ITEM, lambda s: s.add_item(1, "Tag")),
|
||||
(pb.MX_COMMAND_KIND_ADD_ITEM2, lambda s: s.add_item2(1, "Tag", "ctx")),
|
||||
(pb.MX_COMMAND_KIND_SUBSCRIBE_BULK, lambda s: s.subscribe_bulk(1, ["Tag"])),
|
||||
(pb.MX_COMMAND_KIND_READ_BULK, lambda s: s.read_bulk(1, ["Tag"])),
|
||||
(pb.MX_COMMAND_KIND_DRAIN_EVENTS, lambda s: s.drain_events(10)),
|
||||
],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_and_bulk_helpers_raise_on_reply_without_payload(kind, call) -> None:
|
||||
"""CPY-004: an OK reply with no payload must not read as handle 0 / an empty list."""
|
||||
reply = pb.MxCommandReply(
|
||||
session_id="session-1",
|
||||
kind=kind,
|
||||
protocol_status=pb.ProtocolStatus(code=pb.PROTOCOL_STATUS_CODE_OK),
|
||||
)
|
||||
session, _ = await _session_with([reply])
|
||||
|
||||
with pytest.raises(MalformedReplyError) as captured:
|
||||
await call(session)
|
||||
|
||||
assert captured.value.raw_reply is reply
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register_falls_back_to_return_value_int32() -> None:
|
||||
reply = pb.MxCommandReply(
|
||||
session_id="session-1",
|
||||
kind=pb.MX_COMMAND_KIND_REGISTER,
|
||||
protocol_status=pb.ProtocolStatus(code=pb.PROTOCOL_STATUS_CODE_OK),
|
||||
return_value=pb.MxValue(int32_value=5),
|
||||
)
|
||||
session, _ = await _session_with([reply])
|
||||
|
||||
assert await session.register("client") == 5
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_empty_bulk_payload_is_a_valid_empty_result() -> None:
|
||||
reply = pb.MxCommandReply(
|
||||
session_id="session-1",
|
||||
kind=pb.MX_COMMAND_KIND_DRAIN_EVENTS,
|
||||
protocol_status=pb.ProtocolStatus(code=pb.PROTOCOL_STATUS_CODE_OK),
|
||||
drain_events=pb.DrainEventsReply(),
|
||||
)
|
||||
session, _ = await _session_with([reply])
|
||||
|
||||
assert await session.drain_events(10) == []
|
||||
|
||||
Reference in New Issue
Block a user