|
import pytest |
|
import httpx |
|
pytest_plugins = ["pytest_asyncio"] |
|
|
|
@pytest.mark.asyncio |
|
async def test_register_user(client, initialize_tests): |
|
async with httpx.AsyncClient() as async_client: |
|
response = await async_client.post("http://localhost:8001/users/register", json={ |
|
"username": "testwuser", |
|
"email": "[email protected]", |
|
"password": "testpassword123" |
|
}) |
|
|
|
assert response.status_code == 200 |
|
data = response.json() |
|
assert data["success"] == True |
|
assert data["data"]["username"] == "testuser" |
|
assert data["data"]["email"] == "[email protected]" |
|
|
|
@pytest.mark.asyncio |
|
async def test_register_duplicate_email(client, initialize_tests): |
|
|
|
async with httpx.AsyncClient() as async_client: |
|
await async_client.post("http://localhost:8001/users/register", json={ |
|
"username": "existing", |
|
"email": "[email protected]", |
|
"password": "password123" |
|
}) |
|
|
|
|
|
response = await async_client.post("http://localhost:8001/users/register", json={ |
|
"username": "testwuser", |
|
"email": "[email protected]", |
|
"password": "testpassword123" |
|
}) |
|
|
|
assert response.status_code == 400 |
|
data = response.json() |
|
print(data) |
|
assert data["success"] == False |
|
assert "Email already registered" in data["message"] |
|
|
|
|
|
@pytest.mark.asyncio |
|
async def test_get_portfolio(client, initialize_tests): |
|
async with httpx.AsyncClient() as async_client: |
|
|
|
register_response = await async_client.post("http://localhost:8001/users/register", json={ |
|
"username": "portfoliouser", |
|
"email": "[email protected]", |
|
"password": "password123" |
|
}) |
|
user_id = register_response.json()["data"]["id"] |
|
|
|
|
|
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_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 |
|
|
|
|
|
|