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
49 lines
1.3 KiB
Python
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."
|
|
|
|
|
|
|