feat(Q6): timelapse generator, schedules, and web routes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
49
tests/unit/test_timelapse.py
Normal file
49
tests/unit/test_timelapse.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import datetime
|
||||
import time
|
||||
import pytest
|
||||
from vigilar.config import VigilarConfig, CameraConfig
|
||||
from vigilar.storage.queries import insert_timelapse_schedule, get_timelapse_schedules, delete_timelapse_schedule
|
||||
from vigilar.highlights.timelapse import generate_timelapse
|
||||
from vigilar.web.app import create_app
|
||||
|
||||
def test_insert_schedule(test_db):
|
||||
sid = insert_timelapse_schedule(test_db, "front", "Daily", 6, 20, "20:00")
|
||||
assert sid > 0
|
||||
|
||||
def test_get_schedules(test_db):
|
||||
insert_timelapse_schedule(test_db, "front", "A", 6, 12, "12:00")
|
||||
insert_timelapse_schedule(test_db, "front", "B", 12, 20, "20:00")
|
||||
assert len(get_timelapse_schedules(test_db, "front")) == 2
|
||||
|
||||
def test_delete_schedule(test_db):
|
||||
sid = insert_timelapse_schedule(test_db, "front", "Test", 6, 20, "20:00")
|
||||
delete_timelapse_schedule(test_db, sid)
|
||||
assert len(get_timelapse_schedules(test_db, "front")) == 0
|
||||
|
||||
def test_generate_timelapse_no_recordings(test_db, tmp_path):
|
||||
result = generate_timelapse("front", datetime.date.today(), 6, 20, 30, str(tmp_path), test_db)
|
||||
assert result is None
|
||||
|
||||
@pytest.fixture
|
||||
def timelapse_app(test_db):
|
||||
cfg = VigilarConfig(cameras=[CameraConfig(id="front", display_name="Front", rtsp_url="rtsp://x")])
|
||||
app = create_app(cfg)
|
||||
app.config["TESTING"] = True
|
||||
app.config["DB_ENGINE"] = test_db
|
||||
return app
|
||||
|
||||
def test_post_timelapse(timelapse_app):
|
||||
with timelapse_app.test_client() as c:
|
||||
rv = c.post("/cameras/front/timelapse", json={"date": "2026-04-02"})
|
||||
assert rv.status_code in (200, 202)
|
||||
|
||||
def test_get_schedules_route(timelapse_app, test_db):
|
||||
insert_timelapse_schedule(test_db, "front", "Test", 6, 20, "20:00")
|
||||
with timelapse_app.test_client() as c:
|
||||
rv = c.get("/cameras/front/timelapse/schedules")
|
||||
assert len(rv.get_json()) == 1
|
||||
|
||||
def test_create_schedule_route(timelapse_app):
|
||||
with timelapse_app.test_client() as c:
|
||||
rv = c.post("/cameras/front/timelapse/schedule", json={"name": "Daily", "time": "20:00"})
|
||||
assert rv.status_code == 200
|
||||
Reference in New Issue
Block a user