From 2da9f016ea71d88f1bb2ad3963ec32e3eb905abc Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Mon, 15 Jul 2024 14:52:02 -0400
Subject: [PATCH] test: add basic program tests

---
 program/tests/test_basic_program.py | 74 +++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 program/tests/test_basic_program.py

diff --git a/program/tests/test_basic_program.py b/program/tests/test_basic_program.py
new file mode 100644
index 00000000..c724cfe9
--- /dev/null
+++ b/program/tests/test_basic_program.py
@@ -0,0 +1,74 @@
+import pytest
+
+from conftest import create_daily_schedule
+
+pytestmark = pytest.mark.django_db
+
+
+def url(include_virtual=False):
+    if include_virtual:
+        return "/api/v1/program/basic/?include_virtual=true"
+
+    return "/api/v1/program/basic/"
+
+
+def assert_entry(entry, show) -> None:
+    """asserts the playout entry corresponds to the given show."""
+
+    assert entry["end"]
+    assert entry["id"]
+    assert "playlistId" in entry
+    assert entry["start"]
+    assert entry["timeslotId"]
+
+    assert entry["showId"] == show.id
+
+
+def assert_virtual_entry(entry, fallback_show) -> None:
+    """asserts the playout entry is virtual and corresponds to given fallback show."""
+
+    assert entry["end"]
+    assert entry["id"]
+    assert "playlistId" in entry
+    assert entry["start"]
+
+    assert not entry["timeslotId"]
+
+    assert entry["showId"] == fallback_show.id
+
+
+def test_basic(admin_api_client, api_client, daily_rrule, show):
+    create_daily_schedule(admin_api_client, daily_rrule, show)
+
+    response = api_client.get(url())
+
+    assert response.status_code == 200
+    assert len(response.json()) == 1
+
+    assert_entry(response.json()[0], show)
+
+
+def test_basic_include_virtual(
+    admin_api_client,
+    api_client,
+    daily_rrule,
+    show,
+    fallback_show,
+    radio_settings,
+):
+
+    create_daily_schedule(admin_api_client, daily_rrule, show)
+
+    response = api_client.get(url(include_virtual=True))
+
+    assert response.status_code == 200
+    assert len(response.json()) == 3
+
+    virtual_entry1, entry, virtual_entry2 = response.json()
+
+    assert_virtual_entry(virtual_entry1, fallback_show)
+    assert_entry(entry, show)
+    assert_virtual_entry(virtual_entry2, fallback_show)
+
+    assert virtual_entry1["end"] == entry["start"]
+    assert entry["end"] == virtual_entry2["start"]
-- 
GitLab