Skip to content

Commit

Permalink
adding page support for search api
Browse files Browse the repository at this point in the history
  • Loading branch information
vbichov authored and amotl committed Oct 13, 2024
1 parent 5e30c8c commit c6c7907
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions grafana_client/elements/_async/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def search_dashboards(
folder_uids=None,
starred=None,
limit=None,
page=None,
):
"""
Expand All @@ -31,6 +32,7 @@ async def search_dashboards(
:param folder_uids:
:param starred:
:param limit:
:param page:
:return:
"""
list_dashboard_path = "/search"
Expand Down Expand Up @@ -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)
5 changes: 5 additions & 0 deletions grafana_client/elements/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def search_dashboards(
folder_uids=None,
starred=None,
limit=None,
page=None,
):
"""
Expand All @@ -31,6 +32,7 @@ def search_dashboards(
:param folder_uids:
:param starred:
:param limit:
:param page:
:return:
"""
list_dashboard_path = "/search"
Expand Down Expand Up @@ -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)
26 changes: 26 additions & 0 deletions test/elements/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c6c7907

Please sign in to comment.