Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding page support for search api #188

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)