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:
Marker689
2026-05-10 07:58:03 +03:00
parent d11be24c5f
commit f252c256d8
5 changed files with 255 additions and 0 deletions

88
tests/test_nexus.py Normal file
View File

@@ -0,0 +1,88 @@
"""Tests for Nexus package info extractors."""
from guarddog_nexus.core.nexus import (
extract_go_info,
extract_npm_info,
extract_package_info,
extract_pypi_info,
)
class TestPyPIExtractor:
def test_simple(self):
assert extract_pypi_info("/packages/requests/2.31.0/requests-2.31.0.tar.gz") == (
"requests",
"2.31.0",
)
def test_leading_slash(self):
assert extract_pypi_info("packages/numpy/1.24.0/numpy-1.24.0.tar.gz") == (
"numpy",
"1.24.0",
)
def test_non_package(self):
assert extract_pypi_info("/some/path") is None
def test_too_short(self):
assert extract_pypi_info("/packages/pkg") is None
class TestGoExtractor:
def test_simple(self):
assert extract_go_info("packages/github.com/gorilla/mux/@v/v1.8.0.zip") == (
"github.com/gorilla/mux",
"v1.8.0",
)
def test_long_module(self):
assert extract_go_info(
"/packages/github.com/gin-gonic/gin/@v/v1.9.0.zip"
) == ("github.com/gin-gonic/gin", "v1.9.0")
def test_no_at_v(self):
assert extract_go_info("packages/some/pkg/v1.0.0.zip") is None
def test_empty(self):
assert extract_go_info("") is None
class TestNpmExtractor:
def test_simple(self):
assert extract_npm_info("packages/lodash/-/lodash-4.17.21.tgz") == (
"lodash",
"4.17.21",
)
def test_scoped_package(self):
# Note: scoped packages have a different path in Nexus
assert extract_npm_info("packages/@scope/name/-/name-1.0.0.tgz") is None
def test_not_packages(self):
assert extract_npm_info("/other/lodash/-/lodash-4.17.21.tgz") is None
def test_short_path(self):
assert extract_npm_info("packages/lodash") is None
class TestDispatchExtractor:
def test_pypi(self):
assert extract_package_info(
"/packages/requests/2.31.0/requests-2.31.0.tar.gz", "pypi"
) == ("requests", "2.31.0")
def test_go(self):
assert extract_package_info(
"github.com/gorilla/mux/@v/v1.8.0.zip", "go"
) == ("github.com/gorilla/mux", "v1.8.0")
def test_npm(self):
assert extract_package_info(
"packages/lodash/-/lodash-4.17.21.tgz", "npm"
) == ("lodash", "4.17.21")
def test_unknown_ecosystem(self):
assert extract_package_info(
"/packages/pkg/1.0/file.tar.gz", "unknown"
) == ("pkg", "1.0")