Add pytest test files for microservices
- Created test files for GPU service (tests/test_main.py) - Created test files for Marketplace service (tests/test_main.py) - Created test files for Trading service (tests/test_main.py) - Created test files for Governance service (tests/test_main.py) - Created integration tests for API gateway (tests/test_gateway.py) - Added pytest dependencies to all service pyproject.toml files - Created TEST_COVERAGE_REQUIREMENTS.md documenting coverage targets and best practices This completes Phase 8: Create pytest test files for microservices
This commit is contained in:
@@ -13,6 +13,12 @@ dependencies = [
|
||||
"aitbc-core",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
test = [
|
||||
"pytest>=7.4.0",
|
||||
"pytest-asyncio>=0.21.0",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
@@ -21,3 +27,6 @@ build-backend = "poetry.core.masonry.api"
|
||||
packages = [
|
||||
{ include = "api_gateway", from = "src" }
|
||||
]
|
||||
|
||||
[tool.poetry.extras]
|
||||
test = ["pytest", "pytest-asyncio"]
|
||||
|
||||
3
apps/api-gateway/tests/__init__.py
Normal file
3
apps/api-gateway/tests/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
API Gateway tests
|
||||
"""
|
||||
71
apps/api-gateway/tests/test_gateway.py
Normal file
71
apps/api-gateway/tests/test_gateway.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
Test API Gateway routing
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from api_gateway.main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
"""Create test client for API Gateway"""
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_gateway_health_check(client):
|
||||
"""Test gateway health check endpoint"""
|
||||
response = client.get("/health")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "healthy"
|
||||
assert data["service"] == "api-gateway"
|
||||
|
||||
|
||||
def test_service_registry(client):
|
||||
"""Test service registry endpoint"""
|
||||
response = client.get("/services")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "services" in data
|
||||
services = data["services"]
|
||||
assert isinstance(services, list)
|
||||
# Check that GPU service is registered
|
||||
gpu_service = next((s for s in services if s["name"] == "gpu"), None)
|
||||
assert gpu_service is not None
|
||||
assert gpu_service["url"] == "http://localhost:8101"
|
||||
assert "/gpu/*" in gpu_service["routes"]
|
||||
|
||||
|
||||
def test_gpu_route_proxy(client):
|
||||
"""Test that gateway proxies requests to GPU service"""
|
||||
# This test requires GPU service to be running
|
||||
# In CI, this would be mocked or services would be started
|
||||
response = client.get("/gpu/health")
|
||||
# May fail if service not running, but tests routing logic
|
||||
assert response.status_code in [200, 503] # 503 if service down
|
||||
|
||||
|
||||
def test_marketplace_route_proxy(client):
|
||||
"""Test that gateway proxies requests to Marketplace service"""
|
||||
response = client.get("/marketplace/health")
|
||||
assert response.status_code in [200, 503]
|
||||
|
||||
|
||||
def test_trading_route_proxy(client):
|
||||
"""Test that gateway proxies requests to Trading service"""
|
||||
response = client.get("/trading/health")
|
||||
assert response.status_code in [200, 503]
|
||||
|
||||
|
||||
def test_governance_route_proxy(client):
|
||||
"""Test that gateway proxies requests to Governance service"""
|
||||
response = client.get("/governance/health")
|
||||
assert response.status_code in [200, 503]
|
||||
|
||||
|
||||
def test_unknown_route(client):
|
||||
"""Test that unknown routes return 404"""
|
||||
response = client.get("/unknown/path")
|
||||
assert response.status_code == 404
|
||||
Reference in New Issue
Block a user