IOT: update_thing() now behaves correctly with merge=True (#6918)
This commit is contained in:
parent
00cce90984
commit
5794b619e2
@ -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
|
||||
|
@ -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"] == {}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user