41 lines
1.9 KiB
Python
41 lines
1.9 KiB
Python
import pytest
|
|
import random
|
|
|
|
from backend.models.permission.constants import DefaultPermissionEnum
|
|
from tests.base.authentication_web import AuthenticationWeb
|
|
|
|
|
|
class TestDeletePermission:
|
|
@pytest.mark.asyncio
|
|
async def test_delete_permission_success(self, authentication_web: AuthenticationWeb):
|
|
"""Test deleting a permission successfully."""
|
|
suffix = str(random.randint(10000, 99999))
|
|
perm = await authentication_web.create_permission({
|
|
"permission_key": f"delperm_{suffix}",
|
|
"permission_name": f"delperm_{suffix}",
|
|
"description": "desc"
|
|
})
|
|
perm_id = perm.json()["id"]
|
|
resp = await authentication_web.delete_permission({"permission_id": perm_id})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["success"] is True
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_permission_fail_not_found(self, authentication_web: AuthenticationWeb):
|
|
"""Test deleting a permission fails when permission_id does not exist."""
|
|
resp = await authentication_web.delete_permission({"permission_id": "000000000000000000000000"})
|
|
assert resp.status_code == 422 or resp.status_code == 400
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_default_permission_fail(self, authentication_web: AuthenticationWeb):
|
|
"""Test deleting a default permission fails. Default permission cannot be deleted."""
|
|
# Query a default role
|
|
resp = await authentication_web.query_permissions(
|
|
params={"page": 1, "page_size": 2, "permission_key": DefaultPermissionEnum.CHANGE_PERMISSIONS.value.permission_key})
|
|
json = resp.json()
|
|
default_permission_id = json["items"][0]["id"]
|
|
resp = await authentication_web.delete_permission(perm_data={"permission_id": default_permission_id})
|
|
assert resp.status_code == 422 or resp.status_code == 400
|
|
|
|
if __name__ == '__main__':
|
|
pytest.main([__file__]) |