59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
import random
|
|
|
|
import pytest
|
|
|
|
from tests.base.authentication_web import AuthenticationWeb
|
|
|
|
|
|
class TestQueryRole:
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_query_all_roles(self, authentication_web: AuthenticationWeb):
|
|
"""Test querying all roles returns a list."""
|
|
resp = await authentication_web.query_roles(params={})
|
|
assert resp.status_code == 200
|
|
json = resp.json()
|
|
assert "items" in json
|
|
assert "total" in json
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_query_roles_by_key(self, authentication_web: AuthenticationWeb):
|
|
"""Test querying roles by role_key with fuzzy search."""
|
|
suffix = str(random.randint(10000, 99999))
|
|
await authentication_web.create_role({
|
|
"role_key": f"querykey_{suffix}",
|
|
"role_name": f"querykey_{suffix}",
|
|
"role_description": "desc",
|
|
"role_level": 1
|
|
})
|
|
resp = await authentication_web.query_roles(params={"role_key": f"querykey_{suffix}"})
|
|
assert resp.status_code == 200
|
|
json = resp.json()
|
|
assert any(f"querykey_{suffix}" in item["role_key"] for item in json["items"])
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_query_roles_by_name(self, authentication_web: AuthenticationWeb):
|
|
"""Test querying roles by role_name with fuzzy search."""
|
|
suffix = str(random.randint(10000, 99999))
|
|
await authentication_web.create_role({
|
|
"role_key": f"queryname_{suffix}",
|
|
"role_name": f"queryname_{suffix}",
|
|
"role_description": "desc",
|
|
"role_level": 1
|
|
})
|
|
resp = await authentication_web.query_roles(params={"role_name": f"queryname_{suffix}"})
|
|
assert resp.status_code == 200
|
|
json = resp.json()
|
|
assert any(f"queryname_{suffix}" in item["role_name"] for item in json["items"])
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_query_roles_pagination(self, authentication_web: AuthenticationWeb):
|
|
"""Test querying roles with pagination."""
|
|
resp = await authentication_web.query_roles(params={"page": 1, "page_size": 2})
|
|
assert resp.status_code == 200
|
|
json = resp.json()
|
|
assert "items" in json
|
|
assert "total" in json
|
|
assert "page" in json
|
|
assert "page_size" in json
|