test: фаза 4 — тесты extractors, ecosystem, i18n, metrics
- test_nexus.py: extract_pypi/go/npm, dispatch, edge cases (16 тестов) - test_i18n.py: RU/EN переводы, fallback, форматирование, web UI (10 тестов) - test_metrics.py: Prometheus endpoint (4 теста) - test_webhooks.py: _detect_ecosystem (6 тестов), Go/npm webhook fixtures - conftest.py: sample_nexus_go/npm_webhook fixtures - Всего: 85 тестов (было 50)
This commit is contained in:
@@ -82,3 +82,52 @@ async def test_webhook_component_no_version(client, sample_nexus_component_webho
|
||||
resp = await client.post("/webhooks/nexus", json=sample_nexus_component_webhook)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "ignored"
|
||||
|
||||
|
||||
# --- Ecosystem detection tests ---
|
||||
|
||||
def test_detect_ecosystem_pypi():
|
||||
from guarddog_nexus.routes.webhooks import _detect_ecosystem
|
||||
|
||||
assert _detect_ecosystem({"format": "pypi"}) == "pypi"
|
||||
assert _detect_ecosystem({"format": "pip"}) == "pypi"
|
||||
assert _detect_ecosystem({"format": "python"}) == "pypi"
|
||||
|
||||
|
||||
def test_detect_ecosystem_go():
|
||||
from guarddog_nexus.routes.webhooks import _detect_ecosystem
|
||||
|
||||
assert _detect_ecosystem({"format": "go"}) == "go"
|
||||
assert _detect_ecosystem({"format": "golang"}) == "go"
|
||||
|
||||
|
||||
def test_detect_ecosystem_npm():
|
||||
from guarddog_nexus.routes.webhooks import _detect_ecosystem
|
||||
|
||||
assert _detect_ecosystem({"format": "npm"}) == "npm"
|
||||
assert _detect_ecosystem({"format": "node"}) == "npm"
|
||||
|
||||
|
||||
def test_detect_ecosystem_unknown():
|
||||
from guarddog_nexus.routes.webhooks import _detect_ecosystem
|
||||
|
||||
assert _detect_ecosystem({"format": "maven"}) == "maven"
|
||||
assert _detect_ecosystem({}) == "pypi" # default
|
||||
|
||||
|
||||
# --- Go/npm webhook integration ---
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_webhook_go_asset(client, sample_nexus_go_webhook):
|
||||
with patch("guarddog_nexus.routes.webhooks._scan_in_background") as _mock:
|
||||
resp = await client.post("/webhooks/nexus", json=sample_nexus_go_webhook)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "accepted"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_webhook_npm_asset(client, sample_nexus_npm_webhook):
|
||||
with patch("guarddog_nexus.routes.webhooks._scan_in_background") as _mock:
|
||||
resp = await client.post("/webhooks/nexus", json=sample_nexus_npm_webhook)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "accepted"
|
||||
|
||||
Reference in New Issue
Block a user