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

test: add tests for day schedule & playout

parent bb088cbd
No related branches found
No related tags found
No related merge requests found
Pipeline #8263 passed
from datetime import datetime, timedelta
import pytest
pytestmark = pytest.mark.django_db
def url(include_virtual=False):
year, month, day = datetime.today().year, datetime.today().month, datetime.today().day
if include_virtual:
return f"/api/v1/program/{year}/{month}/{day}/?include_virtual=true"
else:
return f"/api/v1/program/{year}/{month}/{day}/"
def create_once_schedule(admin_api_client, once_rrule, show) -> None:
"""creates a schedule for a show that repeats once using the REST API."""
now = datetime.now()
in_an_hour = now + timedelta(hours=1)
data = {
"schedule": {
"end_time": in_an_hour.strftime("%H:%M:%S"),
"first_date": now.strftime("%Y-%m-%d"),
"last_date": None,
"rrule_id": once_rrule.id,
"show_id": show.id,
"start_time": now.strftime("%H:%M:%S"),
},
}
admin_api_client.post("/api/v1/schedules/", data=data, format="json")
def test_day_schedule(admin_api_client, api_client, once_rrule, show):
create_once_schedule(admin_api_client, once_rrule, show)
response = api_client.get(url())
assert response.status_code == 200
assert len(response.json()) == 1
entry = response.json()[0]
assert not entry["isVirtual"]
assert entry["showId"] == show.id
assert entry["showName"] == show.name
def test_day_schedule_include_virtual(
admin_api_client,
api_client,
once_rrule,
show,
fallback_show,
radio_settings,
):
create_once_schedule(admin_api_client, once_rrule, show)
response = api_client.get(url(include_virtual=True))
assert response.status_code == 200
assert len(response.json()) == 3
for entry in response.json():
if entry["isVirtual"]:
print("V")
assert entry["showId"] == fallback_show.id
assert entry["showName"] == fallback_show.name
else:
print("R")
assert entry["showId"] == show.id
assert entry["showName"] == show.name
from datetime import datetime, timedelta
import pytest
pytestmark = pytest.mark.django_db
def url(include_virtual=False):
if include_virtual:
return "/api/v1/playout/?include_virtual=true"
return "/api/v1/playout/"
def create_daily_schedule(admin_api_client, daily_rrule, show) -> None:
"""creates a schedule for a show that repeats daily using the REST API."""
now = datetime.now()
in_one_hour = now + timedelta(hours=1)
in_seven_days = now + timedelta(days=7)
data = {
"schedule": {
"end_time": in_one_hour.strftime("%H:%M:%S"),
"first_date": now.strftime("%Y-%m-%d"),
"last_date": in_seven_days.strftime("%Y-%m-%d"),
"rrule_id": daily_rrule.id,
"show_id": show.id,
"start_time": now.strftime("%H:%M:%S"),
}
}
admin_api_client.post("/api/v1/schedules/", data=data, format="json")
def test_playout(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()) == 7
for entry in response.json():
assert not entry["isVirtual"]
assert entry["showId"] == show.id
assert entry["showName"] == show.name
def test_playout_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()) == 14 or 15
for entry in response.json():
if entry["isVirtual"]:
assert entry["showId"] == fallback_show.id
assert entry["showName"] == fallback_show.name
else:
assert entry["showId"] == show.id
assert entry["showName"] == show.name
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