@@ -101,6 +101,89 @@ def test_get_resource_401(self, mock_http_client_with_response):
101101 self .fga .get_resource (resource_type = "test" , resource_id = "test" )
102102
103103
104+ class TestWarnings :
105+ @pytest .fixture (autouse = True )
106+ def setup (self , sync_http_client_for_test ):
107+ self .http_client = sync_http_client_for_test
108+ self .fga = FGA (http_client = self .http_client )
109+
110+ @pytest .fixture
111+ def mock_check_warning_response (self ):
112+ return {
113+ "result" : "authorized" ,
114+ "is_implicit" : True ,
115+ "warnings" : [
116+ {
117+ "code" : "missing_context_keys" ,
118+ "message" : "Missing context keys" ,
119+ "keys" : ["key1" , "key2" ],
120+ }
121+ ],
122+ }
123+
124+ @pytest .fixture
125+ def mock_query_warning_response (self ):
126+ return {
127+ "object" : "list" ,
128+ "data" : [
129+ {
130+ "resource_type" : "user" ,
131+ "resource_id" : "richard" ,
132+ "relation" : "member" ,
133+ "warrant" : {
134+ "resource_type" : "role" ,
135+ "resource_id" : "developer" ,
136+ "relation" : "member" ,
137+ "subject" : {"resource_type" : "user" , "resource_id" : "richard" },
138+ },
139+ "is_implicit" : True ,
140+ }
141+ ],
142+ "list_metadata" : {},
143+ "warnings" : [
144+ {
145+ "code" : "missing_context_keys" ,
146+ "message" : "Missing context keys" ,
147+ "keys" : ["key1" , "key2" ],
148+ }
149+ ],
150+ }
151+
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
157+ )
158+
159+ response = self .fga .check (
160+ op = "any_of" ,
161+ checks = [
162+ WarrantCheckInput (
163+ resource_type = "schedule" ,
164+ resource_id = "schedule-A1" ,
165+ relation = "viewer" ,
166+ subject = SubjectInput (resource_type = "user" , resource_id = "user-A" ),
167+ )
168+ ],
169+ )
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
185+
186+
104187class TestFGA :
105188 @pytest .fixture (autouse = True )
106189 def setup (self , sync_http_client_for_test ):
0 commit comments