Fix: iot:UpdateThingShadow does not properly maintain state document (#4045)
Device shadow updates affect only the fields specified in the request state document. Any field with a value of null is removed from the device's shadow.[1] Verified behavior against a real AWS backend. [1]: https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-rest-api.html#API_UpdateThingShadow
This commit is contained in:
parent
70a7a7e0a0
commit
163ae322e8
3 changed files with 68 additions and 7 deletions
|
|
@ -109,3 +109,41 @@ def test_update():
|
|||
def test_publish():
|
||||
client = boto3.client("iot-data", region_name="ap-northeast-1")
|
||||
client.publish(topic="test/topic", qos=1, payload=b"")
|
||||
|
||||
|
||||
@mock_iot
|
||||
@mock_iotdata
|
||||
def test_delete_field_from_device_shadow():
|
||||
test_thing_name = "TestThing"
|
||||
|
||||
iot_raw_client = boto3.client("iot", region_name="eu-central-1")
|
||||
iot_raw_client.create_thing(thingName=test_thing_name)
|
||||
iot = boto3.client("iot-data", region_name="eu-central-1")
|
||||
|
||||
iot.update_thing_shadow(
|
||||
thingName=test_thing_name,
|
||||
payload=json.dumps({"state": {"desired": {"state1": 1, "state2": 2}}}),
|
||||
)
|
||||
response = json.loads(
|
||||
iot.get_thing_shadow(thingName=test_thing_name)["payload"].read()
|
||||
)
|
||||
assert len(response["state"]["desired"]) == 2
|
||||
|
||||
iot.update_thing_shadow(
|
||||
thingName=test_thing_name,
|
||||
payload=json.dumps({"state": {"desired": {"state1": None}}}),
|
||||
)
|
||||
response = json.loads(
|
||||
iot.get_thing_shadow(thingName=test_thing_name)["payload"].read()
|
||||
)
|
||||
assert len(response["state"]["desired"]) == 1
|
||||
assert "state2" in response["state"]["desired"]
|
||||
|
||||
iot.update_thing_shadow(
|
||||
thingName=test_thing_name,
|
||||
payload=json.dumps({"state": {"desired": {"state2": None}}}),
|
||||
)
|
||||
response = json.loads(
|
||||
iot.get_thing_shadow(thingName=test_thing_name)["payload"].read()
|
||||
)
|
||||
assert "desired" not in response["state"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue