IOT: search_index() now returns the connectivity-attribute (#6535)
This commit is contained in:
parent
cdcf356424
commit
1aa8e7a7b2
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user