Skip to content

Commit

Permalink
Fix call_api to use serial number properly (#143)
Browse files Browse the repository at this point in the history
In the migration from `send_api_request` to `invoke_api`, I accidentally dropped
the serial number. This PR fixes that, and adds a test to enforce it.
  • Loading branch information
jkeljo authored May 14, 2023
1 parent 35a4040 commit f02e705
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion siobrultech_protocols/gem/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def call_api(

async def send(arg: T) -> R:
future = asyncio.get_event_loop().create_future()
protocol.invoke_api(api, arg, future)
protocol.invoke_api(api, arg, future, serial_number)
return await asyncio.wait_for(future, timeout=timeout.total_seconds())

delay = protocol.begin_api_request()
Expand Down
9 changes: 9 additions & 0 deletions tests/gem/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ async def testApiCall(self):
response = await f(None)
self.assertEqual(response, "RESPONSE")

async def testApiCallWithSerialNumber(self):
call = ApiCall(lambda _: "^^^REQUEST", lambda response: response, None, None)
async with call_api(call, self._protocol, serial_number=1234567) as f:
self.setApiResponse("RESPONSE".encode())
response = await f(None)
self.assertEqual(response, "RESPONSE")

self.assertEqual(self._transport.writes, [b"^^^SYSPDL", b"^^^NMB34567REQUEST"])

async def testTaskCanceled(self):
call = ApiCall(lambda _: "REQUEST", lambda response: response, None, None)
with self.assertRaises(asyncio.CancelledError):
Expand Down

0 comments on commit f02e705

Please sign in to comment.