Skip to content
Snippets Groups Projects
Commit d327bbdc authored by David Trattnig's avatar David Trattnig
Browse files

test: timetable renderer

parent f13ad211
No related branches found
No related tags found
1 merge request!35ORM-less scheduling
...@@ -20,8 +20,20 @@ ...@@ -20,8 +20,20 @@
import unittest import unittest
from aura_engine.base.config import AuraConfig from aura_engine.base.config import AuraConfig
from aura_engine.scheduling.domain import PlaylistItem from aura_engine.base.utils import SimpleUtil as SU
from aura_engine.scheduling.utils import M3UPlaylistProcessor from aura_engine.scheduling.domain import Playlist, PlaylistItem, Timeslot
from aura_engine.scheduling.programme import TimetableService
from aura_engine.scheduling.utils import M3UPlaylistProcessor, TimetableRenderer
class MockedScheduler:
timetable: TimetableService
def __init__(self, timetable: [Timeslot]):
self.timetable = timetable
def get_timetable(self) -> TimetableService:
return self.timetable
class TestSchedulingUtils(unittest.TestCase): class TestSchedulingUtils(unittest.TestCase):
...@@ -31,6 +43,7 @@ class TestSchedulingUtils(unittest.TestCase): ...@@ -31,6 +43,7 @@ class TestSchedulingUtils(unittest.TestCase):
config = None config = None
m3u = None m3u = None
timetable: TimetableService
# Setup and teardown # Setup and teardown
...@@ -39,6 +52,9 @@ class TestSchedulingUtils(unittest.TestCase): ...@@ -39,6 +52,9 @@ class TestSchedulingUtils(unittest.TestCase):
self.m3u = M3UPlaylistProcessor() self.m3u = M3UPlaylistProcessor()
self.m3u.playlist_folder = "./tests/m3u/" self.m3u.playlist_folder = "./tests/m3u/"
cache_location = self.config.get("cache_dir")
self.timetable = TimetableService(cache_location)
def tearDown(self): def tearDown(self):
pass pass
...@@ -69,13 +85,63 @@ class TestSchedulingUtils(unittest.TestCase): ...@@ -69,13 +85,63 @@ class TestSchedulingUtils(unittest.TestCase):
def test_spread_no_m3u_playlist(self): def test_spread_no_m3u_playlist(self):
print(self._testMethodName) print(self._testMethodName)
print(self._testMethodName)
item = PlaylistItem("playlist://404.m3u", None, 100, PlaylistItem.Metadata("", "", "")) item = PlaylistItem("playlist://404.m3u", None, 100, PlaylistItem.Metadata("", "", ""))
items = self.m3u.spread(item) items = self.m3u.spread(item)
self.assertEqual(0, len(items)) self.assertEqual(0, len(items))
def test_timetable_renderer(self):
print(self._testMethodName)
# Build timeslots
now = SU.timestamp()
ts1 = Timeslot(
id=1, repetition_id=None, start=now - 180, end=now - 120, show=None, episode=None
)
ts2 = Timeslot(
id=1, repetition_id=None, start=now - 120, end=now + 120, show=None, episode=None
)
ts3 = Timeslot(
id=1, repetition_id=None, start=now + 120, end=now + 180, show=None, episode=None
)
ts4 = Timeslot(
id=1, repetition_id=None, start=now + 180, end=now + 360, show=None, episode=None
)
# Set playlist for timeslot 2 (currently playing)
pl = Playlist("999", "Playlist X", False)
alpha = PlaylistItem("alpha.flac", 20, 100, None)
beta = PlaylistItem("beta.flac", 100, 100, None)
gamma = PlaylistItem("gamma.flac", 20, 100, None)
delta = PlaylistItem("delta.flac", 200, 100, None)
epsilon = PlaylistItem("epsilon.flac", 300, 100, None)
pl.add(alpha)
pl.add(beta)
pl.add(gamma)
pl.add(delta)
pl.add(epsilon)
ts2.set_playlists(None, pl, None)
# Set playlist for timeslot 3 (playing next)
pl = Playlist("555", "Playlist Y", False)
alpha = PlaylistItem("red.flac", 20, 100, None)
beta = PlaylistItem("green.flac", 100, 100, None)
gamma = PlaylistItem("blue.flac", 20, 100, None)
pl.add(alpha)
pl.add(beta)
pl.add(gamma)
ts3.set_playlists(pl, None, None)
timeslots = [ts1, ts2, ts3, ts4]
self.timetable.timetable = timeslots
scheduler = MockedScheduler(self.timetable)
# Build and display report
tr = TimetableRenderer(scheduler)
report = tr.get_ascii_timeslots()
print(report)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment