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
from conftest import create_daily_schedule
......@@ -16,19 +18,20 @@ def url(include_virtual=False, start=None, end=None):
return "/api/v1/program/calendar/"
def assert_episodes(episodes) -> None:
def assert_episodes(episodes, one_week=False) -> None:
"""asserts the episodes are valid."""
assert len(episodes) == 1
assert len(episodes) == 1 if not one_week else 7
assert episodes[0]["id"]
assert episodes[0]["timeslotId"]
for episode in episodes:
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."""
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]["id"]
......@@ -60,16 +63,17 @@ def assert_shows(shows, show, fallback_show=None) -> None:
assert shows[1]["name"] == fallback_show.name
def assert_timeslots(timeslots, show) -> None:
"""asserts the timeslots are valid correspond to the given show."""
def assert_timeslots(timeslots, show, one_week=False) -> None:
"""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"]
assert timeslots[0]["noteId"]
assert timeslots[0]["end"]
assert timeslots[0]["start"]
assert timeslots[0]["showId"] == show.id
for timeslot in timeslots:
assert timeslot["id"]
assert timeslot["noteId"]
assert timeslot["end"]
assert timeslot["start"]
assert timeslot["showId"] == show.id
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)
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(
admin_api_client,
api_client,
......@@ -110,9 +136,39 @@ def test_calendar_include_virtual(
case "episodes":
assert_episodes(value)
case "program":
print(value)
assert_program(value, show, fallback_show)
case "shows":
assert_shows(value, show, fallback_show)
case "timeslots":
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