You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.4 KiB

from test_main import *
import pytest
@pytest.mark.order(1)
def test_register_user():
response = client.post("/register", json={"username": "testuser", "password": "testpassword"})
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert "token_type" in data
assert "user_id" in data
response = client.post("/register", json={"username": "testuser", "password": "testpassword"})
assert response.status_code == 409 # Conflict - Cannot create two times the same user
def test_login_user():
response = client.post("/login", data={"username": "testuser", "password": "testpassword"})
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert "token_type" in data
assert "user_id" in data
response = client.post("/login", data={"username": "testuser", "password": "BADpassword"})
assert response.status_code == 401 # Unauthorized, bad pwd
def test_search_users():
login_response = client.post("/login", data={"username": "testuser", "password": "testpassword"})
token = login_response.json()["access_token"]
response = client.get("/users?name=testuser", headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert data[0]["username"] == "testuser"