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.

42 lines
1.7 KiB

from test_main import *
def test_add_friend(token):
# Register another user that will be used as a friend
response = client.post("/register", json={"username": "testfriend", "password": "testpassword"})
user_id = response.json()["user_id"]
friend_data = {"friend_user_id": user_id}
response = client.post("/friend/add", json=friend_data, headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 200
data = response.json()
assert "id" in data
def test_add_friend_myself(token):
friend_data = {"friend_user_id": str(db["users"].find_one({"username": "testuser"})["_id"])}
response = client.post("/friend/add", json=friend_data, headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 409 # Cannot add yourself as a friend
def test_list_friends(token):
response = client.get("/friends", headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 200
data = response.json()
assert isinstance(data, dict)
def test_get_friend(token):
friend_id = str(db["friends"].find_one({})["_id"])
response = client.get(f"/friend/{friend_id}", headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 200
data = response.json()
assert "id" in data
assert "user_id" in data
assert "friend_user_id" in data
assert "status" in data
def test_get_friend_wrong_format(token):
response = client.get(f"/friend/randomIdThatDoesntExists", headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 422
def test_get_friend_unknown_id(token):
response = client.get(f"/friend/123456789987654321abcdef", headers={"Authorization": f"Bearer {token}"})
assert response.status_code == 404