Some checks failed
CLI Tests / test-cli (push) Failing after 4s
Deploy to Testnet / deploy-testnet (push) Successful in 1m40s
Documentation Validation / validate-docs (push) Failing after 12s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 2m42s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 34s
Package Tests / Python package - aitbc-core (push) Successful in 27s
Package Tests / Python package - aitbc-crypto (push) Successful in 13s
Package Tests / Python package - aitbc-sdk (push) Successful in 16s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 8s
Package Tests / JavaScript package - aitbc-token (push) Successful in 18s
Python Tests / test-python (push) Failing after 50s
Security Scanning / security-scan (push) Failing after 43s
Multi-Node Stress Testing / stress-test (push) Successful in 12s
Cross-Node Transaction Testing / transaction-test (push) Successful in 9s
- Created aitbc/_version.py with centralized version definition - Updated aitbc/__init__.py to import __version__ from _version module - Updated constants.py to use __version__ for PACKAGE_VERSION - Replaced print() calls with logger in decorators.py, events.py, queue_manager.py, and state.py - Added logger initialization using get_logger(__name__) in config.py, decorators.py, events.py, queue_manager.py, and state.py - Added cli/commands
100 lines
3.6 KiB
Python
100 lines
3.6 KiB
Python
"""
|
|
Coordinator API test fixtures
|
|
Provides fixtures for testing the coordinator API
|
|
"""
|
|
|
|
import sys
|
|
import pytest
|
|
from pathlib import Path
|
|
from unittest.mock import Mock
|
|
|
|
project_root = Path(__file__).parent.parent.parent
|
|
|
|
|
|
@pytest.fixture
|
|
def coordinator_client():
|
|
"""Create a test client for coordinator API"""
|
|
from fastapi.testclient import TestClient
|
|
from aitbc.testing import MockResponse
|
|
|
|
try:
|
|
# Import the coordinator app specifically
|
|
coordinator_path = str(project_root / "apps" / "coordinator-api" / "src")
|
|
if coordinator_path not in sys.path[:1]:
|
|
sys.path.insert(0, coordinator_path)
|
|
|
|
from app.main import app as coordinator_app
|
|
print("✅ Using real coordinator API client")
|
|
return TestClient(coordinator_app)
|
|
except ImportError as e:
|
|
# Create a mock client if imports fail
|
|
print(f"Warning: Using mock coordinator_client due to import error: {e}")
|
|
|
|
mock_response = MockResponse(
|
|
status_code=201,
|
|
json_data={
|
|
"job_id": "test-job-123",
|
|
"state": "QUEUED",
|
|
"assigned_miner_id": None,
|
|
"requested_at": "2026-01-26T18:00:00.000000",
|
|
"expires_at": "2026-01-26T18:15:00.000000",
|
|
"error": None,
|
|
"payment_id": "test-payment-456",
|
|
"payment_status": "escrowed"
|
|
}
|
|
)
|
|
|
|
mock_client = Mock()
|
|
mock_client.post.return_value = mock_response
|
|
|
|
mock_get_response = MockResponse(
|
|
status_code=200,
|
|
json_data={
|
|
"job_id": "test-job-123",
|
|
"state": "QUEUED",
|
|
"assigned_miner_id": None,
|
|
"requested_at": "2026-01-26T18:00:00.000000",
|
|
"expires_at": "2026-01-26T18:15:00.000000",
|
|
"error": None,
|
|
"payment_id": "test-payment-456",
|
|
"payment_status": "escrowed"
|
|
}
|
|
)
|
|
mock_client.get.return_value = mock_get_response
|
|
|
|
mock_receipts_response = MockResponse(
|
|
status_code=200,
|
|
json_data={
|
|
"items": [],
|
|
"total": 0
|
|
}
|
|
)
|
|
|
|
def mock_get_side_effect(url, headers=None):
|
|
if "receipts" in url:
|
|
return mock_receipts_response
|
|
elif "/docs" in url or "/openapi.json" in url:
|
|
return MockResponse(status_code=200, text='{"openapi": "3.0.0", "info": {"title": "AITBC Coordinator API"}}')
|
|
elif "/v1/health" in url:
|
|
return MockResponse(status_code=200, json_data={"status": "ok", "env": "dev"})
|
|
elif "/payment" in url:
|
|
return MockResponse(
|
|
status_code=200,
|
|
json_data={
|
|
"job_id": "test-job-123",
|
|
"payment_id": "test-payment-456",
|
|
"amount": 100,
|
|
"currency": "AITBC",
|
|
"status": "escrowed",
|
|
"payment_method": "aitbc_token",
|
|
"escrow_address": "test-escrow-id",
|
|
"created_at": "2026-01-26T18:00:00.000000",
|
|
"updated_at": "2026-01-26T18:00:00.000000"
|
|
}
|
|
)
|
|
return mock_get_response
|
|
|
|
mock_client.get.side_effect = mock_get_side_effect
|
|
mock_client.patch.return_value = MockResponse(status_code=200, json_data={"status": "updated"})
|
|
return mock_client
|