11import pytest
2- from common .environments .permissions import VIEW_ENVIRONMENT
2+ from common .environments .permissions import (
3+ MANAGE_SEGMENT_OVERRIDES ,
4+ VIEW_ENVIRONMENT ,
5+ )
36from common .projects .permissions import MANAGE_SEGMENTS
47from django .urls import reverse
58from django .utils import timezone
@@ -32,7 +35,8 @@ def test_create_cohort__staff_with_manage_segments__returns_201(
3235 [MANAGE_SEGMENTS ], project_id = dynamo_enabled_project .id
3336 )
3437 with_environment_permissions ( # type: ignore[call-arg]
35- [VIEW_ENVIRONMENT ], environment_id = dynamo_enabled_project_environment_one .id
38+ [VIEW_ENVIRONMENT , MANAGE_SEGMENT_OVERRIDES ],
39+ environment_id = dynamo_enabled_project_environment_one .id ,
3640 )
3741 url = reverse (
3842 "api-v1:environments:cohorts:cohorts-list" ,
@@ -90,6 +94,26 @@ def test_create_cohort__manage_segments_without_environment_access__returns_403(
9094 assert response .status_code == status .HTTP_403_FORBIDDEN
9195
9296
97+ def test_create_cohort__without_manage_segment_overrides__returns_403 (
98+ staff_client : APIClient ,
99+ environment : Environment ,
100+ with_project_permissions : WithProjectPermissionsCallable ,
101+ with_environment_permissions : WithEnvironmentPermissionsCallable ,
102+ ) -> None :
103+ # Given - segment rights and environment access, but no override rights
104+ with_project_permissions ([MANAGE_SEGMENTS ]) # type: ignore[call-arg]
105+ with_environment_permissions ([VIEW_ENVIRONMENT ]) # type: ignore[call-arg]
106+ url = reverse (
107+ "api-v1:environments:cohorts:cohorts-list" , args = [environment .api_key ]
108+ )
109+
110+ # When
111+ response = staff_client .post (url , data = {"name" : "Beta users" }, format = "json" )
112+
113+ # Then
114+ assert response .status_code == status .HTTP_403_FORBIDDEN
115+
116+
93117def test_create_cohort__unknown_environment__returns_403 (
94118 staff_client : APIClient ,
95119) -> None :
@@ -148,7 +172,8 @@ def test_delete_cohort__staff_with_manage_segments__returns_202(
148172 [MANAGE_SEGMENTS ], project_id = dynamo_enabled_project .id
149173 )
150174 with_environment_permissions ( # type: ignore[call-arg]
151- [VIEW_ENVIRONMENT ], environment_id = edge_cohort .environment_id
175+ [VIEW_ENVIRONMENT , MANAGE_SEGMENT_OVERRIDES ],
176+ environment_id = edge_cohort .environment_id ,
152177 )
153178 url = reverse (
154179 "api-v1:environments:cohorts:cohorts-detail" ,
@@ -201,7 +226,8 @@ def test_create_cohort__saas_startup_plan__returns_201(
201226 [MANAGE_SEGMENTS ], project_id = dynamo_enabled_project .id
202227 )
203228 with_environment_permissions ( # type: ignore[call-arg]
204- [VIEW_ENVIRONMENT ], environment_id = dynamo_enabled_project_environment_one .id
229+ [VIEW_ENVIRONMENT , MANAGE_SEGMENT_OVERRIDES ],
230+ environment_id = dynamo_enabled_project_environment_one .id ,
205231 )
206232 url = reverse (
207233 "api-v1:environments:cohorts:cohorts-list" ,
@@ -223,7 +249,9 @@ def test_create_cohort__non_edge_project__returns_400(
223249) -> None :
224250 # Given
225251 with_project_permissions ([MANAGE_SEGMENTS ]) # type: ignore[call-arg]
226- with_environment_permissions ([VIEW_ENVIRONMENT ]) # type: ignore[call-arg]
252+ with_environment_permissions ( # type: ignore[call-arg]
253+ [VIEW_ENVIRONMENT , MANAGE_SEGMENT_OVERRIDES ]
254+ )
227255 url = reverse (
228256 "api-v1:environments:cohorts:cohorts-list" , args = [environment .api_key ]
229257 )
0 commit comments