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

test: add fixtures for rrules and schedules

parent 18fdb34e
No related branches found
No related tags found
No related merge requests found
from datetime import datetime, timedelta from datetime import date, datetime, time, timedelta
import pytest import pytest
from rest_framework.test import APIClient from rest_framework.test import APIClient
...@@ -184,6 +184,26 @@ def daily_rrule() -> RRule: ...@@ -184,6 +184,26 @@ def daily_rrule() -> RRule:
return RRuleFactory(freq=3) return RRuleFactory(freq=3)
@pytest.fixture
def weekly_rrule() -> RRule:
return RRuleFactory(freq=2)
@pytest.fixture
def business_days_rrule() -> RRule:
return RRuleFactory(freq=2, by_weekdays="0,1,2,3,4")
@pytest.fixture
def weekends_rrule() -> RRule:
return RRuleFactory(freq=2, by_weekdays="5,6")
@pytest.fixture
def monthly_rrule() -> RRule:
return RRuleFactory(freq=1)
@pytest.fixture @pytest.fixture
def show() -> Show: def show() -> Show:
return ShowFactory() return ShowFactory()
...@@ -255,11 +275,94 @@ def once_schedule(once_rrule, show) -> Schedule: ...@@ -255,11 +275,94 @@ def once_schedule(once_rrule, show) -> Schedule:
end = start + timedelta(hours=1) end = start + timedelta(hours=1)
return ScheduleFactory( return ScheduleFactory(
end_time=end.strftime("%H:%M:%S"), end_time=time(end.hour, end.minute, end.second),
first_date=start.strftime("%Y-%m-%d"), first_date=date(start.year, start.month, start.day),
rrule=once_rrule, rrule=once_rrule,
show=show, show=show,
start_time=start.strftime("%H:%M:%S"), start_time=time(start.hour, start.minute, start.second),
)
@pytest.fixture
def daily_schedule(daily_rrule, show) -> Schedule:
start = datetime.now()
end = start + timedelta(hours=1)
last = start + timedelta(days=7)
return ScheduleFactory(
end_time=time(end.hour, end.minute, end.second),
first_date=date(start.year, start.month, start.day),
last_date=date(last.year, last.month, last.day),
rrule=daily_rrule,
show=show,
start_time=time(start.hour, start.minute, start.second),
)
# FIXME: parametrize to avoid repetition
@pytest.fixture
def weekly_schedule(weekly_rrule, show) -> Schedule:
start = datetime.now()
end = start + timedelta(hours=1)
last = start + timedelta(weeks=4)
return ScheduleFactory(
end_time=time(end.hour, end.minute, end.second),
first_date=date(start.year, start.month, start.day),
last_date=date(last.year, last.month, last.day),
rrule=weekly_rrule,
show=show,
start_time=time(start.hour, start.minute, start.second),
)
# FIXME: parametrize to avoid repetition
@pytest.fixture
def business_days_schedule(business_days_rrule, show) -> Schedule:
start = datetime.now()
end = start + timedelta(hours=1)
last = start + timedelta(weeks=4)
return ScheduleFactory(
end_time=time(end.hour, end.minute, end.second),
first_date=date(start.year, start.month, start.day),
last_date=date(last.year, last.month, last.day),
rrule=business_days_rrule,
show=show,
start_time=time(start.hour, start.minute, start.second),
)
# FIXME: parametrize to avoid repetition
@pytest.fixture
def weekends_schedule(weekends_rrule, show) -> Schedule:
start = datetime.now()
end = start + timedelta(hours=1)
last = start + timedelta(weeks=4)
return ScheduleFactory(
end_time=time(end.hour, end.minute, end.second),
first_date=date(start.year, start.month, start.day),
last_date=date(last.year, last.month, last.day),
rrule=weekends_rrule,
show=show,
start_time=time(start.hour, start.minute, start.second),
)
@pytest.fixture
def monthly_schedule(monthly_rrule, show) -> Schedule:
start = datetime.now()
end = start + timedelta(hours=1)
last = start + timedelta(weeks=5)
return ScheduleFactory(
end_time=time(end.hour, end.minute, end.second),
first_date=date(start.year, start.month, start.day),
last_date=date(last.year, last.month, last.day),
rrule=monthly_rrule,
show=show,
start_time=time(start.hour, start.minute, start.second),
) )
......
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