Files
aitbc/tests/fixtures/common.py
aitbc 3897bcbf24
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
refactor: move version to separate module and improve logging
- 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
2026-05-11 20:12:01 +02:00

139 lines
3.6 KiB
Python

"""
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()