37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from config.settings import settings
|
|
from router.router import app
|
|
|
|
KEY = "test-admin-key"
|
|
pytestmark = pytest.mark.usefixtures("no_bot_comments")
|
|
|
|
|
|
def client():
|
|
return AsyncClient(transport=ASGITransport(app=app), base_url="http://test")
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_admin_users_needs_key(monkeypatch):
|
|
monkeypatch.setattr(settings, "admin_api_key", KEY)
|
|
async with client() as c:
|
|
assert (await c.get("/v1/admin/users")).status_code == 401
|
|
assert (await c.get("/v1/admin/users", headers={"X-Admin-Key": "wrong"})).status_code == 401
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_admin_users_lists_level_and_points(offline, monkeypatch):
|
|
monkeypatch.setattr(settings, "admin_api_key", KEY)
|
|
async with client() as c:
|
|
body = (await c.post("/v1/auth/signup", json={"login_id": "adm_user1", "password": "password1", "nickname": "가짜닉"})).json()
|
|
h = {"Authorization": f"Bearer {body['access_token']}"}
|
|
await c.post("/v1/auth/terms", headers=h)
|
|
await c.post("/v1/level/attend", headers=h)
|
|
|
|
res = (await c.get("/v1/admin/users", headers={"X-Admin-Key": KEY})).json()
|
|
me = next(u for u in res["items"] if u["nickname"] == "가짜닉")
|
|
assert me["provider"] == 1 and me["points"] == 10 and me["level"] == 1 and me["level_name"] == "이슬" and me["last_active"]
|
|
assert "login_id" not in me and "birth_date" not in me
|
|
assert res["counts"]["1"] >= 1 and res["total"] >= 1
|