46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
from src.core.settings import settings
|
|
from src.schemas.users import User
|
|
|
|
|
|
async def test_registration(ac):
|
|
user = {"username": "kot", "email": "super@kot.ru", "password": "P@ssw0rd"}
|
|
result = await ac.post(
|
|
f"{settings.api.v1_login_url}/signup",
|
|
json=user,
|
|
)
|
|
assert result.status_code == 200
|
|
assert User.model_validate(result.json())
|
|
assert result.json()["is_active"]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"fingerprint, username,password,expected_status",
|
|
[("string", "kot", "P@ssw0rd", 200), ("", "kot", "P@ssw0rd", 422)],
|
|
)
|
|
async def test_login(
|
|
ac: AsyncClient,
|
|
fingerprint: str,
|
|
username: str,
|
|
password: str,
|
|
expected_status: int,
|
|
):
|
|
result = await ac.post(
|
|
f"{settings.api.v1_login_url}/login",
|
|
data={
|
|
"fingerprint": fingerprint,
|
|
"grant_type": "password",
|
|
"username": username,
|
|
"password": password,
|
|
},
|
|
)
|
|
assert result.status_code == expected_status
|
|
if expected_status == 200:
|
|
assert result.json().get("access_token") is not None
|
|
else:
|
|
json_response = result.json()
|
|
if expected_status == 422:
|
|
assert "detail" in json_response
|