#132 | #121: backoffice / dev-1.0-121 (#131)

cfr #121

Co-authored-by: Christophe Siraut <d@tobald.eu.org>
Co-authored-by: bkfox <thomas bkfox net>
Co-authored-by: Thomas Kairos <thomas@bkfox.net>
Reviewed-on: rc/aircox#131
Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
This commit is contained in:
2024-04-28 22:02:09 +02:00
committed by Thomas Kairos
parent 1e17a1334a
commit 55123c386d
348 changed files with 124397 additions and 17879 deletions

View File

@ -1,14 +1,12 @@
import pytest
from datetime import timedelta
from django.conf import settings as conf
from django.utils import timezone as tz
from aircox import models
from aircox.controllers.sound_file import SoundFile
# FIXME: use from tests.models.sound
@pytest.fixture
def path_infos():
return {
@ -27,6 +25,7 @@ def path_infos():
"day": 2,
"hour": 10,
"minute": 13,
"n": None,
"name": "Sample 2",
},
"test/20220103_1_sample_3.mp3": {
@ -56,42 +55,25 @@ def sound_files(path_infos):
return {k: r for k, r in ((path, SoundFile(conf.MEDIA_ROOT + "/" + path)) for path in path_infos.keys())}
@pytest.fixture
def sound_file(sound_files):
return next(sound_files.items())
def test_sound_path(sound_files):
for path, sound_file in sound_files.items():
assert path == sound_file.sound_path
def test_read_path(path_infos, sound_files):
for path, sound_file in sound_files.items():
expected = path_infos[path]
result = sound_file.read_path(path)
# remove None values
result = {k: v for k, v in result.items() if v is not None}
assert expected == result, "path: {}".format(path)
class TestSoundFile:
def sound_path(self, sound_file):
assert sound_file[0] == sound_file[1].sound_path
def sync(self):
raise NotImplementedError("test is not implemented")
def _setup_diff(program, info):
episode = models.Episode(program=program, title="test-episode")
at = tz.datetime(**{k: info[k] for k in ("year", "month", "day", "hour", "minute") if info.get(k)})
at = tz.make_aware(at)
diff = models.Diffusion(episode=episode, start=at, end=at + timedelta(hours=1))
episode.save()
diff.save()
return diff
def create_episode_sound(self):
raise NotImplementedError("test is not implemented")
@pytest.mark.django_db(transaction=True)
def test_find_episode(sound_files):
station = models.Station(name="test-station")
program = models.Program(station=station, title="test")
station.save()
program.save()
for path, sound_file in sound_files.items():
infos = sound_file.read_path(path)
diff = _setup_diff(program, infos)
sound = models.Sound(program=diff.program, file=path)
result = sound_file.find_episode(sound, infos)
assert diff.episode == result
# TODO: find_playlist, sync
def _on_delete(self):
raise NotImplementedError("test is not implemented")

View File

@ -223,22 +223,19 @@ class TestSoundMonitor:
[
(("scan all programs...",), {}),
]
+ [
((f"#{program.id} {program.title}",), {})
for program in programs
]
+ [((f"#{program.id} {program.title}",), {}) for program in programs]
)
assert dirs == [program.abspath for program in programs]
traces = tuple(
[
[
(
(program, settings.SOUND_ARCHIVES_SUBDIR),
{"logger": logger, "type": Sound.TYPE_ARCHIVE},
(program, settings.SOUND_BROADCASTS_SUBDIR),
{"logger": logger, "broadcast": True},
),
(
(program, settings.SOUND_EXCERPTS_SUBDIR),
{"logger": logger, "type": Sound.TYPE_EXCERPT},
{"logger": logger, "broadcast": False},
),
]
for program in programs
@ -247,6 +244,7 @@ class TestSoundMonitor:
traces_flat = tuple([item for sublist in traces for item in sublist])
assert interface._traces("scan_for_program") == traces_flat
# TODO / FIXME
def broken_test_monitor(self, monitor, monitor_interfaces, logger):
def sleep(*args, **kwargs):
monitor.stop()
@ -260,6 +258,7 @@ class TestSoundMonitor:
assert observer
schedules = observer._traces("schedule")
for (handler, *_), kwargs in schedules:
breakpoint()
assert isinstance(handler, sound_monitor.MonitorHandler)
assert isinstance(handler.pool, futures.ThreadPoolExecutor)
assert (handler.subdir, handler.type) in (