@@ -20,6 +20,16 @@ def expected_created_by(
2020 return None
2121
2222
23+ @pytest .fixture
24+ def expected_dismissed_by (
25+ admin_client_auth_type : AdminClientAuthType ,
26+ admin_user_email : str ,
27+ ) -> str :
28+ if admin_client_auth_type == "user" :
29+ return admin_user_email
30+ return "test_key"
31+
32+
2333def test_feature_health_providers__get__expected_response (
2434 project : int ,
2535 admin_client_new : APIClient ,
@@ -76,6 +86,70 @@ def test_feature_health_providers__delete__expected_response(
7686 assert response .json () == []
7787
7888
89+ def test_feature_health_events__dismiss__unauthorized__expected_response (
90+ project : int ,
91+ unhealthy_feature_health_event : int ,
92+ test_user_client : APIClient ,
93+ ) -> None :
94+ # Given
95+ feature_health_events_dismiss_url = reverse (
96+ "api-v1:projects:feature-health-events-dismiss" ,
97+ args = [project , unhealthy_feature_health_event ],
98+ )
99+
100+ # When
101+ response = test_user_client .post (feature_health_events_dismiss_url )
102+
103+ # Then
104+ assert response .status_code == 403
105+ assert response .json () == {
106+ "detail" : "You do not have permission to perform this action."
107+ }
108+
109+
110+ @pytest .mark .freeze_time ("2023-01-19T09:09:47.325132+00:00" )
111+ def test_feature_health_events__dismiss__expected_response (
112+ project : int ,
113+ unhealthy_feature : int ,
114+ unhealthy_feature_health_event : int ,
115+ admin_client_new : APIClient ,
116+ expected_dismissed_by : str ,
117+ mocker : MockerFixture ,
118+ ) -> None :
119+ # Given
120+ feature_health_events_url = reverse (
121+ "api-v1:projects:feature-health-events-list" , args = [project ]
122+ )
123+ feature_health_events_dismiss_url = reverse (
124+ "api-v1:projects:feature-health-events-dismiss" ,
125+ args = [project , unhealthy_feature_health_event ],
126+ )
127+
128+ # When
129+ with freeze_time ("2023-01-19T10:09:47.325132+00:00" ):
130+ response = admin_client_new .post (feature_health_events_dismiss_url )
131+
132+ # Then
133+ assert response .status_code == 204
134+ response = admin_client_new .get (feature_health_events_url )
135+ assert response .json () == [
136+ {
137+ "created_at" : "2023-01-19T10:09:47.325132Z" ,
138+ "environment" : None ,
139+ "feature" : unhealthy_feature ,
140+ "id" : mocker .ANY ,
141+ "provider_name" : "Sample" ,
142+ "reason" : {
143+ "text_blocks" : [
144+ {"text" : f"Manually dismissed by { expected_dismissed_by } " }
145+ ],
146+ "url_blocks" : [],
147+ },
148+ "type" : "HEALTHY" ,
149+ },
150+ ]
151+
152+
79153def test_webhook__invalid_path__expected_response (
80154 api_client : APIClient ,
81155) -> None :
@@ -97,6 +171,7 @@ def test_webhook__sample_provider__post__expected_feature_health_event_created__
97171 sample_feature_health_provider_webhook_url : str ,
98172 api_client : APIClient ,
99173 admin_client_new : APIClient ,
174+ mocker : MockerFixture ,
100175) -> None :
101176 # Given
102177 feature_health_events_url = reverse (
@@ -121,6 +196,7 @@ def test_webhook__sample_provider__post__expected_feature_health_event_created__
121196 response = admin_client_new .get (feature_health_events_url )
122197 assert response .json () == [
123198 {
199+ "id" : mocker .ANY ,
124200 "created_at" : "2023-01-19T09:09:47.325132Z" ,
125201 "environment" : None ,
126202 "feature" : feature ,
@@ -156,6 +232,7 @@ def test_webhook__sample_provider__post_with_environment_expected_feature_health
156232 sample_feature_health_provider_webhook_url : str ,
157233 api_client : APIClient ,
158234 admin_client_new : APIClient ,
235+ mocker : MockerFixture ,
159236) -> None :
160237 # Given
161238 feature_health_events_url = reverse (
@@ -179,6 +256,7 @@ def test_webhook__sample_provider__post_with_environment_expected_feature_health
179256 response = admin_client_new .get (feature_health_events_url )
180257 assert response .json () == [
181258 {
259+ "id" : mocker .ANY ,
182260 "created_at" : "2023-01-19T09:09:47.325132Z" ,
183261 "environment" : environment ,
184262 "feature" : feature ,
@@ -197,6 +275,7 @@ def test_webhook__unhealthy_feature__post__expected_feature_health_event_created
197275 sample_feature_health_provider_webhook_url : str ,
198276 api_client : APIClient ,
199277 admin_client_new : APIClient ,
278+ mocker : MockerFixture ,
200279) -> None :
201280 # Given
202281 feature_health_events_url = reverse (
@@ -222,6 +301,7 @@ def test_webhook__unhealthy_feature__post__expected_feature_health_event_created
222301 response = admin_client_new .get (feature_health_events_url )
223302 assert response .json () == [
224303 {
304+ "id" : mocker .ANY ,
225305 "created_at" : "2023-01-19T09:09:48.325132Z" ,
226306 "environment" : None ,
227307 "feature" : unhealthy_feature ,
@@ -273,6 +353,7 @@ def test_webhook__grafana_provider__post__expected_feature_health_event_created(
273353 grafana_feature_health_provider_webhook_url : str ,
274354 api_client : APIClient ,
275355 admin_client_new : APIClient ,
356+ mocker : MockerFixture ,
276357) -> None :
277358 # Given
278359 feature_health_events_url = reverse (
@@ -335,6 +416,7 @@ def test_webhook__grafana_provider__post__expected_feature_health_event_created(
335416 response = admin_client_new .get (feature_health_events_url )
336417 assert response .json () == [
337418 {
419+ "id" : mocker .ANY ,
338420 "created_at" : "2025-02-12T21:06:50Z" ,
339421 "environment" : None ,
340422 "feature" : feature ,
@@ -354,6 +436,7 @@ def test_webhook__grafana_provider__post__multiple__expected_feature_health_even
354436 grafana_feature_health_provider_webhook_url : str ,
355437 api_client : APIClient ,
356438 admin_client_new : APIClient ,
439+ mocker : MockerFixture ,
357440) -> None :
358441 # Given
359442 feature_health_events_url = reverse (
@@ -502,6 +585,7 @@ def test_webhook__grafana_provider__post__multiple__expected_feature_health_even
502585 # second firing alert has not been resolved
503586 # and provided an environment label
504587 {
588+ "id" : mocker .ANY ,
505589 "created_at" : "2025-02-12T21:07:50Z" ,
506590 "environment" : environment ,
507591 "feature" : feature ,
@@ -511,6 +595,7 @@ def test_webhook__grafana_provider__post__multiple__expected_feature_health_even
511595 },
512596 # first firing alert has been resolved
513597 {
598+ "id" : mocker .ANY ,
514599 "created_at" : "2025-02-12T21:12:50Z" ,
515600 "environment" : None ,
516601 "feature" : feature ,
0 commit comments