File size: 2,077 Bytes
9d4bd7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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"]