-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_auth.py
33 lines (24 loc) · 1.09 KB
/
test_auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pytest
from httpx import AsyncClient
from auth.crud import hash_pass
from auth.models import User
@pytest.mark.anyio
async def test_register(client: AsyncClient):
uname, passw = ["admin2", "admin123"]
assert await User.filter(username=uname).count() == 0
data = {"username": uname, "password":hash_pass(passw)}
response = await client.post("/auth/register", json=data)
# assert response.json() == dict(data, id=1)
assert response.status_code == 201
@pytest.mark.anyio
async def test_get_active_user(client:AsyncClient):
uname, passw = ["admin", "admin123"]
newUser=await User.create(username=uname,password=hash_pass(passw))
token=newUser.create_token({'sub':newUser.username})
data = {"username": uname, "password":passw}
response = await client.get("/auth/me", headers={'Authorization':f'Bearer {token}'})
assert response.status_code==200
# response = await client.get("/auth/users")
# assert response.status_code == 200
# # assert response.json() == [dict(data, id=1)]
# assert await User.filter(username=uname).count() == 1