Spaces:
Running
Running
| import pytest | |
| import httpx | |
| pytest_plugins = ["pytest_asyncio"] | |
| async def test_register_user(client, initialize_tests): | |
| async with httpx.AsyncClient() as async_client: | |
| response = await async_client.post("http://localhost:8000/users/register", json={ | |
| "username": "testwuser", | |
| "email": "test@example.com", | |
| "password": "testpassword123" | |
| }) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["success"] == True | |
| assert data["data"]["username"] == "testuser" | |
| assert data["data"]["email"] == "test@example.com" | |
| async def test_register_duplicate_email(client, initialize_tests): | |
| # First registration | |
| async with httpx.AsyncClient() as async_client: | |
| await async_client.post("http://localhost:8001/users/register", json={ | |
| "username": "existing", | |
| "email": "existing@example.com", | |
| "password": "password123" | |
| }) | |
| # Attempt duplicate registration | |
| response = await async_client.post("http://localhost:8001/users/register", json={ | |
| "username": "testwuser", | |
| "email": "existing@example.com", | |
| "password": "testpassword123" | |
| }) | |
| assert response.status_code == 400 | |
| data = response.json() | |
| print(data) | |
| assert data["success"] == False | |
| assert "Email already registered" in data["message"] | |
| async def test_get_portfolio(client, initialize_tests): | |
| async with httpx.AsyncClient() as async_client: | |
| # First create a user | |
| register_response = await async_client.post("http://localhost:8001/users/register", json={ | |
| "username": "portfoliouser", | |
| "email": "portfolio@example.com", | |
| "password": "password123" | |
| }) | |
| user_id = register_response.json()["data"]["id"] | |
| # Create a portfolio for the user | |
| portfolio_response = await async_client.post(f"http://localhost:8001/users/{user_id}/portfolio", json={ | |
| "name": "Test Portfolio" | |
| }) | |
| assert portfolio_response.status_code == 200 | |
| assert portfolio_response.json()["success"] == True | |
| # Get the portfolio | |
| get_response = await async_client.get(f"http://localhost:8001/users/{user_id}/portfolio") | |
| assert get_response.status_code == 200 | |
| data = get_response.json() | |
| assert data["success"] == True | |
| assert "data" in data | |