@@ -2041,12 +2041,6 @@ async def test_client_batch_check_multiple_request(self, mock_request):
20412041 Check whether a user is authorized to access an object
20422042 """
20432043
2044- # First, mock the response
2045- mock_request.side_effect = [
2046- mock_response('{"allowed": true, "resolution": "1234"}', 200),
2047- mock_response('{"allowed": false, "resolution": "1234"}', 200),
2048- mock_response('{"allowed": true, "resolution": "1234"}', 200),
2049- ]
20502044 body1 = ClientCheckRequest(
20512045 object="document:2021-budget",
20522046 relation="reader",
@@ -2062,6 +2056,20 @@ async def test_client_batch_check_multiple_request(self, mock_request):
20622056 relation="reader",
20632057 user="user:81684243-9356-4421-8fbf-a4f8d36aa31d",
20642058 )
2059+
2060+ # Mock the response based on request body to avoid race conditions
2061+ def mock_side_effect(*args, **kwargs):
2062+ body = kwargs.get("body", {})
2063+ user = body.get("tuple_key", {}).get("user", "")
2064+ if user == "user:81684243-9356-4421-8fbf-a4f8d36aa31b":
2065+ return mock_response('{"allowed": true, "resolution": "1234"}', 200)
2066+ elif user == "user:81684243-9356-4421-8fbf-a4f8d36aa31c":
2067+ return mock_response('{"allowed": false, "resolution": "1234"}', 200)
2068+ elif user == "user:81684243-9356-4421-8fbf-a4f8d36aa31d":
2069+ return mock_response('{"allowed": true, "resolution": "1234"}', 200)
2070+ return mock_response('{"allowed": false, "resolution": "1234"}', 200)
2071+
2072+ mock_request.side_effect = mock_side_effect
20652073 configuration = self.configuration
20662074 configuration.store_id = store_id
20672075 async with OpenFgaClient(configuration) as api_client:
@@ -2150,12 +2158,6 @@ async def test_client_batch_check_multiple_request_fail(self, mock_request):
21502158}
21512159 """
21522160
2153- # First, mock the response
2154- mock_request.side_effect = [
2155- mock_response('{"allowed": true, "resolution": "1234"}', 200),
2156- ValidationException(http_resp=http_mock_response(response_body, 400)),
2157- mock_response('{"allowed": false, "resolution": "1234"}', 200),
2158- ]
21592161 body1 = ClientCheckRequest(
21602162 object="document:2021-budget",
21612163 relation="reader",
@@ -2171,6 +2173,22 @@ async def test_client_batch_check_multiple_request_fail(self, mock_request):
21712173 relation="reader",
21722174 user="user:81684243-9356-4421-8fbf-a4f8d36aa31d",
21732175 )
2176+
2177+ # Mock the response based on request body to avoid race conditions
2178+ def mock_side_effect(*args, **kwargs):
2179+ body = kwargs.get("body", {})
2180+ user = body.get("tuple_key", {}).get("user", "")
2181+ if user == "user:81684243-9356-4421-8fbf-a4f8d36aa31b":
2182+ return mock_response('{"allowed": true, "resolution": "1234"}', 200)
2183+ elif user == "user:81684243-9356-4421-8fbf-a4f8d36aa31c":
2184+ raise ValidationException(
2185+ http_resp=http_mock_response(response_body, 400)
2186+ )
2187+ elif user == "user:81684243-9356-4421-8fbf-a4f8d36aa31d":
2188+ return mock_response('{"allowed": false, "resolution": "1234"}', 200)
2189+ return mock_response('{"allowed": false, "resolution": "1234"}', 200)
2190+
2191+ mock_request.side_effect = mock_side_effect
21742192 configuration = self.configuration
21752193 configuration.store_id = store_id
21762194 async with OpenFgaClient(configuration) as api_client:
0 commit comments