hotspot / App /Tests /test_user_routes.py
Mbonea's picture
new age with tortole user works but not tests
b856986
raw
history blame
2.85 kB
import pytest
from httpx import AsyncClient
from App.app import app # Assuming app.py initializes and configures the FastAPI instance
# Define test user data
test_user = {
"name": "Testasd User",
"email": "[email protected]",
"password": "strongasdpassword123",
"phoneNumber": "1234897890",
"mac_address": "strdding"}
reset_password_data = {
"phoneNumber": "1234897890",
"new_password": "newpassword123"
}
@pytest.mark.asyncio
async def test_register_user():
async with AsyncClient(app=app, base_url="https://8000-mboneaewall-templatebac-t1vqae3xohv.ws-eu116.gitpod.io/") as client:
response = await client.post("/user/register", json=test_user)
assert response.status_code == 201
assert response.json()["code"] == 200
assert response.json()["message"] == "User created successfully"
@pytest.mark.asyncio
async def test_login_user():
async with AsyncClient(app=app, base_url="https://8000-mboneaewall-templatebac-t1vqae3xohv.ws-eu116.gitpod.io/") as client:
login_data = {"phoneNumber": test_user["phoneNumber"], "password": test_user["password"],"mac_address": "strdding"}
response = await client.post("/user/login", data=login_data)
assert response.status_code == 200
assert "access_token" in response.json()
@pytest.mark.asyncio
async def test_forgot_password():
async with AsyncClient(app=app, base_url="https://8000-mboneaewall-templatebac-t1vqae3xohv.ws-eu116.gitpod.io/") as client:
response = await client.post("/user/forgot-password", json={"phoneNumber": test_user["phoneNumber"]})
assert response.status_code == 200
assert response.json()["code"] == 200
assert response.json()["message"] == "Password reset token sent. Check your phone for further instructions."
@pytest.mark.asyncio
async def test_verify_reset_token():
async with AsyncClient(app=app, base_url="https://8000-mboneaewall-templatebac-t1vqae3xohv.ws-eu116.gitpod.io/") as client:
# Mock the reset token for testing (this would typically be retrieved from the response)
verify_data = {"phoneNumber": test_user["phoneNumber"], "reset_token": "123456"}
response = await client.post("/user/verify-reset-token", json=verify_data)
assert response.status_code == 200
assert response.json()["code"] == 200
assert response.json()["message"] == "Token verified. You may now reset your password."
@pytest.mark.asyncio
async def test_reset_password():
async with AsyncClient(app=app, base_url="https://8000-mboneaewall-templatebac-t1vqae3xohv.ws-eu116.gitpod.io/") as client:
response = await client.post("/user/reset-password", json=reset_password_data)
assert response.status_code == 200
assert response.json()["code"] == 200
assert response.json()["message"] == "Password has been reset successfully."