Add sys import to test files and remove obsolete integration tests
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
- Add sys import to 29 test files across agent-coordinator, blockchain-event-bridge, blockchain-node, and coordinator-api - Remove apps/blockchain-event-bridge/tests/test_integration.py (obsolete bridge integration tests) - Remove apps/coordinator-api/tests/test_integration.py (obsolete API integration tests) - Implement GPU registration in marketplace_gpu.py with GPURegistry model persistence
This commit is contained in:
1
apps/plugin-registry/tests/__init__.py
Normal file
1
apps/plugin-registry/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Plugin registry service tests"""
|
||||
317
apps/plugin-registry/tests/test_edge_cases_plugin_registry.py
Normal file
317
apps/plugin-registry/tests/test_edge_cases_plugin_registry.py
Normal file
@@ -0,0 +1,317 @@
|
||||
"""Edge case and error handling tests for plugin registry service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from fastapi.testclient import TestClient
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from main import app, PluginRegistration, PluginVersion, SecurityScan, plugins, plugin_versions, security_scans, analytics, downloads
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_state():
|
||||
"""Reset global state before each test"""
|
||||
plugins.clear()
|
||||
plugin_versions.clear()
|
||||
security_scans.clear()
|
||||
analytics.clear()
|
||||
downloads.clear()
|
||||
yield
|
||||
plugins.clear()
|
||||
plugin_versions.clear()
|
||||
security_scans.clear()
|
||||
analytics.clear()
|
||||
downloads.clear()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_plugin_registration_empty_name():
|
||||
"""Test PluginRegistration with empty name"""
|
||||
plugin = PluginRegistration(
|
||||
name="",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
assert plugin.name == ""
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_plugin_registration_empty_tags():
|
||||
"""Test PluginRegistration with empty tags"""
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
assert plugin.tags == []
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_plugin_version_empty_changelog():
|
||||
"""Test PluginVersion with empty changelog"""
|
||||
version = PluginVersion(
|
||||
version="1.0.0",
|
||||
changelog="",
|
||||
download_url="https://github.com/test/plugin/archive/v1.0.0.tar.gz",
|
||||
checksum="abc123",
|
||||
aitbc_compatibility=["1.0.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
assert version.changelog == ""
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_security_scan_empty_vulnerabilities():
|
||||
"""Test SecurityScan with empty vulnerabilities"""
|
||||
scan = SecurityScan(
|
||||
scan_id="scan_123",
|
||||
plugin_id="test_plugin",
|
||||
version="1.0.0",
|
||||
scan_date=datetime.utcnow(),
|
||||
vulnerabilities=[],
|
||||
risk_score="low",
|
||||
passed=True
|
||||
)
|
||||
assert scan.vulnerabilities == []
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_add_version_nonexistent_plugin():
|
||||
"""Test adding version to nonexistent plugin"""
|
||||
client = TestClient(app)
|
||||
version = PluginVersion(
|
||||
version="1.0.0",
|
||||
changelog="Initial release",
|
||||
download_url="https://github.com/test/plugin/archive/v1.0.0.tar.gz",
|
||||
checksum="abc123",
|
||||
aitbc_compatibility=["1.0.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
response = client.post("/api/v1/plugins/nonexistent/versions", json=version.model_dump(mode='json'))
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_download_nonexistent_plugin():
|
||||
"""Test downloading nonexistent plugin"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/plugins/nonexistent/download/1.0.0")
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_download_nonexistent_version():
|
||||
"""Test downloading nonexistent version"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Try to download nonexistent version
|
||||
response = client.get("/api/v1/plugins/test_plugin/download/2.0.0")
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_security_scan_nonexistent_plugin():
|
||||
"""Test creating security scan for nonexistent plugin"""
|
||||
client = TestClient(app)
|
||||
scan = SecurityScan(
|
||||
scan_id="scan_123",
|
||||
plugin_id="nonexistent",
|
||||
version="1.0.0",
|
||||
scan_date=datetime.utcnow(),
|
||||
vulnerabilities=[],
|
||||
risk_score="low",
|
||||
passed=True
|
||||
)
|
||||
response = client.post("/api/v1/plugins/nonexistent/security-scan", json=scan.model_dump(mode='json'))
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_security_scan_nonexistent_version():
|
||||
"""Test creating security scan for nonexistent version"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Create security scan for nonexistent version
|
||||
scan = SecurityScan(
|
||||
scan_id="scan_123",
|
||||
plugin_id="test_plugin",
|
||||
version="2.0.0",
|
||||
scan_date=datetime.utcnow(),
|
||||
vulnerabilities=[],
|
||||
risk_score="low",
|
||||
passed=True
|
||||
)
|
||||
response = client.post("/api/v1/plugins/test_plugin/security-scan", json=scan.model_dump(mode='json'))
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_plugins_with_filters():
|
||||
"""Test listing plugins with filters"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register multiple plugins
|
||||
plugin1 = PluginRegistration(
|
||||
name="Test Plugin 1",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=["test"],
|
||||
repository_url="https://github.com/test/plugin1",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin1.model_dump())
|
||||
|
||||
plugin2 = PluginRegistration(
|
||||
name="Production Plugin",
|
||||
version="1.0.0",
|
||||
description="A production plugin",
|
||||
author="Test Author",
|
||||
category="production",
|
||||
tags=["prod"],
|
||||
repository_url="https://github.com/test/plugin2",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="web"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin2.model_dump())
|
||||
|
||||
# Filter by category
|
||||
response = client.get("/api/v1/plugins?category=testing")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total_plugins"] == 1
|
||||
assert data["plugins"][0]["category"] == "testing"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_plugins_with_search():
|
||||
"""Test listing plugins with search"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin for testing",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=["test"],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Search for plugin
|
||||
response = client.get("/api/v1/plugins?search=test")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total_plugins"] == 1
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_security_scan_failed():
|
||||
"""Test security scan that failed"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Add version first
|
||||
version = PluginVersion(
|
||||
version="1.0.0",
|
||||
changelog="Initial release",
|
||||
download_url="https://github.com/test/plugin/archive/v1.0.0.tar.gz",
|
||||
checksum="abc123",
|
||||
aitbc_compatibility=["1.0.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
client.post("/api/v1/plugins/test_plugin/versions", json=version.model_dump(mode='json'))
|
||||
|
||||
# Create failed security scan
|
||||
scan = SecurityScan(
|
||||
scan_id="scan_123",
|
||||
plugin_id="test_plugin",
|
||||
version="1.0.0",
|
||||
scan_date=datetime.utcnow(),
|
||||
vulnerabilities=[{"severity": "high", "description": "Critical issue"}],
|
||||
risk_score="high",
|
||||
passed=False
|
||||
)
|
||||
response = client.post("/api/v1/plugins/test_plugin/security-scan", json=scan.model_dump(mode='json'))
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["passed"] is False
|
||||
assert data["risk_score"] == "high"
|
||||
422
apps/plugin-registry/tests/test_integration_plugin_registry.py
Normal file
422
apps/plugin-registry/tests/test_integration_plugin_registry.py
Normal file
@@ -0,0 +1,422 @@
|
||||
"""Integration tests for plugin registry service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from fastapi.testclient import TestClient
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from main import app, PluginRegistration, PluginVersion, SecurityScan, plugins, plugin_versions, security_scans, analytics, downloads
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_state():
|
||||
"""Reset global state before each test"""
|
||||
plugins.clear()
|
||||
plugin_versions.clear()
|
||||
security_scans.clear()
|
||||
analytics.clear()
|
||||
downloads.clear()
|
||||
yield
|
||||
plugins.clear()
|
||||
plugin_versions.clear()
|
||||
security_scans.clear()
|
||||
analytics.clear()
|
||||
downloads.clear()
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_root_endpoint():
|
||||
"""Test root endpoint"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["service"] == "AITBC Plugin Registry"
|
||||
assert data["status"] == "running"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_health_check_endpoint():
|
||||
"""Test health check endpoint"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/health")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "healthy"
|
||||
assert "total_plugins" in data
|
||||
assert "total_versions" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_register_plugin():
|
||||
"""Test plugin registration"""
|
||||
client = TestClient(app)
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=["test", "demo"],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
response = client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["plugin_id"] == "test_plugin"
|
||||
assert data["status"] == "registered"
|
||||
assert data["name"] == "Test Plugin"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_register_duplicate_plugin():
|
||||
"""Test registering duplicate plugin"""
|
||||
client = TestClient(app)
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
|
||||
# First registration
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Second registration should fail
|
||||
response = client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_add_plugin_version():
|
||||
"""Test adding plugin version"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Add version
|
||||
version = PluginVersion(
|
||||
version="1.1.0",
|
||||
changelog="Bug fixes",
|
||||
download_url="https://github.com/test/plugin/archive/v1.1.0.tar.gz",
|
||||
checksum="def456",
|
||||
aitbc_compatibility=["1.0.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
response = client.post("/api/v1/plugins/test_plugin/versions", json=version.model_dump(mode='json'))
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["version"] == "1.1.0"
|
||||
assert data["status"] == "added"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_add_duplicate_version():
|
||||
"""Test adding duplicate version"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Add version
|
||||
version = PluginVersion(
|
||||
version="1.1.0",
|
||||
changelog="Bug fixes",
|
||||
download_url="https://github.com/test/plugin/archive/v1.1.0.tar.gz",
|
||||
checksum="def456",
|
||||
aitbc_compatibility=["1.0.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
client.post("/api/v1/plugins/test_plugin/versions", json=version.model_dump(mode='json'))
|
||||
|
||||
# Add same version again should fail
|
||||
response = client.post("/api/v1/plugins/test_plugin/versions", json=version.model_dump(mode='json'))
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_plugins():
|
||||
"""Test listing plugins"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/plugins")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "plugins" in data
|
||||
assert "total_plugins" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_plugin():
|
||||
"""Test getting specific plugin"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Get plugin
|
||||
response = client.get("/api/v1/plugins/test_plugin")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["plugin_id"] == "test_plugin"
|
||||
assert data["name"] == "Test Plugin"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_plugin_not_found():
|
||||
"""Test getting nonexistent plugin"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/plugins/nonexistent")
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_plugin_versions():
|
||||
"""Test getting plugin versions"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Get versions
|
||||
response = client.get("/api/v1/plugins/test_plugin/versions")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["plugin_id"] == "test_plugin"
|
||||
assert "versions" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_download_plugin():
|
||||
"""Test downloading plugin"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Add version first
|
||||
version = PluginVersion(
|
||||
version="1.0.0",
|
||||
changelog="Initial release",
|
||||
download_url="https://github.com/test/plugin/archive/v1.0.0.tar.gz",
|
||||
checksum="abc123",
|
||||
aitbc_compatibility=["1.0.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
client.post("/api/v1/plugins/test_plugin/versions", json=version.model_dump(mode='json'))
|
||||
|
||||
# Download plugin
|
||||
response = client.get("/api/v1/plugins/test_plugin/download/1.0.0")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["plugin_id"] == "test_plugin"
|
||||
assert data["version"] == "1.0.0"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_create_security_scan():
|
||||
"""Test creating security scan"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Add version first
|
||||
version = PluginVersion(
|
||||
version="1.0.0",
|
||||
changelog="Initial release",
|
||||
download_url="https://github.com/test/plugin/archive/v1.0.0.tar.gz",
|
||||
checksum="abc123",
|
||||
aitbc_compatibility=["1.0.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
client.post("/api/v1/plugins/test_plugin/versions", json=version.model_dump(mode='json'))
|
||||
|
||||
# Create security scan
|
||||
scan = SecurityScan(
|
||||
scan_id="scan_123",
|
||||
plugin_id="test_plugin",
|
||||
version="1.0.0",
|
||||
scan_date=datetime.utcnow(),
|
||||
vulnerabilities=[],
|
||||
risk_score="low",
|
||||
passed=True
|
||||
)
|
||||
response = client.post("/api/v1/plugins/test_plugin/security-scan", json=scan.model_dump(mode='json'))
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["scan_id"] == "scan_123"
|
||||
assert data["passed"] is True
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_plugin_security():
|
||||
"""Test getting plugin security info"""
|
||||
client = TestClient(app)
|
||||
|
||||
# Register plugin first
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
dependencies=[],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
client.post("/api/v1/plugins/register", json=plugin.model_dump())
|
||||
|
||||
# Get security info
|
||||
response = client.get("/api/v1/plugins/test_plugin/security")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["plugin_id"] == "test_plugin"
|
||||
assert "security_scans" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_categories():
|
||||
"""Test getting categories"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/categories")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "categories" in data
|
||||
assert "total_categories" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_tags():
|
||||
"""Test getting tags"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/tags")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "tags" in data
|
||||
assert "total_tags" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_popular_plugins():
|
||||
"""Test getting popular plugins"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/analytics/popular")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "popular_plugins" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_recent_plugins():
|
||||
"""Test getting recent plugins"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/analytics/recent")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "recent_plugins" in data
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_analytics_dashboard():
|
||||
"""Test getting analytics dashboard"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/analytics/dashboard")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "dashboard" in data
|
||||
101
apps/plugin-registry/tests/test_unit_plugin_registry.py
Normal file
101
apps/plugin-registry/tests/test_unit_plugin_registry.py
Normal file
@@ -0,0 +1,101 @@
|
||||
"""Unit tests for plugin registry service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from main import app, PluginRegistration, PluginVersion, SecurityScan
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_app_initialization():
|
||||
"""Test that the FastAPI app initializes correctly"""
|
||||
assert app is not None
|
||||
assert app.title == "AITBC Plugin Registry"
|
||||
assert app.version == "1.0.0"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_plugin_registration_model():
|
||||
"""Test PluginRegistration model"""
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=["test", "demo"],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
homepage_url="https://test.com",
|
||||
license="MIT",
|
||||
dependencies=["dependency1"],
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
assert plugin.name == "Test Plugin"
|
||||
assert plugin.version == "1.0.0"
|
||||
assert plugin.author == "Test Author"
|
||||
assert plugin.category == "testing"
|
||||
assert plugin.tags == ["test", "demo"]
|
||||
assert plugin.license == "MIT"
|
||||
assert plugin.plugin_type == "cli"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_plugin_registration_defaults():
|
||||
"""Test PluginRegistration default values"""
|
||||
plugin = PluginRegistration(
|
||||
name="Test Plugin",
|
||||
version="1.0.0",
|
||||
description="A test plugin",
|
||||
author="Test Author",
|
||||
category="testing",
|
||||
tags=[],
|
||||
repository_url="https://github.com/test/plugin",
|
||||
license="MIT",
|
||||
aitbc_version="1.0.0",
|
||||
plugin_type="cli"
|
||||
)
|
||||
assert plugin.homepage_url is None
|
||||
assert plugin.dependencies == []
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_plugin_version_model():
|
||||
"""Test PluginVersion model"""
|
||||
version = PluginVersion(
|
||||
version="1.0.0",
|
||||
changelog="Initial release",
|
||||
download_url="https://github.com/test/plugin/archive/v1.0.0.tar.gz",
|
||||
checksum="abc123",
|
||||
aitbc_compatibility=["1.0.0", "1.1.0"],
|
||||
release_date=datetime.utcnow()
|
||||
)
|
||||
assert version.version == "1.0.0"
|
||||
assert version.changelog == "Initial release"
|
||||
assert version.download_url == "https://github.com/test/plugin/archive/v1.0.0.tar.gz"
|
||||
assert version.checksum == "abc123"
|
||||
assert version.aitbc_compatibility == ["1.0.0", "1.1.0"]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_security_scan_model():
|
||||
"""Test SecurityScan model"""
|
||||
scan = SecurityScan(
|
||||
scan_id="scan_123",
|
||||
plugin_id="test_plugin",
|
||||
version="1.0.0",
|
||||
scan_date=datetime.utcnow(),
|
||||
vulnerabilities=[{"severity": "low", "description": "Test"}],
|
||||
risk_score="low",
|
||||
passed=True
|
||||
)
|
||||
assert scan.scan_id == "scan_123"
|
||||
assert scan.plugin_id == "test_plugin"
|
||||
assert scan.version == "1.0.0"
|
||||
assert scan.risk_score == "low"
|
||||
assert scan.passed is True
|
||||
assert len(scan.vulnerabilities) == 1
|
||||
Reference in New Issue
Block a user