82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Test multi-channel same-room with distinct clip offsets."""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
from app.timeutil import push_date_from_ts
|
|
|
|
|
|
def test_same_room_multi_channel_offsets(temp_db):
|
|
day = push_date_from_ts(time.time())
|
|
ch_a = temp_db.create_shorts_channel(name="A", daily_min=9, daily_max=9, enabled=True)
|
|
ch_b = temp_db.create_shorts_channel(name="B", daily_min=9, daily_max=9, enabled=True)
|
|
ch_c = temp_db.create_shorts_channel(name="C", daily_min=9, daily_max=9, enabled=True)
|
|
|
|
off0 = temp_db.next_shorts_room_clip_offset("roomX", day, clip_sec=15)
|
|
assert off0 == 0
|
|
j1 = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="roomX",
|
|
channel_pk=ch_a["id"],
|
|
push_date=day,
|
|
clip_offset_sec=off0,
|
|
)
|
|
assert j1 is not None
|
|
assert float(j1.get("clip_offset_sec") or 0) == 0
|
|
|
|
off1 = temp_db.next_shorts_room_clip_offset("roomX", day, clip_sec=15)
|
|
assert off1 == 15
|
|
j2 = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="roomX",
|
|
channel_pk=ch_b["id"],
|
|
push_date=day,
|
|
clip_offset_sec=off1,
|
|
)
|
|
assert j2 is not None
|
|
assert float(j2.get("clip_offset_sec") or 0) == 15
|
|
|
|
off2 = temp_db.next_shorts_room_clip_offset("roomX", day, clip_sec=15)
|
|
assert off2 == 30
|
|
j3 = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="roomX",
|
|
channel_pk=ch_c["id"],
|
|
push_date=day,
|
|
clip_offset_sec=off2,
|
|
)
|
|
assert j3 is not None
|
|
|
|
# Same channel cannot reuse same room
|
|
j_dup = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="roomX",
|
|
channel_pk=ch_a["id"],
|
|
push_date=day,
|
|
clip_offset_sec=45,
|
|
)
|
|
assert j_dup is None
|
|
|
|
|
|
def test_legacy_global_dedupe_still_works(temp_db):
|
|
day = push_date_from_ts(time.time())
|
|
ch_a = temp_db.create_shorts_channel(name="A2", daily_min=9, daily_max=9, enabled=True)
|
|
ch_b = temp_db.create_shorts_channel(name="B2", daily_min=9, daily_max=9, enabled=True)
|
|
j1 = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="roomY",
|
|
channel_pk=ch_a["id"],
|
|
push_date=day,
|
|
dedupe_room_global=True,
|
|
)
|
|
assert j1 is not None
|
|
j2 = temp_db.create_shorts_job(
|
|
session_id="",
|
|
room_id="roomY",
|
|
channel_pk=ch_b["id"],
|
|
push_date=day,
|
|
dedupe_room_global=True,
|
|
)
|
|
assert j2 is None
|