From c6c7907b63386c3c8f563427bd83c326e623d7e1 Mon Sep 17 00:00:00 2001 From: Vitaly Bihov Date: Sun, 13 Oct 2024 12:34:06 +0300 Subject: [PATCH] adding page support for search api --- grafana_client/elements/_async/search.py | 5 +++++ grafana_client/elements/search.py | 5 +++++ test/elements/test_search.py | 26 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/grafana_client/elements/_async/search.py b/grafana_client/elements/_async/search.py index 1d50e98..7dc5aba 100644 --- a/grafana_client/elements/_async/search.py +++ b/grafana_client/elements/_async/search.py @@ -19,6 +19,7 @@ async def search_dashboards( folder_uids=None, starred=None, limit=None, + page=None, ): """ @@ -31,6 +32,7 @@ async def search_dashboards( :param folder_uids: :param starred: :param limit: + :param page: :return: """ list_dashboard_path = "/search" @@ -63,4 +65,7 @@ async def search_dashboards( if limit: params["limit"] = limit + if page: + params["page"] = page + return await self.client.GET(list_dashboard_path, params=params) diff --git a/grafana_client/elements/search.py b/grafana_client/elements/search.py index b73347b..6c9da60 100644 --- a/grafana_client/elements/search.py +++ b/grafana_client/elements/search.py @@ -19,6 +19,7 @@ def search_dashboards( folder_uids=None, starred=None, limit=None, + page=None, ): """ @@ -31,6 +32,7 @@ def search_dashboards( :param folder_uids: :param starred: :param limit: + :param page: :return: """ list_dashboard_path = "/search" @@ -63,4 +65,7 @@ def search_dashboards( if limit: params["limit"] = limit + if page: + params["page"] = page + return self.client.GET(list_dashboard_path, params=params) diff --git a/test/elements/test_search.py b/test/elements/test_search.py index 7237869..b17257c 100644 --- a/test/elements/test_search.py +++ b/test/elements/test_search.py @@ -51,3 +51,29 @@ def test_search_dashboards_with_out_filter(self, m): with self.assertRaises(GrafanaBadInputError): self.grafana.search.search_dashboards() + + @requests_mock.Mocker() + def test_search_dashboards_with_page(self, m): + m.get( + "http://localhost/api/search?page=1", + json=[ + { + "id": 2307, + "uid": "LfQAz3t4z1DSA", + "title": "ERRORS", + "uri": "db/errors", + "url": "/d/LfQAz3t4z1DSA/errors", + "slug": "", + "type": "dash-db", + "tags": [], + "isStarred": False, + "sortMeta": 0, + } + ], + ) + + result = self.grafana.search.search_dashboards( + page=1, + ) + self.assertEqual(result[0]["id"], 2307) + self.assertEqual(len(result), 1)