Skip to content

Commit 6f3c530

Browse files
authored
fix: Adjust the tests (#51)
1 parent b307f89 commit 6f3c530

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ The core features that are implemented inside this library:
1313

1414
In general, my focus on this project is to implement and deliver old and new features from the Grafana API, to document all features and functionality clear,ly and to increase the overall test coverage of the project.
1515

16+
## TODO
17+
- [ ] [Team Sync](https://grafana.com/docs/grafana/latest/developers/http_api/team_sync/)
18+
- [ ] [Public Dashboard](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard_public/)
19+
1620
## Currently, supported features
1721

1822
### Dashboard

grafana_api/folder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import json
33

4+
import httpx
5+
46
from .api import Api
57
from .model import APIModel, APIEndpoints, RequestsMethods
68

@@ -132,7 +134,7 @@ def create_folder(self, title: str, uid: str = None) -> dict:
132134
raise ValueError
133135

134136
def update_folder(
135-
self, title: str, uid: str, version: int = 0, overwrite: bool = False
137+
self, title: str, uid: str, version: int = 0, overwrite: bool = False
136138
) -> dict:
137139
"""The method includes a functionality to update a folder information inside the organization specified by the uid, the title, the version of the folder or if folder information be overwritten
138140
@@ -197,7 +199,10 @@ def delete_folder(self, uid: str):
197199
RequestsMethods.DELETE,
198200
)
199201

200-
if api_call.status_code != 200:
202+
if isinstance(api_call, dict) and api_call.get("message") != "Folder deleted":
203+
logging.error(f"Please, check the error: {api_call}.")
204+
raise Exception
205+
elif isinstance(api_call, httpx.Response) and api_call.status_code != 200:
201206
logging.error(f"Please, check the error: {api_call}.")
202207
raise Exception
203208
else:

tests/integrationtest/test_organisation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ def test_a_add_new_user_to_current_organization(self):
5555
organisation_users: list = (
5656
self.organisation.get_all_users_by_the_current_organization_lookup()
5757
)
58-
self.assertEqual("Test", organisation_users[1].get("login"))
58+
self.assertEqual("Test", organisation_users[2].get("login"))
5959

6060
def test_b_update_organization_user_role_by_user_id(self):
6161
self.organisation.update_organization_user_role_by_user_id(7, "Editor")
6262

6363
organisation_users: list = (
6464
self.organisation.get_all_users_by_the_current_organization()
6565
)
66-
self.assertEqual(7, organisation_users[1].get("userId"))
67-
self.assertEqual("Editor", organisation_users[1].get("role"))
66+
self.assertEqual(7, organisation_users[2].get("userId"))
67+
self.assertEqual("Editor", organisation_users[2].get("role"))
6868

6969
def test_c_delete_organization_user_by_user_id(self):
7070
self.organisation.delete_organization_user_by_user_id(7)

tests/integrationtest/test_playlist.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ def test_get_playlist(self):
2222

2323
def test_get_playlist_items(self):
2424
self.assertEqual(
25-
"653", self.playlist.get_playlist_items("PgorUJA4z")[0].get("value")
26-
)
27-
28-
def test_get_playlist_dashboards(self):
29-
self.assertEqual(
30-
653, self.playlist.get_playlist_dashboards("PgorUJA4z")[0].get("id")
25+
"tests", self.playlist.get_playlist_items("PgorUJA4z")[0].get("value")
3126
)
3227

3328
def test_a_create_playlist(self):

tests/unittests/test_folder.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from unittest import TestCase
22
from unittest.mock import MagicMock, patch
33

4+
import httpx
5+
46
from grafana_api.model import APIModel
57
from grafana_api.folder import Folder
68

@@ -191,6 +193,15 @@ def test_delete_folder(self, call_the_api_mock):
191193

192194
self.assertEqual(None, folder.delete_folder("test"))
193195

196+
@patch("grafana_api.api.Api.call_the_api")
197+
def test_delete_folder_right_message(self, call_the_api_mock):
198+
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
199+
folder: Folder = Folder(grafana_api_model=model)
200+
201+
call_the_api_mock.return_value = dict({"message": "Folder deleted"})
202+
203+
self.assertEqual(None, folder.delete_folder("test"))
204+
194205
@patch("grafana_api.api.Api.call_the_api")
195206
def test_delete_folder_no_uid(self, call_the_api_mock):
196207
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
@@ -202,11 +213,21 @@ def test_delete_folder_no_uid(self, call_the_api_mock):
202213
folder.delete_folder("")
203214

204215
@patch("grafana_api.api.Api.call_the_api")
205-
def test_delete_folder_error_response(self, call_the_api_mock):
216+
def test_delete_folder_error_response_wrong_object(self, call_the_api_mock):
206217
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
207218
folder: Folder = Folder(grafana_api_model=model)
208219

209-
call_the_api_mock.return_value.status_code = 404
220+
call_the_api_mock.return_value = httpx.Response(404)
221+
222+
with self.assertRaises(Exception):
223+
folder.delete_folder("test")
224+
225+
@patch("grafana_api.api.Api.call_the_api")
226+
def test_delete_folder_error_response_wrong_message(self, call_the_api_mock):
227+
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
228+
folder: Folder = Folder(grafana_api_model=model)
229+
230+
call_the_api_mock.return_value = dict({"message": "test"})
210231

211232
with self.assertRaises(Exception):
212233
folder.delete_folder("test")

0 commit comments

Comments
 (0)