From 209f97e829f7795917ebb6492f8239d98fa13478 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Mon, 18 Nov 2024 19:05:50 -0400 Subject: [PATCH] test: add fixtures for rrules and schedules --- conftest.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/conftest.py b/conftest.py index 199f5471..38aa424b 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), ) -- GitLab