osint-dashboard/tests/test_camera_publish.py
Sirius DevOps 9809fdf05b fix(cameras): stop publishing discovery rows as events
Camera scrapes still upsert the cameras table. They no longer
JetStream-publish events.camera messages, which the ingester was
inserting as HUD event spam.
2026-11-14 00:30:13 -05:00

59 lines
1.6 KiB
Python

"""Camera discovery must not become an events row."""
from __future__ import annotations
import asyncio
import inspect
import json
from datetime import datetime, timezone
def _camera() -> dict:
now = datetime(2026, 11, 14, 3, 43, tzinfo=timezone.utc)
return {
"vendor": "UCSD",
"source_url": "https://example.test/cameras/ucsd.jpg",
"location_lat": 32.88,
"location_lon": -117.24,
"location_name": "UCSD",
"discovery_source": "ucsd",
"url_hash": "abc123",
"snapshot_url": "https://example.test/cameras/ucsd.jpg",
"device_type": "snapshot",
"first_seen": now,
"last_seen": now,
}
def test_publish_new_cameras_does_not_emit_camera_event(monkeypatch):
"""One newly seen camera must not produce a NATS message with source_type=camera."""
import nats
import run_camera_service as svc
published: list[dict] = []
class _JS:
async def publish(self, _subject, payload):
published.append(json.loads(payload))
class _NC:
def jetstream(self):
return _JS()
async def close(self):
return None
async def _connect(*_a, **_k):
return _NC()
monkeypatch.setattr(nats, "connect", _connect)
if getattr(svc, "nats", None) is not None:
monkeypatch.setattr(svc.nats, "connect", _connect)
n = asyncio.run(svc.publish_new_cameras([_camera()]))
assert n == 0
assert published == []
src = inspect.getsource(svc.publish_new_cameras)
assert "Open camera" not in src
assert '"source_type": "camera"' not in src