Spaces:
Sleeping
Sleeping
| import json | |
| from httpx import AsyncClient | |
| import pytest | |
| from app.core.config import settings | |
| async def test_users_crud(httpx_async_client: AsyncClient): | |
| # Test CREATE | |
| user_data = { | |
| "name": "John Doe", | |
| "email": "john.doe@example.com", | |
| "password": "password123", | |
| } | |
| response = await httpx_async_client.post( | |
| f"{settings.API_V1_STR}/users/", | |
| data=json.dumps(user_data), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert response.status_code == 200 | |
| user_id = response.json()["user_id"] | |
| # Test READ | |
| response = await httpx_async_client.get(f"{settings.API_V1_STR}/users/{user_id}") | |
| assert response.status_code == 200 | |
| user = response.json() | |
| assert user["name"] == user_data["name"] | |
| assert user["email"] == user_data["email"] | |
| assert "password" not in user | |
| # Test UPDATE | |
| updated_user_data = { | |
| "name": "Jane Doe", | |
| } | |
| response = await httpx_async_client.put( | |
| f"{settings.API_V1_STR}/users/{user_id}", | |
| data=json.dumps(updated_user_data), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert response.status_code == 200 | |
| updated_user = response.json() | |
| assert updated_user["name"] == updated_user_data["name"] | |
| assert updated_user["email"] == user_data["email"] | |
| assert "password" not in updated_user | |
| # Test DELETE | |
| response = await httpx_async_client.delete(f"{settings.API_V1_STR}/users/{user_id}") | |
| assert response.status_code == 200 | |