diff --git a/conftest.py b/conftest.py index 199f5471250b2108720e00ceb1fd60a52d778ca7..38aa424b9ac33a9ce800b3365e359acc6fbe62bb 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import date, datetime, time, timedelta import pytest from rest_framework.test import APIClient @@ -184,6 +184,26 @@ def daily_rrule() -> RRule: 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 def show() -> Show: return ShowFactory() @@ -255,11 +275,94 @@ def once_schedule(once_rrule, show) -> Schedule: end = start + timedelta(hours=1) return ScheduleFactory( - end_time=end.strftime("%H:%M:%S"), - first_date=start.strftime("%Y-%m-%d"), + end_time=time(end.hour, end.minute, end.second), + first_date=date(start.year, start.month, start.day), rrule=once_rrule, 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), )