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
124 lines
3.2 KiB
Python
124 lines
3.2 KiB
Python
"""Unit tests for plugin analytics service"""
|
|
|
|
import pytest
|
|
import sys
|
|
import sys
|
|
from pathlib import Path
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
from main import app, PluginUsage, PluginPerformance, PluginRating, PluginEvent
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_app_initialization():
|
|
"""Test that the FastAPI app initializes correctly"""
|
|
assert app is not None
|
|
assert app.title == "AITBC Plugin Analytics Service"
|
|
assert app.version == "1.0.0"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_usage_model():
|
|
"""Test PluginUsage model"""
|
|
usage = PluginUsage(
|
|
plugin_id="plugin_123",
|
|
user_id="user_123",
|
|
action="install",
|
|
timestamp=datetime.now(timezone.utc),
|
|
metadata={"source": "marketplace"}
|
|
)
|
|
assert usage.plugin_id == "plugin_123"
|
|
assert usage.user_id == "user_123"
|
|
assert usage.action == "install"
|
|
assert usage.metadata == {"source": "marketplace"}
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_usage_defaults():
|
|
"""Test PluginUsage with default metadata"""
|
|
usage = PluginUsage(
|
|
plugin_id="plugin_123",
|
|
user_id="user_123",
|
|
action="use",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert usage.metadata == {}
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_performance_model():
|
|
"""Test PluginPerformance model"""
|
|
perf = PluginPerformance(
|
|
plugin_id="plugin_123",
|
|
version="1.0.0",
|
|
cpu_usage=50.5,
|
|
memory_usage=30.2,
|
|
response_time=0.123,
|
|
error_rate=0.001,
|
|
uptime=99.9,
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert perf.plugin_id == "plugin_123"
|
|
assert perf.version == "1.0.0"
|
|
assert perf.cpu_usage == 50.5
|
|
assert perf.memory_usage == 30.2
|
|
assert perf.response_time == 0.123
|
|
assert perf.error_rate == 0.001
|
|
assert perf.uptime == 99.9
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_rating_model():
|
|
"""Test PluginRating model"""
|
|
rating = PluginRating(
|
|
plugin_id="plugin_123",
|
|
user_id="user_123",
|
|
rating=5,
|
|
review="Great plugin!",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert rating.plugin_id == "plugin_123"
|
|
assert rating.rating == 5
|
|
assert rating.review == "Great plugin!"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_rating_defaults():
|
|
"""Test PluginRating with default review"""
|
|
rating = PluginRating(
|
|
plugin_id="plugin_123",
|
|
user_id="user_123",
|
|
rating=4,
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert rating.review is None
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_event_model():
|
|
"""Test PluginEvent model"""
|
|
event = PluginEvent(
|
|
event_type="error",
|
|
plugin_id="plugin_123",
|
|
user_id="user_123",
|
|
data={"error": "timeout"},
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert event.event_type == "error"
|
|
assert event.plugin_id == "plugin_123"
|
|
assert event.user_id == "user_123"
|
|
assert event.data == {"error": "timeout"}
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_event_defaults():
|
|
"""Test PluginEvent with default values"""
|
|
event = PluginEvent(
|
|
event_type="info",
|
|
plugin_id="plugin_123",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert event.user_id is None
|
|
assert event.data == {}
|