anyway/backend/src/tests/test_user.py
Helldragon67 f258df8e72
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m15s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 48s
Build and release debug APK / Build APK (pull_request) Failing after 4m38s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s
better endpoints
2025-02-17 10:27:02 +01:00

49 lines
1.3 KiB
Python

"""Collection of tests to ensure correct handling of user data."""
from fastapi.testclient import TestClient
import pytest
from ..main import app
TEST_EMAIL = "dummy@example.com"
TEST_PW = "DummyPassword123"
@pytest.fixture(scope="module")
def client():
"""Client used to call the app."""
return TestClient(app)
def test_user_handling(client) :
"""
Test the creation of a new user.
"""
# Create a new user
response = client.post(f"/user/create/{TEST_EMAIL}/{TEST_PW}")
# Verify user has been created
assert response.status_code == 200, "Failed to create dummy user"
user_id = response.json()
# Create same user again to raise an error
response = client.post(f"/user/create/{TEST_EMAIL}/{TEST_PW}")
# Verify user already exists
assert response.status_code == 422, "Failed to simulate dummy user already created."
# Delete the user.
response = client.post(f"/user/delete/{user_id}")
# Verify user has been deleted
assert response.status_code == 200, "Failed to delete dummy user."
# Delete the user again to raise an error
response = client.post(f"/user/delete/{user_id}")
# Verify user has been deleted
assert response.status_code == 404, "Failed to simulate dummy user already deleted."