http sender drops reply keys no output port declares
A sender without outputs no longer fails on a {"status": "ok"} reply.
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
import httpx
|
||||
|
||||
from fluksio.flow.messages import DType, MessageSpec
|
||||
from fluksio.flow.nodes import MqttNode
|
||||
from fluksio.flow.nodes import HttpNode, MqttNode
|
||||
from fluksio.flow.nodes.http import close_shared_client, shared_client
|
||||
|
||||
|
||||
@@ -20,6 +22,28 @@ def test_http_senders_share_one_pooled_client():
|
||||
close_shared_client()
|
||||
|
||||
|
||||
def test_an_http_reply_keeps_only_the_declared_ports(monkeypatch):
|
||||
"""A `status` beside the value is the endpoint's business, not an error."""
|
||||
reply = {"temp": 21.5, "status": "ok"}
|
||||
client = httpx.Client(
|
||||
transport=httpx.MockTransport(lambda _: httpx.Response(200, json=reply))
|
||||
)
|
||||
monkeypatch.setattr("fluksio.flow.nodes.http.shared_client", lambda: client)
|
||||
|
||||
def sender(*provides: MessageSpec) -> HttpNode:
|
||||
node = HttpNode(
|
||||
requires=[MessageSpec(name="setpoint", dtype=DType.FLOAT)],
|
||||
provides=provides,
|
||||
params={"url": "http://thermostat.test/set"},
|
||||
)
|
||||
node.assign_flow("heating", "thermostat")
|
||||
return node
|
||||
|
||||
temp = MessageSpec(name="temp", dtype=DType.FLOAT)
|
||||
assert sender(temp).execute({"heating.setpoint": 21.0}) == {"heating.temp": 21.5}
|
||||
assert sender().execute({"heating.setpoint": 21.0}) is None
|
||||
|
||||
|
||||
def _sender() -> MqttNode:
|
||||
node = MqttNode(
|
||||
requires=[MessageSpec(name="setpoint", port="setpoint", dtype=DType.FLOAT)],
|
||||
|
||||
Reference in New Issue
Block a user