@@ -107,9 +107,8 @@ def setup(self, sync_http_client_for_test):
107107 self .http_client = sync_http_client_for_test
108108 self .fga = FGA (http_client = self .http_client )
109109
110- @pytest .fixture
111- def mock_check_warning_response (self ):
112- return {
110+ def test_check_with_warning (self , mock_http_client_with_response ):
111+ mock_response = {
113112 "result" : "authorized" ,
114113 "is_implicit" : True ,
115114 "warnings" : [
@@ -120,10 +119,23 @@ def mock_check_warning_response(self):
120119 }
121120 ],
122121 }
122+ mock_http_client_with_response (self .http_client , mock_response , 200 )
123123
124- @pytest .fixture
125- def mock_query_warning_response (self ):
126- return {
124+ response = self .fga .check (
125+ op = "any_of" ,
126+ checks = [
127+ WarrantCheckInput (
128+ resource_type = "schedule" ,
129+ resource_id = "schedule-A1" ,
130+ relation = "viewer" ,
131+ subject = SubjectInput (resource_type = "user" , resource_id = "user-A" ),
132+ )
133+ ],
134+ )
135+ assert response .dict (exclude_none = True ) == mock_response
136+
137+ def test_query_with_warning (self , mock_http_client_with_response ):
138+ mock_response = {
127139 "object" : "list" ,
128140 "data" : [
129141 {
@@ -149,12 +161,28 @@ def mock_query_warning_response(self):
149161 ],
150162 }
151163
152- def test_check_with_warning (
153- self , mock_check_warning_response , mock_http_client_with_response
154- ):
155- mock_http_client_with_response (
156- self .http_client , mock_check_warning_response , 200
164+ mock_http_client_with_response (self .http_client , mock_response , 200 )
165+
166+ response = self .fga .query (
167+ q = "select member of type user for permission:view-docs" ,
168+ order = "asc" ,
169+ warrant_token = "warrant_token" ,
157170 )
171+ assert response .dict (exclude_none = True ) == mock_response
172+
173+ def test_check_with_generic_warning (self , mock_http_client_with_response ):
174+ mock_response = {
175+ "result" : "authorized" ,
176+ "is_implicit" : True ,
177+ "warnings" : [
178+ {
179+ "code" : "generic" ,
180+ "message" : "Generic warning" ,
181+ }
182+ ],
183+ }
184+
185+ mock_http_client_with_response (self .http_client , mock_response , 200 )
158186
159187 response = self .fga .check (
160188 op = "any_of" ,
@@ -167,21 +195,7 @@ def test_check_with_warning(
167195 )
168196 ],
169197 )
170- assert response .dict (exclude_none = True ) == mock_check_warning_response
171-
172- def test_query_with_warning (
173- self , mock_query_warning_response , mock_http_client_with_response
174- ):
175- mock_http_client_with_response (
176- self .http_client , mock_query_warning_response , 200
177- )
178-
179- response = self .fga .query (
180- q = "select member of type user for permission:view-docs" ,
181- order = "asc" ,
182- warrant_token = "warrant_token" ,
183- )
184- assert response .dict (exclude_none = True ) == mock_query_warning_response
198+ assert response .dict (exclude_none = True ) == mock_response
185199
186200
187201class TestFGA :
0 commit comments