import pytest import httpx pytest_plugins = ["pytest_asyncio"] @pytest.mark.asyncio async def test_queue_import_stock(client, initialize_tests): async with httpx.AsyncClient() as async_client: response = await async_client.post("http://localhost:8001/stocks/import/CRDB") assert response.status_code == 200 data = response.json() assert data["success"] == True assert data["message"] == "Stock import task queued" assert "task_id" in data["data"] @pytest.mark.asyncio async def test_get_stock_prices_not_found(client, initialize_tests): async with httpx.AsyncClient() as async_client: response = await async_client.get("http://localhost:8001/stocks/INVALID/prices") assert response.status_code == 404 data = response.json() assert data["success"] == False assert "Stock not found" in data["message"] @pytest.mark.asyncio async def test_get_stock_prices(client, initialize_tests): async with httpx.AsyncClient() as async_client: # First import a stock await async_client.post("http://localhost:8001/stocks/import/CRDB") # Then get its prices response = await async_client.get("http://localhost:8001/stocks/CRDB/prices") assert response.status_code == 200 data = response.json() assert data["success"] == True assert data["message"] == "Stock prices retrieved" assert "prices" in data["data"] @pytest.mark.asyncio async def test_get_stock_metrics(client, initialize_tests): async with httpx.AsyncClient() as async_client: # First import a stock await async_client.post("http://localhost:8001/stocks/import/CRDB") # Then get its metrics response = await async_client.get("http://localhost:8001/stocks/CRDB/metrics") assert response.status_code == 200 data = response.json() print(data) assert data["success"] == True assert data["message"] == "Stock metrics calculated" assert "metrics" in data["data"]