diff --git a/moto/iot/models.py b/moto/iot/models.py index 33f3664c6..a27c7c1e8 100644 --- a/moto/iot/models.py +++ b/moto/iot/models.py @@ -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") diff --git a/tests/test_iot/test_iot_search.py b/tests/test_iot/test_iot_search.py index 72d596476..48f7ea165 100644 --- a/tests/test_iot/test_iot_search.py +++ b/tests/test_iot/test_iot_search.py @@ -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