Add sys import to test files and remove obsolete integration tests
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
- Add sys import to 29 test files across agent-coordinator, blockchain-event-bridge, blockchain-node, and coordinator-api - Remove apps/blockchain-event-bridge/tests/test_integration.py (obsolete bridge integration tests) - Remove apps/coordinator-api/tests/test_integration.py (obsolete API integration tests) - Implement GPU registration in marketplace_gpu.py with GPURegistry model persistence
This commit is contained in:
1
apps/agent-services/agent-registry/tests/__init__.py
Normal file
1
apps/agent-services/agent-registry/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Agent registry service tests"""
|
||||
@@ -0,0 +1,156 @@
|
||||
"""Edge case and error handling tests for agent registry service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_db():
|
||||
"""Reset database before each test"""
|
||||
import app
|
||||
# Delete the database file if it exists
|
||||
db_path = Path("agent_registry.db")
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
app.init_db()
|
||||
yield
|
||||
|
||||
# Clean up after test
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_empty_name():
|
||||
"""Test Agent with empty name"""
|
||||
from app import Agent
|
||||
agent = Agent(
|
||||
id="agent_123",
|
||||
name="",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert agent.name == ""
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_empty_chain_id():
|
||||
"""Test Agent with empty chain_id"""
|
||||
from app import Agent
|
||||
agent = Agent(
|
||||
id="agent_123",
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert agent.chain_id == ""
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_empty_endpoint():
|
||||
"""Test Agent with empty endpoint"""
|
||||
from app import Agent
|
||||
agent = Agent(
|
||||
id="agent_123",
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint=""
|
||||
)
|
||||
assert agent.endpoint == ""
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_registration_empty_name():
|
||||
"""Test AgentRegistration with empty name"""
|
||||
from app import AgentRegistration
|
||||
registration = AgentRegistration(
|
||||
name="",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert registration.name == ""
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_registration_empty_chain_id():
|
||||
"""Test AgentRegistration with empty chain_id"""
|
||||
from app import AgentRegistration
|
||||
registration = AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert registration.chain_id == ""
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_agents_no_match_filter():
|
||||
"""Test listing agents with filter that matches nothing"""
|
||||
import app
|
||||
from fastapi.testclient import TestClient
|
||||
client = TestClient(app.app)
|
||||
|
||||
# Register an agent
|
||||
registration = app.AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
client.post("/api/agents/register", json=registration.model_dump())
|
||||
|
||||
# Filter for non-existent type
|
||||
response = client.get("/api/agents?agent_type=compliance")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) == 0
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_agents_multiple_filters():
|
||||
"""Test listing agents with multiple filters"""
|
||||
import app
|
||||
from fastapi.testclient import TestClient
|
||||
client = TestClient(app.app)
|
||||
|
||||
# Register agents
|
||||
registration1 = app.AgentRegistration(
|
||||
name="Trading Agent",
|
||||
type="trading",
|
||||
capabilities=["trading", "analysis"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
registration2 = app.AgentRegistration(
|
||||
name="Compliance Agent",
|
||||
type="compliance",
|
||||
capabilities=["compliance"],
|
||||
chain_id="ait-testnet",
|
||||
endpoint="http://localhost:8001"
|
||||
)
|
||||
client.post("/api/agents/register", json=registration1.model_dump())
|
||||
client.post("/api/agents/register", json=registration2.model_dump())
|
||||
|
||||
# Filter by both type and chain
|
||||
response = client.get("/api/agents?agent_type=trading&chain_id=ait-devnet")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) == 1
|
||||
assert data[0]["type"] == "trading"
|
||||
assert data[0]["chain_id"] == "ait-devnet"
|
||||
@@ -0,0 +1,193 @@
|
||||
"""Integration tests for agent registry service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from fastapi.testclient import TestClient
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_db():
|
||||
"""Reset database before each test"""
|
||||
import app
|
||||
# Delete the database file if it exists
|
||||
db_path = Path("agent_registry.db")
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
app.init_db()
|
||||
yield
|
||||
|
||||
# Clean up after test
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_health_check():
|
||||
"""Test health check endpoint"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
response = client.get("/api/health")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "ok"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_register_agent():
|
||||
"""Test registering a new agent"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
registration = app.AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading", "analysis"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000",
|
||||
metadata={"region": "us-east"}
|
||||
)
|
||||
response = client.post("/api/agents/register", json=registration.model_dump())
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["name"] == "Test Agent"
|
||||
assert data["type"] == "trading"
|
||||
assert "id" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_register_agent_no_metadata():
|
||||
"""Test registering an agent without metadata"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
registration = app.AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
response = client.post("/api/agents/register", json=registration.model_dump())
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["name"] == "Test Agent"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_agents():
|
||||
"""Test listing all agents"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
|
||||
# Register an agent first
|
||||
registration = app.AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
client.post("/api/agents/register", json=registration.model_dump())
|
||||
|
||||
response = client.get("/api/agents")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) >= 1
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_agents_with_type_filter():
|
||||
"""Test listing agents filtered by type"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
|
||||
# Register agents
|
||||
registration1 = app.AgentRegistration(
|
||||
name="Trading Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
registration2 = app.AgentRegistration(
|
||||
name="Compliance Agent",
|
||||
type="compliance",
|
||||
capabilities=["compliance"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8001"
|
||||
)
|
||||
client.post("/api/agents/register", json=registration1.model_dump())
|
||||
client.post("/api/agents/register", json=registration2.model_dump())
|
||||
|
||||
response = client.get("/api/agents?agent_type=trading")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert all(agent["type"] == "trading" for agent in data)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_agents_with_chain_filter():
|
||||
"""Test listing agents filtered by chain"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
|
||||
# Register agents
|
||||
registration1 = app.AgentRegistration(
|
||||
name="Devnet Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
registration2 = app.AgentRegistration(
|
||||
name="Testnet Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-testnet",
|
||||
endpoint="http://localhost:8001"
|
||||
)
|
||||
client.post("/api/agents/register", json=registration1.model_dump())
|
||||
client.post("/api/agents/register", json=registration2.model_dump())
|
||||
|
||||
response = client.get("/api/agents?chain_id=ait-devnet")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert all(agent["chain_id"] == "ait-devnet" for agent in data)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_agents_with_capability_filter():
|
||||
"""Test listing agents filtered by capability"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
|
||||
# Register agents
|
||||
registration = app.AgentRegistration(
|
||||
name="Trading Agent",
|
||||
type="trading",
|
||||
capabilities=["trading", "analysis"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
client.post("/api/agents/register", json=registration.model_dump())
|
||||
|
||||
response = client.get("/api/agents?capability=trading")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) >= 1
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_agents_empty():
|
||||
"""Test listing agents when none exist"""
|
||||
import app
|
||||
client = TestClient(app.app)
|
||||
|
||||
response = client.get("/api/agents")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) == 0
|
||||
@@ -0,0 +1,105 @@
|
||||
"""Unit tests for agent registry service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
from app import app, Agent, AgentRegistration
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_app_initialization():
|
||||
"""Test that the FastAPI app initializes correctly"""
|
||||
assert app is not None
|
||||
assert app.title == "AITBC Agent Registry API"
|
||||
assert app.version == "1.0.0"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_model():
|
||||
"""Test Agent model"""
|
||||
agent = Agent(
|
||||
id="agent_123",
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading", "analysis"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000",
|
||||
metadata={"region": "us-east"}
|
||||
)
|
||||
assert agent.id == "agent_123"
|
||||
assert agent.name == "Test Agent"
|
||||
assert agent.type == "trading"
|
||||
assert agent.capabilities == ["trading", "analysis"]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_model_empty_capabilities():
|
||||
"""Test Agent model with empty capabilities"""
|
||||
agent = Agent(
|
||||
id="agent_123",
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=[],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert agent.capabilities == []
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_model_no_metadata():
|
||||
"""Test Agent model with default metadata"""
|
||||
agent = Agent(
|
||||
id="agent_123",
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert agent.metadata == {}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_registration_model():
|
||||
"""Test AgentRegistration model"""
|
||||
registration = AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading", "analysis"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000",
|
||||
metadata={"region": "us-east"}
|
||||
)
|
||||
assert registration.name == "Test Agent"
|
||||
assert registration.type == "trading"
|
||||
assert registration.capabilities == ["trading", "analysis"]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_registration_model_empty_capabilities():
|
||||
"""Test AgentRegistration with empty capabilities"""
|
||||
registration = AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=[],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert registration.capabilities == []
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_agent_registration_model_no_metadata():
|
||||
"""Test AgentRegistration with default metadata"""
|
||||
registration = AgentRegistration(
|
||||
name="Test Agent",
|
||||
type="trading",
|
||||
capabilities=["trading"],
|
||||
chain_id="ait-devnet",
|
||||
endpoint="http://localhost:8000"
|
||||
)
|
||||
assert registration.metadata == {}
|
||||
Reference in New Issue
Block a user