Files
meshcore-hub/tests/test_common/test_schemas_routes.py
T
Louis King a64d0b5561 test: close Route Health Monitoring coverage gaps (PR #308)
Add 49 targeted tests across 8 files to lift patch coverage from 76.9%
to ~95%+:

- collector/cli.py (3% -> covered): TestImportRoutes (12 tests for
  _import_routes: happy-path, upsert, all error branches, exception
  handler) + TestRouteSeedImport (seed command integration).
- api/routes/routes.py: update_route all-field branch, duplicate-label
  409, observer sync, unresolved-nodes 400, hidden-route 404, get_route
  contributing-observers, create with observers, preview guards,
  history retention clamp.
- collector/routes.py: evaluate_all_routes exception handler, preview
  early-return guards, evaluate_route_history < 2 expected, limit/until/
  observer params on fetch_candidate_paths, _route_expected_hashes
  derive branch, _has_any_hops_per_day empty guard.
- collector/subscriber.py: TestRouteEvaluatorScheduler (disabled,
  runs-and-stops, error-is-logged) mirroring TestSpamRescoreScheduler.
- common/schemas/routes.py: RouteUpdate + RoutePreviewRequest validators
  (min nodes, distinct, clear_threshold).
- collector/route_evaluator.py: evaluation exception handler.
- common/config.py: route_evaluator_interval_seconds default + custom.
- api/routes/packet_groups.py: mixed-visibility representative selection.
2026-07-16 23:30:28 +01:00

39 lines
1.5 KiB
Python

"""Tests for route schema validators (RouteUpdate, RoutePreviewRequest)."""
import pytest
from pydantic import ValidationError
from meshcore_hub.common.schemas.routes import RoutePreviewRequest, RouteUpdate
class TestRouteUpdateValidator:
def test_min_two_nodes(self):
with pytest.raises(ValidationError, match="At least 2 path nodes"):
RouteUpdate(node_public_keys=["a" * 64])
def test_distinct_nodes(self):
with pytest.raises(ValidationError, match="Path nodes must be distinct"):
RouteUpdate(node_public_keys=["a" * 64, "a" * 64])
def test_clear_threshold_must_exceed_packet_count(self):
with pytest.raises(ValidationError, match="clear_threshold must be >"):
RouteUpdate(packet_count_threshold=5, clear_threshold=5)
def test_clear_threshold_ok_when_only_one_set(self):
route = RouteUpdate(clear_threshold=5)
assert route.clear_threshold == 5
def test_clear_threshold_gt_packet_count_ok(self):
route = RouteUpdate(packet_count_threshold=3, clear_threshold=6)
assert route.clear_threshold == 6
class TestRoutePreviewValidator:
def test_distinct_nodes(self):
with pytest.raises(ValidationError, match="Path nodes must be distinct"):
RoutePreviewRequest(node_public_keys=["a" * 64, "a" * 64])
def test_min_two_nodes(self):
with pytest.raises(ValidationError, match="At least 2 path nodes"):
RoutePreviewRequest(node_public_keys=["a" * 64])