Skip to content
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
4 changes: 2 additions & 2 deletions grafana_api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def get_user_teams(self, id: int) -> list:
f"{APIEndpoints.USERS.value}/{id}/teams",
)

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

if api_call == list() or api_call[0].get("id") is None:
if api_call != list() and api_call[0].get("id") is None:
logging.error(f"Check the error: {api_call}.")
raise Exception
else:
Expand Down
20 changes: 20 additions & 0 deletions tests/unittests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ def test_get_user_teams_no_teams(self, call_the_api_mock):

call_the_api_mock.return_value = list()

self.assertEqual(list(), user.get_user_teams(1))

@patch("grafana_api.api.Api.call_the_api")
def test_get_user_teams_invalid_teams(self, call_the_api_mock):
model: APIModel = APIModel(
host=MagicMock(), username=MagicMock(), password=MagicMock()
)
user: User = User(grafana_api_model=model)

call_the_api_mock.return_value = list([{"id": None}])

with self.assertRaises(Exception):
user.get_user_teams(1)

Expand Down Expand Up @@ -430,6 +441,15 @@ def test_get_user_teams_no_teams(self, call_the_api_mock):

call_the_api_mock.return_value = list()

self.assertEqual(list(), current_user.get_user_teams())

@patch("grafana_api.api.Api.call_the_api")
def test_get_user_teams_invalid_teams(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
current_user: CurrentUser = CurrentUser(grafana_api_model=model)

call_the_api_mock.return_value = list([{"id": None}])

with self.assertRaises(Exception):
current_user.get_user_teams()

Expand Down