Download tests/test_user_auth.py from binhugg2/api: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/spaces/binhugg2/api/resolve/main/tests/test_user_auth.py
- Command line
-
hf download hf://spaces/binhugg2/api/tests/test_user_auth.py
-
curl -L -o test_user_auth.py https://huggingface.co/spaces/binhugg2/api/resolve/main/tests/test_user_auth.py
2 kB
| import pytest | |
| async def test_user_register(client): | |
| resp = await client.post("/user/auth/register", json={ | |
| "username": "newuser01", | |
| "password": "Pass@1234", | |
| }) | |
| assert resp.status_code == 200 | |
| body = resp.json() | |
| assert body["code"] == 0 | |
| assert "accessToken" in body["data"] | |
| async def test_user_register_duplicate(client): | |
| await client.post("/user/auth/register", json={ | |
| "username": "dupuser", | |
| "password": "Pass@1234", | |
| }) | |
| resp = await client.post("/user/auth/register", json={ | |
| "username": "dupuser", | |
| "password": "Pass@1234", | |
| }) | |
| assert resp.json()["code"] == 40001 | |
| async def test_user_login_success(client): | |
| await client.post("/user/auth/register", json={ | |
| "username": "loginuser", | |
| "password": "Pass@1234", | |
| }) | |
| resp = await client.post("/user/auth/login", json={ | |
| "username": "loginuser", | |
| "password": "Pass@1234", | |
| }) | |
| assert resp.status_code == 200 | |
| assert resp.json()["code"] == 0 | |
| assert "accessToken" in resp.json()["data"] | |
| async def test_user_login_wrong_password(client): | |
| await client.post("/user/auth/register", json={ | |
| "username": "wrongpwduser", | |
| "password": "Pass@1234", | |
| }) | |
| resp = await client.post("/user/auth/login", json={ | |
| "username": "wrongpwduser", | |
| "password": "WrongPass", | |
| }) | |
| assert resp.json()["code"] == 40001 | |
| async def test_user_profile(client, user_token): | |
| resp = await client.get( | |
| "/user/auth/profile", | |
| headers={"Authorization": f"Bearer {user_token}"}, | |
| ) | |
| assert resp.status_code == 200 | |
| body = resp.json() | |
| assert body["code"] == 0 | |
| assert body["data"]["username"] == "testuser" | |
| async def test_user_profile_unauthorized(client): | |
| resp = await client.get("/user/auth/profile") | |
| assert resp.status_code == 403 | |