Skip to content

Commit 9be6215

Browse files
committed
test: add comprehensive test coverage for header precedence validation
- Add test for streamed_list_objects with custom headers - Improve test coverage for header merging edge cases - Validate that custom headers properly override defaults across all sync API methods
1 parent d226b1f commit 9be6215

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/sync/client/per_request_headers_sync_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,44 @@ def test_sync_client_consistency_across_async_api(self, mock_request):
274274

275275
# Verify other options were also applied
276276
self.assertIsNotNone(call_args)
277+
278+
@patch("openfga_sdk.sync.open_fga_api.OpenFgaApi.streamed_list_objects")
279+
def test_sync_streamed_list_objects_with_custom_headers(self, mock_streamed_list_objects):
280+
"""Test sync streamed_list_objects with custom headers to cover missing line"""
281+
# Mock the streaming API response
282+
mock_streamed_list_objects.return_value = [
283+
{"result": {"object": "document:1"}},
284+
{"result": {"object": "document:2"}},
285+
]
286+
287+
custom_headers = {
288+
"x-stream-id": "stream-123",
289+
"x-batch-size": "100"
290+
}
291+
292+
with OpenFgaClient(self.configuration) as fga_client:
293+
options = {
294+
"headers": custom_headers
295+
}
296+
297+
from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest
298+
body = ClientListObjectsRequest(
299+
user="user:test-user",
300+
relation="viewer",
301+
type="document",
302+
)
303+
304+
# This should call the streamed_list_objects method and cover line 932
305+
results = list(fga_client.streamed_list_objects(body, options))
306+
307+
# Verify we got results
308+
self.assertEqual(len(results), 2)
309+
self.assertEqual(results[0].object, "document:1")
310+
self.assertEqual(results[1].object, "document:2")
311+
312+
# Verify the API was called with the expected parameters including headers
313+
mock_streamed_list_objects.assert_called_once()
314+
call_kwargs = mock_streamed_list_objects.call_args.kwargs
315+
self.assertIn("_headers", call_kwargs)
316+
self.assertEqual(call_kwargs["_headers"]["x-stream-id"], "stream-123")
317+
self.assertEqual(call_kwargs["_headers"]["x-batch-size"], "100")

0 commit comments

Comments
 (0)