Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 22s
Blockchain Synchronization Verification / sync-verification (push) Successful in 3s
CLI Tests / test-cli (push) Failing after 13s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 3s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m34s
Documentation Validation / validate-docs (push) Failing after 10s
Documentation Validation / validate-policies-strict (push) Successful in 3s
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Integration Tests / test-service-integration (push) Successful in 2m42s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 3s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 5s
P2P Network Verification / p2p-verification (push) Successful in 3s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 33s
Package Tests / Python package - aitbc-core (push) Successful in 17s
Package Tests / Python package - aitbc-crypto (push) Successful in 11s
Security Scanning / security-scan (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Successful in 13s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 9s
Package Tests / JavaScript package - aitbc-token (push) Successful in 17s
Staking Tests / test-staking-service (push) Failing after 6s
Staking Tests / test-staking-integration (push) Has been skipped
Staking Tests / test-staking-contract (push) Has been skipped
Staking Tests / run-staking-test-runner (push) Has been skipped
169 lines
4.9 KiB
Python
169 lines
4.9 KiB
Python
"""Edge case and error handling tests for plugin analytics service"""
|
|
|
|
import pytest
|
|
import sys
|
|
import sys
|
|
from pathlib import Path
|
|
from fastapi.testclient import TestClient
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
from main import app, PluginUsage, PluginPerformance, PluginRating, PluginEvent, plugin_usage_data, plugin_performance_data, plugin_ratings, plugin_events
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def reset_state():
|
|
"""Reset global state before each test"""
|
|
plugin_usage_data.clear()
|
|
plugin_performance_data.clear()
|
|
plugin_ratings.clear()
|
|
plugin_events.clear()
|
|
yield
|
|
plugin_usage_data.clear()
|
|
plugin_performance_data.clear()
|
|
plugin_ratings.clear()
|
|
plugin_events.clear()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_usage_empty_plugin_id():
|
|
"""Test PluginUsage with empty plugin_id"""
|
|
usage = PluginUsage(
|
|
plugin_id="",
|
|
user_id="user_123",
|
|
action="install",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert usage.plugin_id == ""
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_performance_negative_values():
|
|
"""Test PluginPerformance with negative values"""
|
|
perf = PluginPerformance(
|
|
plugin_id="plugin_123",
|
|
version="1.0.0",
|
|
cpu_usage=-10.0,
|
|
memory_usage=-5.0,
|
|
response_time=-0.1,
|
|
error_rate=-0.01,
|
|
uptime=-50.0,
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert perf.cpu_usage == -10.0
|
|
assert perf.memory_usage == -5.0
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_rating_out_of_range():
|
|
"""Test PluginRating with out of range rating"""
|
|
rating = PluginRating(
|
|
plugin_id="plugin_123",
|
|
user_id="user_123",
|
|
rating=10,
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert rating.rating == 10
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_plugin_rating_zero():
|
|
"""Test PluginRating with zero rating"""
|
|
rating = PluginRating(
|
|
plugin_id="plugin_123",
|
|
user_id="user_123",
|
|
rating=0,
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert rating.rating == 0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_get_plugin_usage_no_data():
|
|
"""Test getting plugin usage when no data exists"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/analytics/usage/nonexistent")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["total_records"] == 0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_get_plugin_performance_no_data():
|
|
"""Test getting plugin performance when no data exists"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/analytics/performance/nonexistent")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["total_records"] == 0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_get_plugin_ratings_no_data():
|
|
"""Test getting plugin ratings when no data exists"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/analytics/ratings/nonexistent")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["total_ratings"] == 0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_dashboard_with_no_data():
|
|
"""Test dashboard with no data"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/analytics/dashboard")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["dashboard"]["overview"]["total_plugins"] == 0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_record_multiple_usage_events():
|
|
"""Test recording multiple usage events for same plugin"""
|
|
client = TestClient(app)
|
|
|
|
for i in range(5):
|
|
usage = PluginUsage(
|
|
plugin_id="plugin_123",
|
|
user_id=f"user_{i}",
|
|
action="use",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
client.post("/api/v1/analytics/usage", json=usage.model_dump(mode='json'))
|
|
|
|
response = client.get("/api/v1/analytics/usage/plugin_123")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["total_records"] == 5
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_usage_trends_days_parameter():
|
|
"""Test usage trends with custom days parameter"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/analytics/trends?days=7")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "trends" in data
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_get_plugin_usage_days_parameter():
|
|
"""Test getting plugin usage with custom days parameter"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/analytics/usage/plugin_123?days=7")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["period_days"] == 7
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_get_plugin_performance_hours_parameter():
|
|
"""Test getting plugin performance with custom hours parameter"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/analytics/performance/plugin_123?hours=12")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["period_hours"] == 12
|