refactor: move version to separate module and improve logging
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
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
This commit is contained in:
100
tests/fixtures/blockchain.py
vendored
Normal file
100
tests/fixtures/blockchain.py
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
Blockchain test fixtures
|
||||
Provides fixtures for testing blockchain node and related components
|
||||
"""
|
||||
|
||||
import sys
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock
|
||||
|
||||
project_root = Path(__file__).parent.parent.parent
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def blockchain_client():
|
||||
"""Create a test client for blockchain node"""
|
||||
from fastapi.testclient import TestClient
|
||||
try:
|
||||
blockchain_path = str(project_root / "apps" / "blockchain-node" / "src")
|
||||
if blockchain_path not in sys.path[:1]:
|
||||
sys.path.insert(0, blockchain_path)
|
||||
|
||||
from aitbc_chain.node import BlockchainNode
|
||||
node = BlockchainNode()
|
||||
return TestClient(node.app)
|
||||
except ImportError:
|
||||
# Create a mock client if imports fail
|
||||
mock_client = Mock()
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"block_number": 100,
|
||||
"hash": "0xblock123",
|
||||
"transaction_hash": "0xtx456"
|
||||
}
|
||||
|
||||
mock_client.post.return_value = mock_response
|
||||
mock_client.get.return_value = mock_response
|
||||
return mock_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def wallet_client():
|
||||
"""Create a test client for wallet daemon"""
|
||||
from fastapi.testclient import TestClient
|
||||
try:
|
||||
wallet_path = str(project_root / "apps" / "wallet-daemon" / "src")
|
||||
if wallet_path not in sys.path[:1]:
|
||||
sys.path.insert(0, wallet_path)
|
||||
|
||||
from app.main import app
|
||||
return TestClient(app)
|
||||
except ImportError:
|
||||
# Create a mock client if imports fail
|
||||
mock_client = Mock()
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"id": "wallet-123",
|
||||
"address": "0x1234567890abcdef",
|
||||
"balance": "1000.0"
|
||||
}
|
||||
|
||||
mock_client.post.return_value = mock_response
|
||||
mock_client.get.return_value = mock_response
|
||||
mock_client.patch.return_value = mock_response
|
||||
return mock_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def marketplace_client():
|
||||
"""Create a test client for marketplace"""
|
||||
from fastapi.testclient import TestClient
|
||||
try:
|
||||
marketplace_path = str(project_root / "apps" / "marketplace" / "src")
|
||||
if marketplace_path not in sys.path[:1]:
|
||||
sys.path.insert(0, marketplace_path)
|
||||
|
||||
from app.main import app
|
||||
return TestClient(app)
|
||||
except ImportError:
|
||||
# Create a mock client if imports fail
|
||||
mock_client = Mock()
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 201
|
||||
mock_response.json.return_value = {
|
||||
"id": "service-123",
|
||||
"name": "Test Service",
|
||||
"status": "active"
|
||||
}
|
||||
|
||||
mock_client.post.return_value = mock_response
|
||||
mock_client.get.return_value = Mock(
|
||||
status_code=200,
|
||||
json=lambda: {"items": [], "total": 0}
|
||||
)
|
||||
return mock_client
|
||||
138
tests/fixtures/common.py
vendored
Normal file
138
tests/fixtures/common.py
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
"""
|
||||
Common test fixtures for AITBC tests
|
||||
Provides shared fixtures used across multiple test domains
|
||||
"""
|
||||
|
||||
import sys
|
||||
import pytest
|
||||
import os
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock
|
||||
|
||||
# Configure Python path for test discovery
|
||||
project_root = Path(__file__).parent.parent.parent
|
||||
|
||||
# Minimal sys.path setup - only essential paths
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
# Import aitbc utilities
|
||||
from aitbc.constants import DATA_DIR, LOG_DIR
|
||||
from aitbc.testing import MockFactory, TestDataGenerator, MockResponse, MockDatabase, MockCache
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_test_environment():
|
||||
"""Automatically set up test environment for all tests"""
|
||||
os.environ["TEST_MODE"] = "true"
|
||||
os.environ["AUDIT_LOG_DIR"] = str(LOG_DIR / "audit")
|
||||
os.environ["TEST_DATABASE_URL"] = "sqlite:///:memory:"
|
||||
os.environ["DATA_DIR"] = str(DATA_DIR)
|
||||
yield
|
||||
# Cleanup if needed
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_optional_dependencies():
|
||||
"""Mock optional dependencies that may not be installed"""
|
||||
# Use pytest-mock to mock modules at test time
|
||||
# Tests that need these can use this fixture
|
||||
return None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_aitbc_crypto():
|
||||
"""Mock aitbc_crypto package when not available"""
|
||||
try:
|
||||
import aitbc_crypto
|
||||
return aitbc_crypto
|
||||
except ImportError:
|
||||
# Create mock
|
||||
mock_crypto = Mock()
|
||||
|
||||
def mock_encrypt_data(data, key):
|
||||
return f"encrypted_{data}"
|
||||
|
||||
def mock_decrypt_data(data, key):
|
||||
return data.replace("encrypted_", "")
|
||||
|
||||
def mock_generate_viewing_key():
|
||||
return "test_viewing_key"
|
||||
|
||||
mock_crypto.encrypt_data = mock_encrypt_data
|
||||
mock_crypto.decrypt_data = mock_decrypt_data
|
||||
mock_crypto.generate_viewing_key = mock_generate_viewing_key
|
||||
|
||||
# Add signing submodule
|
||||
signing_mod = Mock()
|
||||
|
||||
class _ReceiptSigner:
|
||||
def verify_receipt(self, payload, signature):
|
||||
return True
|
||||
|
||||
signing_mod.ReceiptSigner = _ReceiptSigner
|
||||
mock_crypto.signing = signing_mod
|
||||
|
||||
return mock_crypto
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_tenant():
|
||||
"""Create a sample tenant for testing using TestDataGenerator"""
|
||||
return TestDataGenerator.generate_user_data(
|
||||
id="tenant-123",
|
||||
first_name="Test",
|
||||
last_name="Tenant",
|
||||
is_active=True
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_job_data():
|
||||
"""Sample job creation data using TestDataGenerator"""
|
||||
return {
|
||||
"job_type": "ai_inference",
|
||||
"parameters": {
|
||||
"model": "gpt-4",
|
||||
"prompt": "Test prompt",
|
||||
"max_tokens": 100,
|
||||
"temperature": 0.7
|
||||
},
|
||||
"priority": "normal",
|
||||
"timeout": 300
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_db():
|
||||
"""Create a mock database for testing"""
|
||||
return MockDatabase()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_cache():
|
||||
"""Create a mock cache for testing"""
|
||||
return MockCache()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_user_data():
|
||||
"""Generate test user data using TestDataGenerator"""
|
||||
return TestDataGenerator.generate_user_data()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_transaction_data():
|
||||
"""Generate test transaction data using TestDataGenerator"""
|
||||
return TestDataGenerator.generate_transaction_data()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_wallet_data():
|
||||
"""Generate test wallet data using TestDataGenerator"""
|
||||
return TestDataGenerator.generate_wallet_data()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_ethereum_address():
|
||||
"""Generate a test Ethereum address using MockFactory"""
|
||||
return MockFactory.generate_ethereum_address()
|
||||
99
tests/fixtures/coordinator.py
vendored
Normal file
99
tests/fixtures/coordinator.py
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
"""
|
||||
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
|
||||
Reference in New Issue
Block a user