136 lines
5.1 KiB
Python
136 lines
5.1 KiB
Python
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
|
|
async def test_get_users(ac: AsyncClient):
|
|
response = await ac.get("/users")
|
|
assert response.status_code == 200
|
|
assert type(response.json()) == list
|
|
assert len(response.json()) == 3
|
|
|
|
|
|
@pytest.mark.parametrize("email,username,password,date_of_birth,status_code", [
|
|
("sosi@lox.com", "sobakasutulaya", "12311231", "1990-01-01", 200),
|
|
("sosi@lox.com", "sobakasutulaya", "12311231", "1990-01-01", 409),
|
|
("lox@sosi.com", "sobakasutulaya", "12311231", "1990-01-01", 409),
|
|
("lox@sosi.com", "sobakastroinaya", "3228", "1990-01-01", 422),
|
|
("lox@sosi.com", "sobakastroinaya", "asdwdawdasd", "2030-01-01", 422),
|
|
("lox@sosi.com", "sobakastroinaya", "asdwdawdasd", "2000-01-01", 200),
|
|
])
|
|
async def test_register_user(email, username, password, date_of_birth, status_code, ac: AsyncClient):
|
|
response = await ac.post("/users/register", json={
|
|
"email": email,
|
|
"username": username,
|
|
"password": password,
|
|
"date_of_birth": date_of_birth
|
|
})
|
|
|
|
assert response.status_code == status_code
|
|
|
|
|
|
@pytest.mark.parametrize("email_or_username,password,status_code", [
|
|
("sosi@lox.com", "12311231", 200),
|
|
("sobakasutulaya", "12311231", 200),
|
|
("sobakastroinaya", "12311231", 401),
|
|
("sosi@lox.com", "123123", 401),
|
|
("urec@urec.com", "12311231", 200),
|
|
("sobakasutulaya", 12311231, 422),
|
|
(12311231, "sobakasutulaya", 422),
|
|
])
|
|
async def test_login_user(email_or_username: str, password: str, status_code: int, ac: AsyncClient):
|
|
response = await ac.post("/users/login", json={
|
|
"email_or_username": email_or_username,
|
|
"password": password
|
|
})
|
|
assert response.status_code == status_code
|
|
if status_code == 200:
|
|
assert "access_token" in response.json()
|
|
assert "black_phoenix_access_token" in response.cookies
|
|
|
|
|
|
async def test_logout_user(ac: AsyncClient):
|
|
response = await ac.post("/users/logout")
|
|
assert response.status_code == 200
|
|
assert "black_phoenix_access_token" not in response.cookies
|
|
|
|
|
|
async def test_get_user(ac: AsyncClient):
|
|
await ac.post("/users/login", json={
|
|
"email_or_username": "urec@urec.com",
|
|
"password": "12311231"
|
|
})
|
|
response = await ac.get("/users/me")
|
|
assert response.status_code == 200
|
|
assert response.json()["email"] == "urec@urec.com"
|
|
assert response.json()["black_phoenix"] == False
|
|
|
|
|
|
@pytest.mark.parametrize("username,password,statuscode", [
|
|
("urec", "12311231", 409),
|
|
("neurec", "12311231", 200),
|
|
("urec", "adw", 409),
|
|
("urec", "12311231", 200),
|
|
])
|
|
async def test_rename_user(username: str, password: str, statuscode: int, ac: AsyncClient):
|
|
await ac.post("/users/login", json={
|
|
"email_or_username": "urec@urec.com",
|
|
"password": "12311231"
|
|
})
|
|
response = await ac.patch("/users/rename", json={
|
|
"username": username,
|
|
"password": password
|
|
})
|
|
assert response.status_code == statuscode
|
|
if response.status_code == 200:
|
|
assert response.json()["username"] == username
|
|
|
|
|
|
@pytest.mark.parametrize("avatar_url,password,statuscode", [
|
|
("https://images.black-phoenix.ru/static/images/avatars/v6BtxTxfCFi2dBAl_avatar.png", "12311231", 200),
|
|
(
|
|
"https://images.black-phoenix.ru/static/images/%D1%82%D1%8B%20%D1%83%D0%B6%D0%B5%20%D0%BF%D0%B5%D1%88%D0%BA%D0%B0%20BP.png",
|
|
"adw", 409),
|
|
(
|
|
"https://images.black-phoenix.ru/static/images/%D1%82%D1%8B%20%D1%83%D0%B6%D0%B5%20%D0%BF%D0%B5%D1%88%D0%BA%D0%B0%20BP.png",
|
|
"12311231", 200),
|
|
])
|
|
async def test_change_avatar(avatar_url: str, password: str, statuscode: int, ac: AsyncClient):
|
|
await ac.post("/users/login", json={
|
|
"email_or_username": "urec@urec.com",
|
|
"password": "12311231"
|
|
})
|
|
response = await ac.patch("/users/change_avatar", json={
|
|
"new_avatar_image": avatar_url,
|
|
"password": password
|
|
})
|
|
assert response.status_code == statuscode
|
|
if response.status_code == 200:
|
|
assert response.json()["new_avatar_image"] == avatar_url
|
|
|
|
|
|
@pytest.mark.parametrize("login_password,current_password,new_password1,new_password2,statuscode", [
|
|
("12311231", "12311231", "12311231", "12311231", 200),
|
|
("12311231", "12311231", "1231121", "12311231", 422),
|
|
("12311231", "12311231", "1231121", "1231231", 422),
|
|
("12311231", "12311231", "1231121", "1231121", 422),
|
|
("12311231", "12311231", "12311231", "1231121", 422),
|
|
("12311231", "1231131", "12311231", "12311231", 422),
|
|
("12311231", "12311231", "12311241", "12311241", 200),
|
|
("12311241", "12311231", "12311241", "12311241", 409),
|
|
("12311241", "12311241", "12311231", "12311231", 200),
|
|
])
|
|
async def test_change_password(
|
|
login_password: str, current_password: str, new_password1: str, new_password2: str, statuscode: int, ac: AsyncClient
|
|
):
|
|
await ac.post("/users/login", json={
|
|
"email_or_username": "urec@urec.com",
|
|
"password": login_password
|
|
})
|
|
response = await ac.patch("/users/change_password", json={
|
|
"current_password": current_password,
|
|
"new_password": new_password1,
|
|
"new_password2": new_password2
|
|
})
|
|
|
|
assert response.status_code == statuscode
|
|
|