IOT: search_index() now returns the connectivity-attribute (#6535)

This commit is contained in:
Bert Blommers 2023-07-19 09:36:55 +00:00 committed by GitHub
parent cdcf356424
commit 1aa8e7a7b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -59,7 +59,11 @@ class FakeThing(BaseModel):
return self.attributes.get(k) == v
return query_string in self.thing_name
def to_dict(self, include_default_client_id: bool = False) -> Dict[str, Any]:
def to_dict(
self,
include_default_client_id: bool = False,
include_connectivity: bool = False,
) -> Dict[str, Any]:
obj = {
"thingName": self.thing_name,
"thingArn": self.arn,
@ -70,6 +74,11 @@ class FakeThing(BaseModel):
obj["thingTypeName"] = self.thing_type.thing_type_name
if include_default_client_id:
obj["defaultClientId"] = self.thing_name
if include_connectivity:
obj["connectivity"] = {
"connected": True,
"timestamp": time.mktime(datetime.utcnow().timetuple()),
}
return obj
@ -1855,7 +1864,7 @@ class IoTBackend(BaseBackend):
things = [
thing for thing in self.things.values() if thing.matches(query_string)
]
return [t.to_dict() for t in things]
return [t.to_dict(include_connectivity=True) for t in things]
iot_backends = BackendDict(IoTBackend, "iot")

View File

@ -22,11 +22,15 @@ def test_search_things(query_string, results):
client.create_thing(thingName=name)
resp = client.search_index(queryString=query_string)
resp.should.have.key("thingGroups").equals([])
resp.should.have.key("things").length_of(len(results))
assert resp["thingGroups"] == []
assert len(resp["things"]) == len(results)
thing_names = [t["thingName"] for t in resp["things"]]
set(thing_names).should.equal(results)
assert set(thing_names) == results
for thing in resp["things"]:
del thing["connectivity"]["timestamp"]
assert thing["connectivity"] == {"connected": True}
@mock_iot