# This file is auto-generated by oagen. Do not edit.

import json

import pytest
from workos import WorkOSClient, AsyncWorkOSClient
from tests.generated_helpers import load_fixture

from workos.authorization.models import (
    AuthorizationCheck,
    AuthorizationResource,
    GroupRoleAssignment,
    GroupRoleAssignmentList,
    Permission,
    Role,
    RoleList,
    UserRoleAssignment,
    AuthorizationAssignment,
)
from workos.common.models import (
    AuthorizationPermission,
    UserOrganizationMembershipBaseListData,
    PaginationOrder,
)
from workos._pagination import AsyncPage, SyncPage
from workos._errors import (
    AuthenticationError,
    BadRequestError,
    NotFoundError,
    RateLimitExceededError,
    ServerError,
    UnprocessableEntityError,
)
from workos.authorization._resource import (
    ResourceTargetById,
    ParentResourceById,
    ParentById,
)


class TestAuthorization:
    def test_list_group_role_assignments(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_group_role_assignment.json"),
        )
        page = workos.authorization.list_group_role_assignments("test_group_id")
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], GroupRoleAssignment)

    def test_list_group_role_assignments_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_group_role_assignments("test_group_id")
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_group_role_assignments_encodes_query_params(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_group_role_assignments(
            "test_group_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    def test_create_group_role_assignment(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("group_role_assignment.json"),
        )
        result = workos.authorization.create_group_role_assignment(
            "test_group_id", role_slug="test_role_slug"
        )
        assert isinstance(result, GroupRoleAssignment)
        assert result.object == "group_role_assignment"
        assert result.id == "gra_01HXYZ123456789ABCDEFGH"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments"
        )
        body = json.loads(request.content)
        assert body["role_slug"] == "test_role_slug"

    def test_update_group_role_assignments(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("group_role_assignment_list.json"),
        )
        result = workos.authorization.update_group_role_assignments(
            "test_group_id", role_assignments=[]
        )
        assert isinstance(result, GroupRoleAssignmentList)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments"
        )
        body = json.loads(request.content)
        assert "role_assignments" in body

    def test_delete_group_role_assignments(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.delete_group_role_assignments(
            "test_group_id", role_slug="test_role_slug"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments"
        )

    def test_get_group_role_assignment(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("group_role_assignment.json"),
        )
        result = workos.authorization.get_group_role_assignment(
            "test_group_id", "test_role_assignment_id"
        )
        assert isinstance(result, GroupRoleAssignment)
        assert result.object == "group_role_assignment"
        assert result.id == "gra_01HXYZ123456789ABCDEFGH"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments/test_role_assignment_id"
        )

    def test_delete_group_role_assignment(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.delete_group_role_assignment(
            "test_group_id", "test_role_assignment_id"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments/test_role_assignment_id"
        )

    def test_check(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_check.json"),
        )
        result = workos.authorization.check(
            "test_organization_membership_id",
            permission_slug="test_permission_slug",
            resource_target=ResourceTargetById(resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationCheck)
        assert result.authorized is True
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/check"
        )
        body = json.loads(request.content)
        assert body["permission_slug"] == "test_permission_slug"

    def test_list_resources_for_membership(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_authorization_resource.json"),
        )
        page = workos.authorization.list_resources_for_membership(
            "test_organization_membership_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationResource)

    def test_list_resources_for_membership_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_resources_for_membership(
            "test_organization_membership_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_resources_for_membership_encodes_query_params(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_resources_for_membership(
            "test_organization_membership_id",
            parent_resource=ParentResourceById(
                parent_resource_id="value parent_resource_id/test"
            ),
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            permission_slug="value permission_slug/test",
        )
        request = httpx_mock.get_request()
        assert (
            request.url.params["parent_resource_id"] == "value parent_resource_id/test"
        )
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["permission_slug"] == "value permission_slug/test"

    def test_list_effective_permissions(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_authorization_permission.json"),
        )
        page = workos.authorization.list_effective_permissions(
            "test_organization_membership_id", "test_resource_id"
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationPermission)

    def test_list_effective_permissions_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_effective_permissions(
            "test_organization_membership_id", "test_resource_id"
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_effective_permissions_encodes_query_params(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_effective_permissions(
            "test_organization_membership_id",
            "test_resource_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    def test_list_effective_permissions_by_external_id(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_authorization_permission.json"),
        )
        page = workos.authorization.list_effective_permissions_by_external_id(
            "test_organization_membership_id",
            "test_resource_type_slug",
            "test_external_id",
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationPermission)

    def test_list_effective_permissions_by_external_id_empty_page(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_effective_permissions_by_external_id(
            "test_organization_membership_id",
            "test_resource_type_slug",
            "test_external_id",
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_effective_permissions_by_external_id_encodes_query_params(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_effective_permissions_by_external_id(
            "test_organization_membership_id",
            "test_resource_type_slug",
            "test_external_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    def test_list_role_assignments(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_user_role_assignment.json"),
        )
        page = workos.authorization.list_role_assignments(
            "test_organization_membership_id"
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserRoleAssignment)

    def test_list_role_assignments_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_role_assignments(
            "test_organization_membership_id"
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_role_assignments_encodes_query_params(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_role_assignments(
            "test_organization_membership_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            resource_id="value resource_id/test",
            resource_external_id="value resource_external_id/test",
            resource_type_slug="value resource_type_slug/test",
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["resource_id"] == "value resource_id/test"
        assert (
            request.url.params["resource_external_id"]
            == "value resource_external_id/test"
        )
        assert (
            request.url.params["resource_type_slug"] == "value resource_type_slug/test"
        )

    def test_assign_role(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("user_role_assignment.json"),
        )
        result = workos.authorization.assign_role(
            "test_organization_membership_id",
            role_slug="test_role_slug",
            resource_target=ResourceTargetById(resource_id="test_value"),
        )
        assert isinstance(result, UserRoleAssignment)
        assert result.object == "role_assignment"
        assert result.id == "role_assignment_01HXYZ123456789ABCDEFGH"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/role_assignments"
        )
        body = json.loads(request.content)
        assert body["role_slug"] == "test_role_slug"

    def test_remove_role(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.remove_role(
            "test_organization_membership_id",
            role_slug="test_role_slug",
            resource_target=ResourceTargetById(resource_id="test_value"),
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/role_assignments"
        )

    def test_remove_role_assignment(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.remove_role_assignment(
            "test_organization_membership_id", "test_role_assignment_id"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/role_assignments/test_role_assignment_id"
        )

    def test_list_organization_roles(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role_list.json"),
        )
        result = workos.authorization.list_organization_roles("test_organizationId")
        assert isinstance(result, RoleList)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles"
        )

    def test_create_organization_role(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.create_organization_role(
            "test_organizationId", name="test_name"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles"
        )
        body = json.loads(request.content)
        assert body["name"] == "test_name"

    def test_get_organization_role(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.get_organization_role(
            "test_organizationId", "test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug"
        )

    def test_update_organization_role(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.update_organization_role(
            "test_organizationId", "test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug"
        )

    def test_delete_organization_role(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.delete_organization_role(
            "test_organizationId", "test_slug"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug"
        )

    def test_add_organization_role_permission(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.add_organization_role_permission(
            "test_organizationId", "test_slug", body_slug="test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug/permissions"
        )
        body = json.loads(request.content)
        assert body["slug"] == "test_slug"

    def test_set_organization_role_permissions(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.set_organization_role_permissions(
            "test_organizationId", "test_slug", permissions=[]
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug/permissions"
        )
        body = json.loads(request.content)
        assert "permissions" in body

    def test_remove_organization_role_permission(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.remove_organization_role_permission(
            "test_organizationId", "test_slug", "test_permissionSlug"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug/permissions/test_permissionSlug"
        )

    def test_get_resource_by_external_id(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_resource.json"),
        )
        result = workos.authorization.get_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id"
        )

    def test_update_resource_by_external_id(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_resource.json"),
        )
        result = workos.authorization.update_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id"
        )

    def test_delete_resource_by_external_id(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.delete_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id"
        )

    def test_delete_resource_by_external_id_encodes_query_params(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(status_code=204)
        workos.authorization.delete_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            cascade_delete=True,
        )
        request = httpx_mock.get_request()
        assert request.url.params["cascade_delete"] == "true"

    def test_list_memberships_for_resource_by_external_id(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_user_organization_membership_base_list_data.json"),
        )
        page = workos.authorization.list_memberships_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserOrganizationMembershipBaseListData)

    def test_list_memberships_for_resource_by_external_id_empty_page(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_memberships_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_memberships_for_resource_by_external_id_encodes_query_params(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_memberships_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            permission_slug="value permission_slug/test",
            assignment=AuthorizationAssignment("direct"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["permission_slug"] == "value permission_slug/test"
        assert request.url.params["assignment"] == "direct"

    def test_list_role_assignments_for_resource_by_external_id(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("list_user_role_assignment.json"),
        )
        page = workos.authorization.list_role_assignments_for_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserRoleAssignment)

    def test_list_role_assignments_for_resource_by_external_id_empty_page(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_role_assignments_for_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_role_assignments_for_resource_by_external_id_encodes_query_params(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_role_assignments_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            role_slug="value role_slug/test",
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["role_slug"] == "value role_slug/test"

    def test_list_resources(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_authorization_resource.json"),
        )
        page = workos.authorization.list_resources(
            parent=ParentById(parent_resource_id="test_value")
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationResource)

    def test_list_resources_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_resources(
            parent=ParentById(parent_resource_id="test_value")
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_resources_encodes_query_params(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_resources(
            parent=ParentById(parent_resource_id="value parent_resource_id/test"),
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            organization_id="value organization_id/test",
            resource_type_slug="value resource_type_slug/test",
            resource_external_id="value resource_external_id/test",
        )
        request = httpx_mock.get_request()
        assert (
            request.url.params["parent_resource_id"] == "value parent_resource_id/test"
        )
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["organization_id"] == "value organization_id/test"
        assert (
            request.url.params["resource_type_slug"] == "value resource_type_slug/test"
        )
        assert (
            request.url.params["resource_external_id"]
            == "value resource_external_id/test"
        )

    def test_create_resource(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_resource.json"),
        )
        result = workos.authorization.create_resource(
            external_id="test_external_id",
            name="test_name",
            resource_type_slug="test_resource_type_slug",
            organization_id="test_organization_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/resources")
        body = json.loads(request.content)
        assert body["external_id"] == "test_external_id"
        assert body["name"] == "test_name"
        assert body["resource_type_slug"] == "test_resource_type_slug"
        assert body["organization_id"] == "test_organization_id"

    def test_get_resource(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_resource.json"),
        )
        result = workos.authorization.get_resource("test_resource_id")
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/resources/test_resource_id")

    def test_update_resource(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_resource.json"),
        )
        result = workos.authorization.update_resource(
            "test_resource_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith("/authorization/resources/test_resource_id")

    def test_delete_resource(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.delete_resource("test_resource_id")
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith("/authorization/resources/test_resource_id")

    def test_delete_resource_encodes_query_params(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        workos.authorization.delete_resource("test_resource_id", cascade_delete=True)
        request = httpx_mock.get_request()
        assert request.url.params["cascade_delete"] == "true"

    def test_list_memberships_for_resource(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_user_organization_membership_base_list_data.json"),
        )
        page = workos.authorization.list_memberships_for_resource(
            "test_resource_id", permission_slug="test_permission_slug"
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserOrganizationMembershipBaseListData)

    def test_list_memberships_for_resource_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_memberships_for_resource(
            "test_resource_id", permission_slug="test_permission_slug"
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_memberships_for_resource_encodes_query_params(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_memberships_for_resource(
            "test_resource_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            permission_slug="value permission_slug/test",
            assignment=AuthorizationAssignment("direct"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["permission_slug"] == "value permission_slug/test"
        assert request.url.params["assignment"] == "direct"

    def test_list_role_assignments_for_resource(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_user_role_assignment.json"),
        )
        page = workos.authorization.list_role_assignments_for_resource(
            "test_resource_id"
        )
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserRoleAssignment)

    def test_list_role_assignments_for_resource_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_role_assignments_for_resource(
            "test_resource_id"
        )
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_role_assignments_for_resource_encodes_query_params(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_role_assignments_for_resource(
            "test_resource_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            role_slug="value role_slug/test",
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["role_slug"] == "value role_slug/test"

    def test_list_environment_roles(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role_list.json"),
        )
        result = workos.authorization.list_environment_roles()
        assert isinstance(result, RoleList)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/roles")

    def test_create_environment_role(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.create_environment_role(
            slug="test_slug", name="test_name"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/roles")
        body = json.loads(request.content)
        assert body["slug"] == "test_slug"
        assert body["name"] == "test_name"

    def test_get_environment_role(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.get_environment_role("test_slug")
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/roles/test_slug")

    def test_update_environment_role(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.update_environment_role("test_slug")
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith("/authorization/roles/test_slug")

    def test_add_environment_role_permission(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.add_environment_role_permission(
            "test_slug", body_slug="test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/roles/test_slug/permissions")
        body = json.loads(request.content)
        assert body["slug"] == "test_slug"

    def test_set_environment_role_permissions(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("role.json"),
        )
        result = workos.authorization.set_environment_role_permissions(
            "test_slug", permissions=[]
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith("/authorization/roles/test_slug/permissions")
        body = json.loads(request.content)
        assert "permissions" in body

    def test_list_permissions(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_authorization_permission.json"),
        )
        page = workos.authorization.list_permissions()
        assert isinstance(page, SyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationPermission)

    def test_list_permissions_empty_page(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = workos.authorization.list_permissions()
        assert isinstance(page, SyncPage)
        assert page.data == []

    def test_list_permissions_encodes_query_params(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_permissions(
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    def test_create_permission(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("permission.json"),
        )
        result = workos.authorization.create_permission(
            slug="test_slug", name="test_name"
        )
        assert isinstance(result, Permission)
        assert result.object == "permission"
        assert result.id == "perm_01HXYZ123456789ABCDEFGHIJ"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/permissions")
        body = json.loads(request.content)
        assert body["slug"] == "test_slug"
        assert body["name"] == "test_name"

    def test_get_permission(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_permission.json"),
        )
        result = workos.authorization.get_permission("test_slug")
        assert isinstance(result, AuthorizationPermission)
        assert result.object == "permission"
        assert result.id == "perm_01HXYZ123456789ABCDEFGHIJ"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/permissions/test_slug")

    def test_update_permission(self, workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("authorization_permission.json"),
        )
        result = workos.authorization.update_permission("test_slug")
        assert isinstance(result, AuthorizationPermission)
        assert result.object == "permission"
        assert result.id == "perm_01HXYZ123456789ABCDEFGHIJ"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith("/authorization/permissions/test_slug")

    def test_delete_permission(self, workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = workos.authorization.delete_permission("test_slug")
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith("/authorization/permissions/test_slug")

    def test_list_group_role_assignments_with_request_options(self, workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        workos.authorization.list_group_role_assignments(
            "test_group_id", request_options={"extra_headers": {"X-Custom": "value"}}
        )
        request = httpx_mock.get_request()
        assert request.headers["X-Custom"] == "value"

    def test_list_group_role_assignments_unauthorized(self, workos, httpx_mock):
        httpx_mock.add_response(
            status_code=401,
            json={"message": "Unauthorized"},
        )
        with pytest.raises(AuthenticationError):
            workos.authorization.list_group_role_assignments("test_group_id")

    def test_list_group_role_assignments_not_found(self, httpx_mock):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=404, json={"message": "Not found"})
            with pytest.raises(NotFoundError):
                workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            workos.close()

    def test_list_group_role_assignments_rate_limited(self, httpx_mock):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(
                status_code=429,
                headers={"Retry-After": "0"},
                json={"message": "Slow down"},
            )
            with pytest.raises(RateLimitExceededError):
                workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            workos.close()

    def test_list_group_role_assignments_server_error(self, httpx_mock):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=500, json={"message": "Server error"})
            with pytest.raises(ServerError):
                workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            workos.close()

    def test_list_group_role_assignments_bad_request(self, httpx_mock):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=400, json={"message": "Bad request"})
            with pytest.raises(BadRequestError):
                workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            workos.close()

    def test_list_group_role_assignments_unprocessable(self, httpx_mock):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=422, json={"message": "Unprocessable"})
            with pytest.raises(UnprocessableEntityError):
                workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            workos.close()


class TestAsyncAuthorization:
    @pytest.mark.asyncio
    async def test_list_group_role_assignments(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("list_group_role_assignment.json"))
        page = await async_workos.authorization.list_group_role_assignments(
            "test_group_id"
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], GroupRoleAssignment)

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_group_role_assignments(
            "test_group_id"
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_group_role_assignments(
            "test_group_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    @pytest.mark.asyncio
    async def test_create_group_role_assignment(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("group_role_assignment.json"))
        result = await async_workos.authorization.create_group_role_assignment(
            "test_group_id", role_slug="test_role_slug"
        )
        assert isinstance(result, GroupRoleAssignment)
        assert result.object == "group_role_assignment"
        assert result.id == "gra_01HXYZ123456789ABCDEFGH"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments"
        )

    @pytest.mark.asyncio
    async def test_update_group_role_assignments(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("group_role_assignment_list.json"))
        result = await async_workos.authorization.update_group_role_assignments(
            "test_group_id", role_assignments=[]
        )
        assert isinstance(result, GroupRoleAssignmentList)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments"
        )

    @pytest.mark.asyncio
    async def test_delete_group_role_assignments(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.delete_group_role_assignments(
            "test_group_id", role_slug="test_role_slug"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments"
        )

    @pytest.mark.asyncio
    async def test_get_group_role_assignment(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("group_role_assignment.json"))
        result = await async_workos.authorization.get_group_role_assignment(
            "test_group_id", "test_role_assignment_id"
        )
        assert isinstance(result, GroupRoleAssignment)
        assert result.object == "group_role_assignment"
        assert result.id == "gra_01HXYZ123456789ABCDEFGH"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments/test_role_assignment_id"
        )

    @pytest.mark.asyncio
    async def test_delete_group_role_assignment(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.delete_group_role_assignment(
            "test_group_id", "test_role_assignment_id"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/groups/test_group_id/role_assignments/test_role_assignment_id"
        )

    @pytest.mark.asyncio
    async def test_check(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_check.json"))
        result = await async_workos.authorization.check(
            "test_organization_membership_id",
            permission_slug="test_permission_slug",
            resource_target=ResourceTargetById(resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationCheck)
        assert result.authorized is True
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/check"
        )

    @pytest.mark.asyncio
    async def test_list_resources_for_membership(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("list_authorization_resource.json"))
        page = await async_workos.authorization.list_resources_for_membership(
            "test_organization_membership_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationResource)

    @pytest.mark.asyncio
    async def test_list_resources_for_membership_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_resources_for_membership(
            "test_organization_membership_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_resources_for_membership_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_resources_for_membership(
            "test_organization_membership_id",
            parent_resource=ParentResourceById(
                parent_resource_id="value parent_resource_id/test"
            ),
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            permission_slug="value permission_slug/test",
        )
        request = httpx_mock.get_request()
        assert (
            request.url.params["parent_resource_id"] == "value parent_resource_id/test"
        )
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["permission_slug"] == "value permission_slug/test"

    @pytest.mark.asyncio
    async def test_list_effective_permissions(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("list_authorization_permission.json"))
        page = await async_workos.authorization.list_effective_permissions(
            "test_organization_membership_id", "test_resource_id"
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationPermission)

    @pytest.mark.asyncio
    async def test_list_effective_permissions_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_effective_permissions(
            "test_organization_membership_id", "test_resource_id"
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_effective_permissions_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_effective_permissions(
            "test_organization_membership_id",
            "test_resource_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    @pytest.mark.asyncio
    async def test_list_effective_permissions_by_external_id(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json=load_fixture("list_authorization_permission.json"))
        page = (
            await async_workos.authorization.list_effective_permissions_by_external_id(
                "test_organization_membership_id",
                "test_resource_type_slug",
                "test_external_id",
            )
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationPermission)

    @pytest.mark.asyncio
    async def test_list_effective_permissions_by_external_id_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = (
            await async_workos.authorization.list_effective_permissions_by_external_id(
                "test_organization_membership_id",
                "test_resource_type_slug",
                "test_external_id",
            )
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_effective_permissions_by_external_id_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_effective_permissions_by_external_id(
            "test_organization_membership_id",
            "test_resource_type_slug",
            "test_external_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    @pytest.mark.asyncio
    async def test_list_role_assignments(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("list_user_role_assignment.json"))
        page = await async_workos.authorization.list_role_assignments(
            "test_organization_membership_id"
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserRoleAssignment)

    @pytest.mark.asyncio
    async def test_list_role_assignments_empty_page(self, async_workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_role_assignments(
            "test_organization_membership_id"
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_role_assignments_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_role_assignments(
            "test_organization_membership_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            resource_id="value resource_id/test",
            resource_external_id="value resource_external_id/test",
            resource_type_slug="value resource_type_slug/test",
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["resource_id"] == "value resource_id/test"
        assert (
            request.url.params["resource_external_id"]
            == "value resource_external_id/test"
        )
        assert (
            request.url.params["resource_type_slug"] == "value resource_type_slug/test"
        )

    @pytest.mark.asyncio
    async def test_assign_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("user_role_assignment.json"))
        result = await async_workos.authorization.assign_role(
            "test_organization_membership_id",
            role_slug="test_role_slug",
            resource_target=ResourceTargetById(resource_id="test_value"),
        )
        assert isinstance(result, UserRoleAssignment)
        assert result.object == "role_assignment"
        assert result.id == "role_assignment_01HXYZ123456789ABCDEFGH"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/role_assignments"
        )

    @pytest.mark.asyncio
    async def test_remove_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.remove_role(
            "test_organization_membership_id",
            role_slug="test_role_slug",
            resource_target=ResourceTargetById(resource_id="test_value"),
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/role_assignments"
        )

    @pytest.mark.asyncio
    async def test_remove_role_assignment(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.remove_role_assignment(
            "test_organization_membership_id", "test_role_assignment_id"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organization_memberships/test_organization_membership_id/role_assignments/test_role_assignment_id"
        )

    @pytest.mark.asyncio
    async def test_list_organization_roles(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role_list.json"))
        result = await async_workos.authorization.list_organization_roles(
            "test_organizationId"
        )
        assert isinstance(result, RoleList)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles"
        )

    @pytest.mark.asyncio
    async def test_create_organization_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.create_organization_role(
            "test_organizationId", name="test_name"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles"
        )

    @pytest.mark.asyncio
    async def test_get_organization_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.get_organization_role(
            "test_organizationId", "test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug"
        )

    @pytest.mark.asyncio
    async def test_update_organization_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.update_organization_role(
            "test_organizationId", "test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug"
        )

    @pytest.mark.asyncio
    async def test_delete_organization_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.delete_organization_role(
            "test_organizationId", "test_slug"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug"
        )

    @pytest.mark.asyncio
    async def test_add_organization_role_permission(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.add_organization_role_permission(
            "test_organizationId", "test_slug", body_slug="test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug/permissions"
        )

    @pytest.mark.asyncio
    async def test_set_organization_role_permissions(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.set_organization_role_permissions(
            "test_organizationId", "test_slug", permissions=[]
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug/permissions"
        )

    @pytest.mark.asyncio
    async def test_remove_organization_role_permission(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.remove_organization_role_permission(
            "test_organizationId", "test_slug", "test_permissionSlug"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organizationId/roles/test_slug/permissions/test_permissionSlug"
        )

    @pytest.mark.asyncio
    async def test_get_resource_by_external_id(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_resource.json"))
        result = await async_workos.authorization.get_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id"
        )

    @pytest.mark.asyncio
    async def test_update_resource_by_external_id(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_resource.json"))
        result = await async_workos.authorization.update_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id"
        )

    @pytest.mark.asyncio
    async def test_delete_resource_by_external_id(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.delete_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith(
            "/authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id"
        )

    @pytest.mark.asyncio
    async def test_delete_resource_by_external_id_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(status_code=204)
        await async_workos.authorization.delete_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            cascade_delete=True,
        )
        request = httpx_mock.get_request()
        assert request.url.params["cascade_delete"] == "true"

    @pytest.mark.asyncio
    async def test_list_memberships_for_resource_by_external_id(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("list_user_organization_membership_base_list_data.json")
        )
        page = await async_workos.authorization.list_memberships_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserOrganizationMembershipBaseListData)

    @pytest.mark.asyncio
    async def test_list_memberships_for_resource_by_external_id_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_memberships_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            permission_slug="test_permission_slug",
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_memberships_for_resource_by_external_id_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_memberships_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            permission_slug="value permission_slug/test",
            assignment=AuthorizationAssignment("direct"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["permission_slug"] == "value permission_slug/test"
        assert request.url.params["assignment"] == "direct"

    @pytest.mark.asyncio
    async def test_list_role_assignments_for_resource_by_external_id(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json=load_fixture("list_user_role_assignment.json"))
        page = await async_workos.authorization.list_role_assignments_for_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserRoleAssignment)

    @pytest.mark.asyncio
    async def test_list_role_assignments_for_resource_by_external_id_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_role_assignments_for_resource_by_external_id(
            "test_organization_id", "test_resource_type_slug", "test_external_id"
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_role_assignments_for_resource_by_external_id_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_role_assignments_for_resource_by_external_id(
            "test_organization_id",
            "test_resource_type_slug",
            "test_external_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            role_slug="value role_slug/test",
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["role_slug"] == "value role_slug/test"

    @pytest.mark.asyncio
    async def test_list_resources(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("list_authorization_resource.json"))
        page = await async_workos.authorization.list_resources(
            parent=ParentById(parent_resource_id="test_value")
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationResource)

    @pytest.mark.asyncio
    async def test_list_resources_empty_page(self, async_workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_resources(
            parent=ParentById(parent_resource_id="test_value")
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_resources_encodes_query_params(self, async_workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_resources(
            parent=ParentById(parent_resource_id="value parent_resource_id/test"),
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            organization_id="value organization_id/test",
            resource_type_slug="value resource_type_slug/test",
            resource_external_id="value resource_external_id/test",
        )
        request = httpx_mock.get_request()
        assert (
            request.url.params["parent_resource_id"] == "value parent_resource_id/test"
        )
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["organization_id"] == "value organization_id/test"
        assert (
            request.url.params["resource_type_slug"] == "value resource_type_slug/test"
        )
        assert (
            request.url.params["resource_external_id"]
            == "value resource_external_id/test"
        )

    @pytest.mark.asyncio
    async def test_create_resource(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_resource.json"))
        result = await async_workos.authorization.create_resource(
            external_id="test_external_id",
            name="test_name",
            resource_type_slug="test_resource_type_slug",
            organization_id="test_organization_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/resources")

    @pytest.mark.asyncio
    async def test_get_resource(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_resource.json"))
        result = await async_workos.authorization.get_resource("test_resource_id")
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/resources/test_resource_id")

    @pytest.mark.asyncio
    async def test_update_resource(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_resource.json"))
        result = await async_workos.authorization.update_resource(
            "test_resource_id",
            parent_resource=ParentResourceById(parent_resource_id="test_value"),
        )
        assert isinstance(result, AuthorizationResource)
        assert result.object == "authorization_resource"
        assert result.name == "Website Redesign"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith("/authorization/resources/test_resource_id")

    @pytest.mark.asyncio
    async def test_delete_resource(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.delete_resource("test_resource_id")
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith("/authorization/resources/test_resource_id")

    @pytest.mark.asyncio
    async def test_delete_resource_encodes_query_params(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        await async_workos.authorization.delete_resource(
            "test_resource_id", cascade_delete=True
        )
        request = httpx_mock.get_request()
        assert request.url.params["cascade_delete"] == "true"

    @pytest.mark.asyncio
    async def test_list_memberships_for_resource(self, async_workos, httpx_mock):
        httpx_mock.add_response(
            json=load_fixture("list_user_organization_membership_base_list_data.json")
        )
        page = await async_workos.authorization.list_memberships_for_resource(
            "test_resource_id", permission_slug="test_permission_slug"
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserOrganizationMembershipBaseListData)

    @pytest.mark.asyncio
    async def test_list_memberships_for_resource_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_memberships_for_resource(
            "test_resource_id", permission_slug="test_permission_slug"
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_memberships_for_resource_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_memberships_for_resource(
            "test_resource_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            permission_slug="value permission_slug/test",
            assignment=AuthorizationAssignment("direct"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["permission_slug"] == "value permission_slug/test"
        assert request.url.params["assignment"] == "direct"

    @pytest.mark.asyncio
    async def test_list_role_assignments_for_resource(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("list_user_role_assignment.json"))
        page = await async_workos.authorization.list_role_assignments_for_resource(
            "test_resource_id"
        )
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], UserRoleAssignment)

    @pytest.mark.asyncio
    async def test_list_role_assignments_for_resource_empty_page(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_role_assignments_for_resource(
            "test_resource_id"
        )
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_role_assignments_for_resource_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_role_assignments_for_resource(
            "test_resource_id",
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
            role_slug="value role_slug/test",
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"
        assert request.url.params["role_slug"] == "value role_slug/test"

    @pytest.mark.asyncio
    async def test_list_environment_roles(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role_list.json"))
        result = await async_workos.authorization.list_environment_roles()
        assert isinstance(result, RoleList)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/roles")

    @pytest.mark.asyncio
    async def test_create_environment_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.create_environment_role(
            slug="test_slug", name="test_name"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/roles")

    @pytest.mark.asyncio
    async def test_get_environment_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.get_environment_role("test_slug")
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/roles/test_slug")

    @pytest.mark.asyncio
    async def test_update_environment_role(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.update_environment_role("test_slug")
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith("/authorization/roles/test_slug")

    @pytest.mark.asyncio
    async def test_add_environment_role_permission(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.add_environment_role_permission(
            "test_slug", body_slug="test_slug"
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/roles/test_slug/permissions")

    @pytest.mark.asyncio
    async def test_set_environment_role_permissions(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("role.json"))
        result = await async_workos.authorization.set_environment_role_permissions(
            "test_slug", permissions=[]
        )
        assert isinstance(result, Role)
        assert result.slug == "admin"
        assert result.object == "role"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith("/authorization/roles/test_slug/permissions")

    @pytest.mark.asyncio
    async def test_list_permissions(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("list_authorization_permission.json"))
        page = await async_workos.authorization.list_permissions()
        assert isinstance(page, AsyncPage)
        assert len(page.data) == 1
        assert isinstance(page.data[0], AuthorizationPermission)

    @pytest.mark.asyncio
    async def test_list_permissions_empty_page(self, async_workos, httpx_mock):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        page = await async_workos.authorization.list_permissions()
        assert isinstance(page, AsyncPage)
        assert page.data == []

    @pytest.mark.asyncio
    async def test_list_permissions_encodes_query_params(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_permissions(
            limit=10,
            before="cursor before",
            after="cursor/after",
            order=PaginationOrder("value_order"),
        )
        request = httpx_mock.get_request()
        assert request.url.params["limit"] == "10"
        assert request.url.params["before"] == "cursor before"
        assert request.url.params["after"] == "cursor/after"
        assert request.url.params["order"] == "value_order"

    @pytest.mark.asyncio
    async def test_create_permission(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("permission.json"))
        result = await async_workos.authorization.create_permission(
            slug="test_slug", name="test_name"
        )
        assert isinstance(result, Permission)
        assert result.object == "permission"
        assert result.id == "perm_01HXYZ123456789ABCDEFGHIJ"
        request = httpx_mock.get_request()
        assert request.method == "POST"
        assert request.url.path.endswith("/authorization/permissions")

    @pytest.mark.asyncio
    async def test_get_permission(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_permission.json"))
        result = await async_workos.authorization.get_permission("test_slug")
        assert isinstance(result, AuthorizationPermission)
        assert result.object == "permission"
        assert result.id == "perm_01HXYZ123456789ABCDEFGHIJ"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith("/authorization/permissions/test_slug")

    @pytest.mark.asyncio
    async def test_update_permission(self, async_workos, httpx_mock):
        httpx_mock.add_response(json=load_fixture("authorization_permission.json"))
        result = await async_workos.authorization.update_permission("test_slug")
        assert isinstance(result, AuthorizationPermission)
        assert result.object == "permission"
        assert result.id == "perm_01HXYZ123456789ABCDEFGHIJ"
        request = httpx_mock.get_request()
        assert request.method == "PATCH"
        assert request.url.path.endswith("/authorization/permissions/test_slug")

    @pytest.mark.asyncio
    async def test_delete_permission(self, async_workos, httpx_mock):
        httpx_mock.add_response(status_code=204)
        result = await async_workos.authorization.delete_permission("test_slug")
        assert result is None
        request = httpx_mock.get_request()
        assert request.method == "DELETE"
        assert request.url.path.endswith("/authorization/permissions/test_slug")

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_with_request_options(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(json={"data": [], "list_metadata": {}})
        await async_workos.authorization.list_group_role_assignments(
            "test_group_id", request_options={"extra_headers": {"X-Custom": "value"}}
        )
        request = httpx_mock.get_request()
        assert request.headers["X-Custom"] == "value"

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_unauthorized(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(status_code=401, json={"message": "Unauthorized"})
        with pytest.raises(AuthenticationError):
            await async_workos.authorization.list_group_role_assignments(
                "test_group_id"
            )

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_not_found(self, httpx_mock):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=404, json={"message": "Not found"})
            with pytest.raises(NotFoundError):
                await workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_rate_limited(self, httpx_mock):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(
                status_code=429,
                headers={"Retry-After": "0"},
                json={"message": "Slow down"},
            )
            with pytest.raises(RateLimitExceededError):
                await workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_server_error(self, httpx_mock):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=500, json={"message": "Server error"})
            with pytest.raises(ServerError):
                await workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_bad_request(self, httpx_mock):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=400, json={"message": "Bad request"})
            with pytest.raises(BadRequestError):
                await workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_group_role_assignments_unprocessable(self, httpx_mock):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=422, json={"message": "Unprocessable"})
            with pytest.raises(UnprocessableEntityError):
                await workos.authorization.list_group_role_assignments("test_group_id")
        finally:
            await workos.close()
