Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /fief-dev_fief /tests /test_apps_api_permissions.py
| import uuid | |
| from typing import Any | |
| import httpx | |
| import pytest | |
| from fastapi import status | |
| from fief.errors import APIErrorCode | |
| from tests.data import TestData, data_mapping | |
| from tests.helpers import HTTPXResponseAssertion | |
| class TestListPermissions: | |
| async def test_unauthorized( | |
| self, | |
| unauthorized_api_assertions: HTTPXResponseAssertion, | |
| test_client_api: httpx.AsyncClient, | |
| ): | |
| response = await test_client_api.get("/permissions/") | |
| unauthorized_api_assertions(response) | |
| async def test_valid( | |
| self, | |
| params: dict[str, Any], | |
| nb_results: int, | |
| test_client_api: httpx.AsyncClient, | |
| test_data: TestData, | |
| ): | |
| response = await test_client_api.get("/permissions/", params=params) | |
| assert response.status_code == status.HTTP_200_OK | |
| json = response.json() | |
| assert json["count"] == nb_results | |
| class TestGetPermission: | |
| async def test_unauthorized( | |
| self, | |
| unauthorized_api_assertions: HTTPXResponseAssertion, | |
| test_client_api: httpx.AsyncClient, | |
| test_data: TestData, | |
| ): | |
| permission = test_data["permissions"]["castles:create"] | |
| response = await test_client_api.get(f"/permissions/{permission.id}") | |
| unauthorized_api_assertions(response) | |
| async def test_not_existing( | |
| self, test_client_api: httpx.AsyncClient, not_existing_uuid: uuid.UUID | |
| ): | |
| response = await test_client_api.get(f"/permissions/{not_existing_uuid}") | |
| assert response.status_code == status.HTTP_404_NOT_FOUND | |
| async def test_valid(self, test_client_api: httpx.AsyncClient, test_data: TestData): | |
| permission = test_data["permissions"]["castles:create"] | |
| response = await test_client_api.get(f"/permissions/{permission.id}") | |
| assert response.status_code == status.HTTP_200_OK | |
| class TestCreatePermission: | |
| async def test_unauthorized( | |
| self, | |
| unauthorized_api_assertions: HTTPXResponseAssertion, | |
| test_client_api: httpx.AsyncClient, | |
| ): | |
| response = await test_client_api.post("/permissions/", json={}) | |
| unauthorized_api_assertions(response) | |
| async def test_already_existing_codename( | |
| self, test_client_api: httpx.AsyncClient, test_data: TestData | |
| ): | |
| response = await test_client_api.post( | |
| "/permissions/", | |
| json={ | |
| "name": "New permission", | |
| "codename": "castles:create", | |
| }, | |
| ) | |
| assert response.status_code == status.HTTP_400_BAD_REQUEST | |
| json = response.json() | |
| assert json["detail"] == APIErrorCode.PERMISSION_CREATE_CODENAME_ALREADY_EXISTS | |
| async def test_valid(self, test_client_api: httpx.AsyncClient): | |
| response = await test_client_api.post( | |
| "/permissions/", | |
| json={ | |
| "name": "New permission", | |
| "codename": "new_permission", | |
| }, | |
| ) | |
| assert response.status_code == status.HTTP_201_CREATED | |
| json = response.json() | |
| assert json["name"] == "New permission" | |
| assert json["codename"] == "new_permission" | |
| class TestUpdatePermission: | |
| async def test_unauthorized( | |
| self, | |
| unauthorized_api_assertions: HTTPXResponseAssertion, | |
| test_client_api: httpx.AsyncClient, | |
| test_data: TestData, | |
| ): | |
| permission = test_data["permissions"]["castles:create"] | |
| response = await test_client_api.patch(f"/permissions/{permission.id}", json={}) | |
| unauthorized_api_assertions(response) | |
| async def test_not_existing( | |
| self, test_client_api: httpx.AsyncClient, not_existing_uuid: uuid.UUID | |
| ): | |
| response = await test_client_api.patch( | |
| f"/permissions/{not_existing_uuid}", json={} | |
| ) | |
| assert response.status_code == status.HTTP_404_NOT_FOUND | |
| async def test_already_existing_codename( | |
| self, test_client_api: httpx.AsyncClient, test_data: TestData | |
| ): | |
| permission = test_data["permissions"]["castles:create"] | |
| response = await test_client_api.patch( | |
| f"/permissions/{permission.id}", json={"codename": "castles:update"} | |
| ) | |
| assert response.status_code == status.HTTP_400_BAD_REQUEST | |
| json = response.json() | |
| assert json["detail"] == APIErrorCode.PERMISSION_UPDATE_CODENAME_ALREADY_EXISTS | |
| async def test_valid( | |
| self, | |
| payload: dict[str, str], | |
| test_client_api: httpx.AsyncClient, | |
| test_data: TestData, | |
| ): | |
| permission = test_data["permissions"]["castles:create"] | |
| response = await test_client_api.patch( | |
| f"/permissions/{permission.id}", json=payload | |
| ) | |
| assert response.status_code == status.HTTP_200_OK | |
| json = response.json() | |
| for field, value in payload.items(): | |
| assert json[field] == value | |
| class TestDeletePermission: | |
| async def test_unauthorized( | |
| self, | |
| unauthorized_api_assertions: HTTPXResponseAssertion, | |
| test_client_api: httpx.AsyncClient, | |
| test_data: TestData, | |
| ): | |
| permission = test_data["permissions"]["castles:create"] | |
| response = await test_client_api.delete(f"/permissions/{permission.id}") | |
| unauthorized_api_assertions(response) | |
| async def test_not_existing( | |
| self, test_client_api: httpx.AsyncClient, not_existing_uuid: uuid.UUID | |
| ): | |
| response = await test_client_api.delete(f"/permissions/{not_existing_uuid}") | |
| assert response.status_code == status.HTTP_404_NOT_FOUND | |
| async def test_valid(self, test_client_api: httpx.AsyncClient, test_data: TestData): | |
| permission = test_data["permissions"]["castles:create"] | |
| response = await test_client_api.delete(f"/permissions/{permission.id}") | |
| assert response.status_code == status.HTTP_204_NO_CONTENT | |
Xet Storage Details
- Size:
- 6.71 kB
- Xet hash:
- f450268b5e5194f6f5ded6d536e7074c500b035d545fc612730dee2911c95899
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.