IOT: update_thing() now behaves correctly with merge=True (#6918)

This commit is contained in:
Nico Tonnhofer 2023-10-15 23:40:15 +02:00 committed by GitHub
parent 00cce90984
commit 5794b619e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 2 deletions

View File

@ -883,7 +883,8 @@ class IoTBackend(BaseBackend):
if not do_merge:
thing.attributes = attributes
else:
thing.attributes = {k: v for k, v in attributes.items() if v}
thing.attributes.update(attributes)
thing.attributes = {k: v for k, v in thing.attributes.items() if v}
def create_keys_and_certificate(
self, set_as_active: bool

View File

@ -52,7 +52,32 @@ def test_update_thing():
assert len(res["things"]) == 1
assert res["things"][0]["thingName"] is not None
assert res["things"][0]["thingArn"] is not None
assert res["things"][0]["attributes"]["k1"] == "v1"
assert res["things"][0]["attributes"] == {"k1": "v1"}
client.update_thing(thingName=name, attributePayload={"attributes": {"k2": "v2"}})
res = client.list_things()
assert len(res["things"]) == 1
assert res["things"][0]["thingName"] is not None
assert res["things"][0]["thingArn"] is not None
assert res["things"][0]["attributes"] == {"k2": "v2"}
client.update_thing(
thingName=name, attributePayload={"attributes": {"k1": "v1"}, "merge": True}
)
res = client.list_things()
assert len(res["things"]) == 1
assert res["things"][0]["thingName"] is not None
assert res["things"][0]["thingArn"] is not None
assert res["things"][0]["attributes"] == {"k1": "v1", "k2": "v2"}
client.update_thing(
thingName=name, attributePayload={"attributes": {"k1": "v1.1"}, "merge": True}
)
res = client.list_things()
assert len(res["things"]) == 1
assert res["things"][0]["thingName"] is not None
assert res["things"][0]["thingArn"] is not None
assert res["things"][0]["attributes"] == {"k1": "v1.1", "k2": "v2"}
client.update_thing(
thingName=name, attributePayload={"attributes": {"k1": ""}, "merge": True}
@ -61,6 +86,13 @@ def test_update_thing():
assert len(res["things"]) == 1
assert res["things"][0]["thingName"] is not None
assert res["things"][0]["thingArn"] is not None
assert res["things"][0]["attributes"] == {"k2": "v2"}
client.update_thing(thingName=name, attributePayload={"attributes": {"k2": ""}})
res = client.list_things()
assert len(res["things"]) == 1
assert res["things"][0]["thingName"] is not None
assert res["things"][0]["thingArn"] is not None
assert res["things"][0]["attributes"] == {}