Skip to content

Commit e1b3c6a

Browse files
authored
fix: Adjust the get_user_teams functionality (#114)
1 parent 4ed6724 commit e1b3c6a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Diff for: grafana_api/user.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def get_user_teams(self, id: int) -> list:
275275
f"{APIEndpoints.USERS.value}/{id}/teams",
276276
)
277277

278-
if api_call == list() or api_call[0].get("id") is None:
278+
if api_call != list() and api_call[0].get("id") is None:
279279
logging.error(f"Check the error: {api_call}.")
280280
raise Exception
281281
else:
@@ -459,7 +459,7 @@ def get_user_teams(self) -> list:
459459
f"{APIEndpoints.USER.value}/teams",
460460
)
461461

462-
if api_call == list() or api_call[0].get("id") is None:
462+
if api_call != list() and api_call[0].get("id") is None:
463463
logging.error(f"Check the error: {api_call}.")
464464
raise Exception
465465
else:

Diff for: tests/unittests/test_user.py

+20
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ def test_get_user_teams_no_teams(self, call_the_api_mock):
274274

275275
call_the_api_mock.return_value = list()
276276

277+
self.assertEqual(list(), user.get_user_teams(1))
278+
279+
@patch("grafana_api.api.Api.call_the_api")
280+
def test_get_user_teams_invalid_teams(self, call_the_api_mock):
281+
model: APIModel = APIModel(
282+
host=MagicMock(), username=MagicMock(), password=MagicMock()
283+
)
284+
user: User = User(grafana_api_model=model)
285+
286+
call_the_api_mock.return_value = list([{"id": None}])
287+
277288
with self.assertRaises(Exception):
278289
user.get_user_teams(1)
279290

@@ -430,6 +441,15 @@ def test_get_user_teams_no_teams(self, call_the_api_mock):
430441

431442
call_the_api_mock.return_value = list()
432443

444+
self.assertEqual(list(), current_user.get_user_teams())
445+
446+
@patch("grafana_api.api.Api.call_the_api")
447+
def test_get_user_teams_invalid_teams(self, call_the_api_mock):
448+
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
449+
current_user: CurrentUser = CurrentUser(grafana_api_model=model)
450+
451+
call_the_api_mock.return_value = list([{"id": None}])
452+
433453
with self.assertRaises(Exception):
434454
current_user.get_user_teams()
435455

0 commit comments

Comments
 (0)