import random import pytest from tests.base.authentication_web import AuthenticationWeb class TestQueryPermission: @pytest.mark.asyncio async def test_query_all_permissions(self, authentication_web: AuthenticationWeb): """Test querying all permissions returns a list.""" resp = await authentication_web.query_permissions({}) assert resp.status_code == 200 json = resp.json() assert "items" in json assert "total" in json @pytest.mark.asyncio async def test_query_permissions_by_key(self, authentication_web: AuthenticationWeb): """Test querying permissions by permission_key with fuzzy search.""" suffix = str(random.randint(10000, 99999)) await authentication_web.create_permission({ "permission_key": f"querykey_{suffix}", "permission_name": f"querykey_{suffix}", "description": "desc" }) resp = await authentication_web.query_permissions({"permission_key": f"querykey_{suffix}"}) assert resp.status_code == 200 json = resp.json() assert any(f"querykey_{suffix}" in item["permission_key"] for item in json["items"]) @pytest.mark.asyncio async def test_query_permissions_by_name(self, authentication_web: AuthenticationWeb): """Test querying permissions by permission_name with fuzzy search.""" suffix = str(random.randint(10000, 99999)) await authentication_web.create_permission({ "permission_key": f"queryname_{suffix}", "permission_name": f"queryname_{suffix}", "description": "desc" }) resp = await authentication_web.query_permissions({"permission_name": f"queryname_{suffix}"}) assert resp.status_code == 200 json = resp.json() assert any(f"queryname_{suffix}" in item["permission_name"] for item in json["items"]) @pytest.mark.asyncio async def test_query_permissions_pagination(self, authentication_web: AuthenticationWeb): """Test querying permissions with pagination.""" resp = await authentication_web.query_permissions({"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 if __name__ == '__main__': pytest.main([__file__])