Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_fga.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,14 @@ def test_query(self, mock_query_response, mock_http_client_with_response):
warrant_token="warrant_token",
)
assert response.dict(exclude_none=True) == mock_query_response

def test_query_with_context(self, mock_query_response, mock_http_client_with_response):
mock_http_client_with_response(self.http_client, mock_query_response, 200)

response = self.fga.query(
q="select member of type user for permission:view-docs",
order="asc",
warrant_token="warrant_token",
context={"region": "us", "subscription": "pro"},
)
assert response.dict(exclude_none=True) == mock_query_response
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make an assertion on what the request URL looks like? (i.e. it should include a string-ified version of the JSON context)

8 changes: 7 additions & 1 deletion workos/fga.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any, Mapping, Optional, Protocol, Sequence
from workos.types.fga import (
CheckOperation,
Expand Down Expand Up @@ -621,11 +622,16 @@ def query(
"after": after,
"context": context,
}
parsed_list_params = {
key: json.dumps(value) if key == "context" and value is not None else value
for key, value in list_params.items()
if value is not None
}

response = self._http_client.request(
"fga/v1/query",
method=REQUEST_METHOD_GET,
params=list_params,
params=parsed_list_params,
headers={"Warrant-Token": warrant_token} if warrant_token else None,
)

Expand Down
Loading