def main_calendar_action(calendar_id: str) -> Response: GregorianCalendar.setfirstweekday(current_app.config["WEEK_STARTING_DAY"]) current_day, current_month, current_year = GregorianCalendar.current_date() year = int(request.args.get("y", current_year)) year = max(min(year, current_app.config["MAX_YEAR"]), current_app.config["MIN_YEAR"]) month = int(request.args.get("m", current_month)) month = max(min(month, 12), 1) month_name = GregorianCalendar.MONTH_NAMES[month - 1] if current_app.config["HIDE_PAST_TASKS"]: view_past_tasks = False else: view_past_tasks = request.cookies.get("ViewPastTasks", "1") == "1" calendar_data = CalendarData(current_app.config["DATA_FOLDER"], current_app.config["WEEK_STARTING_DAY"]) try: data = calendar_data.load_calendar(calendar_id) except FileNotFoundError: abort(404) tasks = calendar_data.tasks_from_calendar(year, month, data) tasks = calendar_data.add_repetitive_tasks_from_calendar( year, month, data, tasks) if not view_past_tasks: calendar_data.hide_past_tasks(year, month, tasks) if current_app.config[ "WEEK_STARTING_DAY"] == constants.WEEK_START_DAY_MONDAY: weekdays_headers = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"] else: weekdays_headers = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] return cast( Response, render_template( "calendar.html", calendar_id=calendar_id, year=year, month=month, month_name=month_name, current_year=current_year, current_month=current_month, current_day=current_day, month_days=GregorianCalendar.month_days(year, month), previous_month_link=previous_month_link(year, month), next_month_link=next_month_link(year, month), base_url=current_app.config["BASE_URL"], tasks=tasks, display_view_past_button=current_app. config["SHOW_VIEW_PAST_BUTTON"], weekdays_headers=weekdays_headers, ), )
def test_tasks_can_be_filtered_after_retrieval( calendar_data: CalendarData, past_normal_tasks_data: Dict) -> None: year = 2001 tasks = calendar_data.tasks_from_calendar(year, 1, past_normal_tasks_data) assert len(tasks["1"]) > 0 # if we switch to next month, month 1 should become empty calendar_data.hide_past_tasks(year, 2, tasks) assert len(tasks["1"]) == 0
def test_loads_normal_tasks_from_calendar_given_data( calendar_data: CalendarData, sample_data_file_data: Dict) -> None: year = 2017 month = 12 month_str = str(month) tasks = calendar_data.tasks_from_calendar(year, month, sample_data_file_data) assert len(tasks[month_str]) == 1 assert len(tasks[month_str]["25"]) == 2 assert tasks[month_str]["25"][0]["id"] in [0, 1] assert tasks[month_str]["25"][1]["id"] in [0, 1] assert tasks[month_str]["25"][0]["id"] != tasks[month_str]["25"][1]["id"]
def test_hidden_montly_weekday_repetitions_dont_appear( calendar_data: CalendarData) -> None: year = 2017 month = 12 data = calendar_data.load_calendar( "repetitive_monthly_weekday_hidden_task_data_file") tasks = calendar_data.tasks_from_calendar(year=year, month=month, data=data) tasks = calendar_data.add_repetitive_tasks_from_calendar(year=year, month=month, data=data, tasks=tasks) assert str(month) not in tasks
def main_calendar_action(calendar_id: str) -> Response: current_day, current_month, current_year = GregorianCalendar.current_date() year = int(request.args.get("y", current_year)) year = max(min(year, config.MAX_YEAR), config.MIN_YEAR) month = int(request.args.get("m", current_month)) month = max(min(month, 12), 1) month_name = GregorianCalendar.MONTH_NAMES[month - 1] if config.HIDE_PAST_TASKS: view_past_tasks = False else: view_past_tasks = request.cookies.get("ViewPastTasks", "1") == "1" calendar_data = CalendarData(config.DATA_FOLDER) try: data = calendar_data.load_calendar(calendar_id) except FileNotFoundError: abort(404) tasks = calendar_data.tasks_from_calendar(year, month, data) tasks = calendar_data.add_repetitive_tasks_from_calendar( year, month, data, tasks) if not view_past_tasks: calendar_data.hide_past_tasks(year, month, tasks) return cast( Response, render_template("calendar.html", calendar_id=calendar_id, year=year, month=month, month_name=month_name, current_year=current_year, current_month=current_month, current_day=current_day, month_days=GregorianCalendar.month_days(year, month), previous_month_link=previous_month_link(year, month), next_month_link=next_month_link(year, month), base_url=config.BASE_URL, tasks=tasks, display_view_past_button=config.SHOW_VIEW_PAST_BUTTON))
def test_joins_repetitive_tasks_with_normal_ones( calendar_data: CalendarData, sample_data_file_data: Dict) -> None: year = 2017 month = 11 month_str = str(month) tasks = calendar_data.tasks_from_calendar(year, month, sample_data_file_data) assert len(tasks[month_str]) == 1 tasks = calendar_data.add_repetitive_tasks_from_calendar( year, month, sample_data_file_data, tasks) assert len(tasks[month_str]) > 0 # month has 4 mondays repetitive_weekly_weekday_task_ocurrences = 4 # month has 5 thursdays repetitive_weekly_weekday_3_task_ocurrences = 5 repetitive_monthly_weekday_task_ocurrences = 1 repetitive_monthly_monthday_task_ocurrences = 1 # We're counting the number of days with tasks, not the exact number of tasks (day 6 has 2 tasks) assert len( tasks[month_str]) == (repetitive_weekly_weekday_task_ocurrences + repetitive_monthly_weekday_task_ocurrences + repetitive_monthly_monthday_task_ocurrences + repetitive_weekly_weekday_3_task_ocurrences) assert len(tasks[month_str]["6"]) == 2 # Normal task should be first (as repetitive ones are appended afterwards) assert tasks[month_str]["6"][0]["id"] == 4 assert "repetition_value" not in tasks[month_str]["6"][0] assert "repetition_value" in tasks[month_str]["6"][1] assert tasks[month_str]["6"][1]["repetition_value"] == 0 assert tasks[month_str]["6"][1][ "repetition_subtype"] == CalendarData.REPETITION_SUBTYPE_WEEK_DAY assert tasks[month_str]["6"][1][ "repetition_type"] == CalendarData.REPETITION_TYPE_WEEKLY
def test_error_retrieving_tasks_from_calendar( year: int, month: int, data: Dict, calendar_data: CalendarData) -> None: with pytest.raises(ValueError): calendar_data.tasks_from_calendar(year, month, data)