64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
|
|
"""
|
||
|
|
Data API integration tests
|
||
|
|
"""
|
||
|
|
import pytest
|
||
|
|
from fastapi.testclient import TestClient
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.integration
|
||
|
|
class TestDataAPI:
|
||
|
|
"""Data API endpoint tests"""
|
||
|
|
|
||
|
|
def test_stats_endpoint(self, client: TestClient):
|
||
|
|
"""Test database stats endpoint"""
|
||
|
|
response = client.get("/api/v1/data/stats")
|
||
|
|
|
||
|
|
assert response.status_code == 200
|
||
|
|
data = response.json()
|
||
|
|
|
||
|
|
# Check stats structure
|
||
|
|
assert "ticker_count" in data
|
||
|
|
assert "price_count" in data
|
||
|
|
assert "financial_count" in data
|
||
|
|
assert "sector_count" in data
|
||
|
|
|
||
|
|
# Counts should be non-negative
|
||
|
|
assert data["ticker_count"] >= 0
|
||
|
|
assert data["price_count"] >= 0
|
||
|
|
assert data["financial_count"] >= 0
|
||
|
|
assert data["sector_count"] >= 0
|
||
|
|
|
||
|
|
@pytest.mark.slow
|
||
|
|
@pytest.mark.crawler
|
||
|
|
def test_collect_ticker_trigger(self, client: TestClient):
|
||
|
|
"""Test ticker collection trigger endpoint"""
|
||
|
|
response = client.post("/api/v1/data/collect/ticker")
|
||
|
|
|
||
|
|
# Should return task ID or success
|
||
|
|
assert response.status_code in [200, 202]
|
||
|
|
|
||
|
|
data = response.json()
|
||
|
|
# Should have task_id or success message
|
||
|
|
assert "task_id" in data or "message" in data
|
||
|
|
|
||
|
|
@pytest.mark.slow
|
||
|
|
@pytest.mark.crawler
|
||
|
|
def test_collect_sector_trigger(self, client: TestClient):
|
||
|
|
"""Test sector collection trigger endpoint"""
|
||
|
|
response = client.post("/api/v1/data/collect/sector")
|
||
|
|
|
||
|
|
assert response.status_code in [200, 202]
|
||
|
|
|
||
|
|
data = response.json()
|
||
|
|
assert "task_id" in data or "message" in data
|
||
|
|
|
||
|
|
def test_collect_all_trigger(self, client: TestClient):
|
||
|
|
"""Test full data collection trigger endpoint"""
|
||
|
|
response = client.post("/api/v1/data/collect/all")
|
||
|
|
|
||
|
|
# Should return task ID
|
||
|
|
assert response.status_code in [200, 202]
|
||
|
|
|
||
|
|
data = response.json()
|
||
|
|
assert "task_id" in data or "message" in data
|