finish writing controllers.monitor tests

This commit is contained in:
bkfox
2023-06-18 16:56:34 +02:00
parent a1ca0e70cf
commit fed076348b
4 changed files with 290 additions and 37 deletions

View File

@ -66,7 +66,7 @@ class Monitor:
"diffusion", "sound", "track"
).order_by("-pk")
def init_last_sound_logs(self, key=None):
def init_last_sound_logs(self):
"""Retrieve last logs and initialize `last_sound_logs`"""
logs = {}
for source in self.streamer.sources:
@ -159,7 +159,7 @@ class Monitor:
return
tracks = Track.objects.filter(
sound__id=log.sound_id, timestamp__isnull=False
sound_id=log.sound_id, timestamp__isnull=False
).order_by("timestamp")
if not tracks.exists():
return
@ -169,15 +169,14 @@ class Monitor:
now = tz.now()
for track in tracks:
pos = log.date + tz.timedelta(seconds=track.timestamp)
if pos > now:
break
self.log(
type=Log.TYPE_ON_AIR,
date=pos,
source=log.source,
track=track,
comment=track,
)
if pos <= now:
self.log(
type=Log.TYPE_ON_AIR,
date=pos,
source=log.source,
track=track,
comment=track,
)
def handle_diffusions(self):
"""Handle scheduled diffusion, trigger if needed, preload playlists and