Skip to content

Commit ded9bc2

Browse files
committed
tests(contact-point): Extend unittests of contact point new functionality
1 parent a1458b9 commit ded9bc2

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

grafana_api/alerting_provisioning.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,7 @@ def get_contact_point(self, name: str) -> list:
244244
f"{APIEndpoints.ALERTING_PROVISIONING.value}/contact-points?name={name}"
245245
)
246246

247-
if api_call == list():
248-
logging.error(f"Check the error: {api_call}.")
249-
raise Exception
250-
else:
251-
return api_call
247+
return api_call
252248

253249
def add_contact_point(
254250
self,

tests/unittests/test_alerting_provisioning.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,41 @@ def test_get_all_contact_points(self, call_the_api_mock):
223223
grafana_api_model=model
224224
)
225225

226-
call_the_api_mock.return_value = list([{"test": "test"}])
226+
call_the_api_mock.return_value = list([{"test": "test"}, {"specific-contact-point": "specific contact point"}])
227227

228228
self.assertEqual(
229-
list([{"test": "test"}]),
229+
list([{"test": "test"}, {"specific-contact-point": "specific contact point"}]),
230230
alerting_provisioning.get_all_contact_points(),
231231
)
232232

233+
@patch("grafana_api.api.Api.call_the_api")
234+
def test_get_specific_contact_points(self, call_the_api_mock):
235+
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
236+
alerting_provisioning: AlertingProvisioning = AlertingProvisioning(
237+
grafana_api_model=model
238+
)
239+
240+
call_the_api_mock.return_value = list([{"specific-contact-point": "specific contact point"}])
241+
242+
self.assertEqual(
243+
list([{"specific-contact-point": "specific contact point"}]),
244+
alerting_provisioning.get_contact_point("specific-contact-point"),
245+
)
246+
247+
@patch("grafana_api.api.Api.call_the_api")
248+
def test_get_specific_contact_points_empty_on_partial_name_should_return_empty_list(self, call_the_api_mock):
249+
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
250+
alerting_provisioning: AlertingProvisioning = AlertingProvisioning(
251+
grafana_api_model=model
252+
)
253+
254+
call_the_api_mock.return_value = list([])
255+
256+
self.assertEqual(
257+
list([]),
258+
alerting_provisioning.get_contact_point("contact-point-invalid-name"),
259+
)
260+
233261
@patch("grafana_api.api.Api.call_the_api")
234262
def test_get_all_contact_points_not_possible(self, call_the_api_mock):
235263
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())

0 commit comments

Comments
 (0)