| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import sys
- import os
- sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- import numpy as np
- import pytest
- from event_pusher import EventPusher
- def test_upload_numpy_image(monkeypatch):
- config = {"device_id": "test-device", "base_url": "http://localhost"}
- pusher = EventPusher(config)
- called = {"path": None, "existed": False}
- def fake_upload(path):
- called["path"] = path
- called["existed"] = os.path.exists(path)
- return "http://example.com/image.jpg"
- monkeypatch.setattr(pusher, "_upload_image", fake_upload)
- img = np.zeros((100, 100, 3), dtype=np.uint8)
- url = pusher.upload_numpy_image(img)
- assert url == "http://example.com/image.jpg"
- assert called["path"] is not None
- assert called["existed"]
- def test_push_tracking_capture(monkeypatch):
- config = {"device_id": "test-device", "base_url": "http://localhost"}
- pusher = EventPusher(config)
- captured = {}
- def fake_post(url, json):
- captured["url"] = url
- captured["json"] = json
- class Resp:
- status_code = 200
- return Resp()
- monkeypatch.setattr(pusher, "_post", fake_post)
- pusher.push_tracking_capture(
- batch_time=1234567890.0,
- captures=[{"track_id": 1, "ptz_image_url": "url1"}]
- )
- assert captured["json"]["eventType"] == "TRACKING_CAPTURE"
- assert captured["json"]["data"]["captureCount"] == 1
|