-
Notifications
You must be signed in to change notification settings - Fork 25
FGA_3: check() #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
swaroopAkkineniWorkos
wants to merge
3
commits into
ENT-5224-python-sdk-for-fga-worktree-fuck-around
Choose a base branch
from
fga-pr2
base: ENT-5224-python-sdk-for-fga-worktree-fuck-around
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+197
−0
Draft
FGA_3: check() #568
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from typing import Union | ||
|
|
||
| from typing_extensions import TypedDict | ||
|
|
||
|
|
||
| class ResourceIdentifierById(TypedDict): | ||
| resource_id: str | ||
|
|
||
|
|
||
| class ResourceIdentifierByExternalId(TypedDict): | ||
| resource_external_id: str | ||
| resource_type_slug: str | ||
|
|
||
|
|
||
| ResourceIdentifier = Union[ResourceIdentifierById, ResourceIdentifierByExternalId] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| from typing import Union | ||
|
|
||
| import pytest | ||
| from tests.utils.syncify import syncify | ||
| from workos.authorization import AsyncAuthorization, Authorization | ||
| from workos.types.authorization.resource_identifier import ( | ||
| ResourceIdentifierByExternalId, | ||
| ResourceIdentifierById, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.sync_and_async(Authorization, AsyncAuthorization) | ||
| class TestAuthorizationCheck: | ||
| @pytest.fixture(autouse=True) | ||
| def setup(self, module_instance: Union[Authorization, AsyncAuthorization]): | ||
| self.http_client = module_instance._http_client | ||
| self.authorization = module_instance | ||
|
|
||
| @pytest.fixture | ||
| def mock_check_authorized(self): | ||
| return {"authorized": True} | ||
|
|
||
| @pytest.fixture | ||
| def mock_check_unauthorized(self): | ||
| return {"authorized": False} | ||
|
|
||
| def test_check_authorized( | ||
| self, mock_check_authorized, capture_and_mock_http_client_request | ||
| ): | ||
| request_kwargs = capture_and_mock_http_client_request( | ||
| self.http_client, mock_check_authorized, 200 | ||
| ) | ||
|
|
||
| result = syncify( | ||
| self.authorization.check( | ||
| "om_01ABC", | ||
| permission_slug="documents:read", | ||
| resource=ResourceIdentifierById(resource_id="res_01ABC"), | ||
| ) | ||
| ) | ||
|
|
||
| assert result.authorized is True | ||
| assert request_kwargs["method"] == "post" | ||
| assert request_kwargs["url"].endswith( | ||
| "/authorization/organization_memberships/om_01ABC/check" | ||
| ) | ||
|
|
||
| def test_check_unauthorized( | ||
| self, mock_check_unauthorized, capture_and_mock_http_client_request | ||
| ): | ||
| request_kwargs = capture_and_mock_http_client_request( | ||
| self.http_client, mock_check_unauthorized, 200 | ||
| ) | ||
|
|
||
| result = syncify( | ||
| self.authorization.check( | ||
| "om_01ABC", | ||
| permission_slug="documents:write", | ||
| resource=ResourceIdentifierById(resource_id="res_01ABC"), | ||
| ) | ||
| ) | ||
|
|
||
| assert result.authorized is False | ||
| assert request_kwargs["method"] == "post" | ||
|
|
||
| def test_check_with_resource_id( | ||
| self, mock_check_authorized, capture_and_mock_http_client_request | ||
| ): | ||
| request_kwargs = capture_and_mock_http_client_request( | ||
| self.http_client, mock_check_authorized, 200 | ||
| ) | ||
|
|
||
| syncify( | ||
| self.authorization.check( | ||
| "om_01ABC", | ||
| permission_slug="documents:read", | ||
| resource=ResourceIdentifierById(resource_id="res_01XYZ"), | ||
| ) | ||
| ) | ||
|
|
||
| assert request_kwargs["json"] == { | ||
| "permission_slug": "documents:read", | ||
| "resource_id": "res_01XYZ", | ||
| } | ||
|
|
||
| def test_check_with_resource_external_id( | ||
| self, mock_check_authorized, capture_and_mock_http_client_request | ||
| ): | ||
| request_kwargs = capture_and_mock_http_client_request( | ||
| self.http_client, mock_check_authorized, 200 | ||
| ) | ||
|
|
||
| syncify( | ||
| self.authorization.check( | ||
| "om_01ABC", | ||
| permission_slug="documents:read", | ||
| resource=ResourceIdentifierByExternalId( | ||
| resource_external_id="ext_doc_123", | ||
| resource_type_slug="document", | ||
| ), | ||
| ) | ||
| ) | ||
|
|
||
| assert request_kwargs["json"] == { | ||
| "permission_slug": "documents:read", | ||
| "resource_external_id": "ext_doc_123", | ||
| "resource_type_slug": "document", | ||
| } | ||
|
|
||
| def test_check_url_construction( | ||
| self, mock_check_authorized, capture_and_mock_http_client_request | ||
| ): | ||
| request_kwargs = capture_and_mock_http_client_request( | ||
| self.http_client, mock_check_authorized, 200 | ||
| ) | ||
|
|
||
| syncify( | ||
| self.authorization.check( | ||
| "om_01MEMBERSHIP", | ||
| permission_slug="admin:access", | ||
| resource=ResourceIdentifierById(resource_id="res_01ABC"), | ||
| ) | ||
| ) | ||
|
|
||
| assert request_kwargs["url"].endswith( | ||
| "/authorization/organization_memberships/om_01MEMBERSHIP/check" | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename to resource_identifier