From 018ba26ba3e437710d18cc586871fc981c842cf4 Mon Sep 17 00:00:00 2001
From: David Trattnig <david@subsquare.at>
Date: Mon, 11 Mar 2024 15:01:06 +0100
Subject: [PATCH] test: timeslot without any playlist

---
 tests/json/steering-api-v1-playout.json | 20 +++++++++++++++
 tests/test_scheduling_api_fetcher.py    | 34 +++++++++++++++++++++++--
 tests/test_scheduling_api_steering.py   |  2 +-
 3 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/tests/json/steering-api-v1-playout.json b/tests/json/steering-api-v1-playout.json
index d35966e5..d91bc743 100644
--- a/tests/json/steering-api-v1-playout.json
+++ b/tests/json/steering-api-v1-playout.json
@@ -78,5 +78,25 @@
       "showMusicFocus": "",
       "showLanguages": "",
       "showFundingCategory": "Standard"
+   },
+   {
+      "id": 21,
+      "start": "2023-05-16T15:10:00",
+      "end": "2023-05-16T15:50:00",
+      "title": "Pepi's Polka III",
+      "scheduleId": 20,
+      "repetitionOfId": null,
+      "playlistId": null,
+      "scheduleDefaultPlaylistId": null,
+      "showDefaultPlaylistId": null,
+      "showId": 1,
+      "showName": "Musikprogramm",
+      "showHosts": "Musikredaktion",
+      "showType": "Unmoderiertes Musikprogramm",
+      "showCategories": "",
+      "showTopics": "",
+      "showMusicFocus": "",
+      "showLanguages": "",
+      "showFundingCategory": "Standard"
    }
 ]
\ No newline at end of file
diff --git a/tests/test_scheduling_api_fetcher.py b/tests/test_scheduling_api_fetcher.py
index d5c831dc..ca4cb7b5 100644
--- a/tests/test_scheduling_api_fetcher.py
+++ b/tests/test_scheduling_api_fetcher.py
@@ -154,7 +154,7 @@ class TestSchedulingApiFetcher(unittest.TestCase):
         # Test Timetable
         self.assertEqual(ApiResult, type(response))
         self.assertEqual(0, response.code)
-        self.assertEqual(3, len(response.timeslots))
+        self.assertEqual(4, len(response.timeslots))
 
         # Test Timeslot 1
         ts1: Timeslot = response.timeslots[0]
@@ -298,6 +298,36 @@ class TestSchedulingApiFetcher(unittest.TestCase):
         self.assertIsNotNone(pl_items[4].next)
         self.assertIsNone(pl_items[5].next)
 
+    @mock.patch("aura_engine.base.api.requests.get", side_effect=mocked_requests_get)
+    def test_fetch_timeslot_without_playlists(self, mock_get):
+        print(self._testMethodName)
+
+        # Clear cache to keep test cases isolated
+        self.api_fetcher.api.prune_cache_dir()
+
+        # Start fetching thread
+        self.api_fetcher.start()
+        response: ApiResult = self.api_fetcher.fetch()
+        print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
+        print("[test_fetch_data] response message: " + str(response.message))
+        if response.exception:
+            print("[test_fetch_data] response exception: \n" + str(response.exception))
+
+        # Test Timetable
+        self.assertEqual(ApiResult, type(response))
+        self.assertEqual(0, response.code)
+        self.assertEqual(4, len(response.timeslots))
+
+        # Test Timeslot 1
+        ts1: Timeslot = response.timeslots[3]
+        self.assertEqual(1, ts1.show.id)
+        self.assertEqual("Pepi's Polka III", ts1.episode.title)
+
+        # Test Timeslot 1 - there are no playlists assigned
+        self.assertIsNone(ts1.playlist.timeslot)
+        self.assertIsNone(ts1.playlist.schedule)
+        self.assertIsNone(ts1.playlist.show)
+
     @mock.patch("aura_engine.base.api.requests.get", side_effect=mocked_requests_get)
     def test_fetch_with_expanded_duration(self, mock_get):
         print(self._testMethodName)
@@ -316,7 +346,7 @@ class TestSchedulingApiFetcher(unittest.TestCase):
         # Test Timetable
         self.assertEqual(ApiResult, type(response))
         self.assertEqual(0, response.code)
-        self.assertEqual(3, len(response.timeslots))
+        self.assertEqual(4, len(response.timeslots))
 
         # Test Timeslot 3
         ts1: Timeslot = response.timeslots[2]
diff --git a/tests/test_scheduling_api_steering.py b/tests/test_scheduling_api_steering.py
index 68317098..4042feac 100644
--- a/tests/test_scheduling_api_steering.py
+++ b/tests/test_scheduling_api_steering.py
@@ -53,7 +53,7 @@ class TestApiSteering(unittest.TestCase):
             timetable.append(t)
 
         self.assertIsNotNone(timetable)
-        self.assertEqual(4, len(timetable))
+        self.assertEqual(5, len(timetable))
 
         t1 = timetable[0]
         self.assertEqual(17, t1.id)
-- 
GitLab