Skip to content
Snippets Groups Projects
Verified Commit 84fc954e authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

test: add one week calendar program tests

parent 75943bed
No related branches found
No related tags found
1 merge request!52new program endpoint
from datetime import datetime, timedelta
import pytest import pytest
from conftest import create_daily_schedule from conftest import create_daily_schedule
...@@ -16,19 +18,20 @@ def url(include_virtual=False, start=None, end=None): ...@@ -16,19 +18,20 @@ def url(include_virtual=False, start=None, end=None):
return "/api/v1/program/calendar/" return "/api/v1/program/calendar/"
def assert_episodes(episodes) -> None: def assert_episodes(episodes, one_week=False) -> None:
"""asserts the episodes are valid.""" """asserts the episodes are valid."""
assert len(episodes) == 1 assert len(episodes) == 1 if not one_week else 7
assert episodes[0]["id"] for episode in episodes:
assert episodes[0]["timeslotId"] assert episode["id"]
assert episode["timeslotId"]
def assert_program(program, show, fallback_show=None) -> None: def assert_program(program, show, fallback_show=None, one_week=False) -> None:
"""asserts the program are valid and correspond to the given show and fallback show.""" """asserts the program are valid and correspond to the given show and fallback show."""
assert len(program) == 1 if fallback_show is None else 3 assert len(program) == 1 if fallback_show is None and not one_week else (7 if one_week else 3)
assert program[0]["end"] assert program[0]["end"]
assert program[0]["id"] assert program[0]["id"]
...@@ -60,16 +63,17 @@ def assert_shows(shows, show, fallback_show=None) -> None: ...@@ -60,16 +63,17 @@ def assert_shows(shows, show, fallback_show=None) -> None:
assert shows[1]["name"] == fallback_show.name assert shows[1]["name"] == fallback_show.name
def assert_timeslots(timeslots, show) -> None: def assert_timeslots(timeslots, show, one_week=False) -> None:
"""asserts the timeslots are valid correspond to the given show.""" """asserts the timeslots are valid and correspond to the given show."""
assert len(timeslots) == 1 assert len(timeslots) == 1 if not one_week else 7
assert timeslots[0]["id"] for timeslot in timeslots:
assert timeslots[0]["noteId"] assert timeslot["id"]
assert timeslots[0]["end"] assert timeslot["noteId"]
assert timeslots[0]["start"] assert timeslot["end"]
assert timeslots[0]["showId"] == show.id assert timeslot["start"]
assert timeslot["showId"] == show.id
def test_calendar(admin_api_client, api_client, daily_rrule, show): def test_calendar(admin_api_client, api_client, daily_rrule, show):
...@@ -91,6 +95,28 @@ def test_calendar(admin_api_client, api_client, daily_rrule, show): ...@@ -91,6 +95,28 @@ def test_calendar(admin_api_client, api_client, daily_rrule, show):
assert_timeslots(value, show) assert_timeslots(value, show)
def test_calendar_one_week(admin_api_client, api_client, daily_rrule, show):
create_daily_schedule(admin_api_client, daily_rrule, show)
now = datetime.now()
in_one_week = now + timedelta(days=7)
response = api_client.get(url(start=now.isoformat(), end=in_one_week.isoformat()))
assert response.status_code == 200
for key, value in response.json().items():
match key:
case "episodes":
assert_episodes(value, one_week=True)
case "program":
assert_program(value, show, one_week=True)
case "shows":
assert_shows(value, show)
case "timeslots":
assert_timeslots(value, show, one_week=True)
def test_calendar_include_virtual( def test_calendar_include_virtual(
admin_api_client, admin_api_client,
api_client, api_client,
...@@ -110,9 +136,39 @@ def test_calendar_include_virtual( ...@@ -110,9 +136,39 @@ def test_calendar_include_virtual(
case "episodes": case "episodes":
assert_episodes(value) assert_episodes(value)
case "program": case "program":
print(value)
assert_program(value, show, fallback_show) assert_program(value, show, fallback_show)
case "shows": case "shows":
assert_shows(value, show, fallback_show) assert_shows(value, show, fallback_show)
case "timeslots": case "timeslots":
assert_timeslots(value, show) assert_timeslots(value, show)
def test_calendar_one_week_include_virtual(
admin_api_client,
api_client,
daily_rrule,
show,
fallback_show,
radio_settings,
):
create_daily_schedule(admin_api_client, daily_rrule, show)
now = datetime.now()
in_one_week = now + timedelta(days=7)
response = api_client.get(
url(include_virtual=True, start=now.isoformat(), end=in_one_week.isoformat())
)
assert response.status_code == 200
for key, value in response.json().items():
match key:
case "episodes":
assert_episodes(value, one_week=True)
case "program":
assert_program(value, show=show, fallback_show=fallback_show, one_week=True)
case "shows":
assert_shows(value, show=show, fallback_show=fallback_show)
case "timeslots":
assert_timeslots(value, show=show, one_week=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment