def test_task_overlap_conflict(): collection_model = TaskCollectionModel() collection_model.import_task_data_from_file( filename='unit_test_inputs/test_overlapping_tasks.json', revert_changes_on_error=False) test_equal(len(collection_model.transient_tasks), 1) test_equal(len(collection_model.recurring_tasks), 1)
def test_add_tasks_to_model(): collection_model = TaskCollectionModel() collection_model.import_task_data_from_file( filename='unit_test_inputs/test_input_file_parse.json', revert_changes_on_error=False) test_equal(len(collection_model.transient_tasks), 1) test_equal(len(collection_model.recurring_tasks), 1) test_equal(len(collection_model.recurring_tasks[0].cancellations), 1) test_equal(collection_model.recurring_tasks[0].generate_recurrence_datetimes(), [ datetime(year=2020, month=1, day=31, hour=10), datetime(year=2020, month=2, day=29, hour=10), ])
def test_recurring_task_instance_generation(): collection_model = TaskCollectionModel() collection_model.import_task_data_from_file( filename='unit_test_inputs/test_recurring_task_instance_generation.json', revert_changes_on_error=False) daily_task = collection_model.recurring_tasks[0] weekly_task = collection_model.recurring_tasks[1] monthly_task = collection_model.recurring_tasks[2] daily_task_0_start = datetime(year=2020, month=1, day=1, hour=00) daily_task_1_start = datetime(year=2020, month=1, day=2, hour=00) weekly_task_0_start = datetime(year=2020, month=2, day=1, hour=00) weekly_task_1_start = datetime(year=2020, month=2, day=8, hour=00) monthly_task_0_start = datetime(year=2020, month=3, day=1, hour=00) monthly_task_1_start = datetime(year=2020, month=4, day=1, hour=00) test_equal(daily_task.generate_recurrence_datetimes(), [ daily_task_0_start, daily_task_1_start ]) test_equal(weekly_task.generate_recurrence_datetimes(), [ weekly_task_0_start, weekly_task_1_start ]) test_equal(monthly_task.generate_recurrence_datetimes(), [ monthly_task_0_start, monthly_task_1_start ]) test_equal(RecurringTaskInstance.generate_instances(daily_task)[0].start, daily_task_0_start) test_equal(RecurringTaskInstance.generate_instances(daily_task)[1].start, daily_task_1_start) test_equal(RecurringTaskInstance.generate_instances(weekly_task)[0].start, weekly_task_0_start) test_equal(RecurringTaskInstance.generate_instances(weekly_task)[1].start, weekly_task_1_start) test_equal(RecurringTaskInstance.generate_instances(monthly_task)[0].start, monthly_task_0_start) test_equal(RecurringTaskInstance.generate_instances(monthly_task)[1].start, monthly_task_1_start)
def test_output_file_write(): collection_model = TaskCollectionModel() collection_model.import_task_data_from_file( filename='unit_test_inputs/test_input_file_parse.json', revert_changes_on_error=False) collection_model.write_task_data_to_file(filename='unit_test_inputs/test_output_file_write.json') with open('unit_test_inputs/test_input_file_parse.json', 'r') as input_file, \ open('unit_test_inputs/test_output_file_write.json', 'r') as output_file: input = json.loads(input_file.read()) output = json.loads(output_file.read()) test_equal(output['tasks'], input['tasks'])
def test_anti_task_removal_protection(): collection_model = TaskCollectionModel() collection_model.import_task_data_from_file( filename='unit_test_inputs/test_anti_task_removal_protection.json', revert_changes_on_error=False) test_equal(len(collection_model.recurring_tasks[0].generate_recurrence_datetimes()), 1) try: anti_task = collection_model.recurring_tasks[0].cancellations[0] collection_model.remove_anti_task(anti_task) except PSSInvalidOperationError: pass test_equal(len(collection_model.transient_tasks), 1) test_equal(len(collection_model.recurring_tasks[0].generate_recurrence_datetimes()), 1) collection_model.remove_task(collection_model.transient_tasks[0]) anti_task = collection_model.recurring_tasks[0].cancellations[0] collection_model.recurring_tasks[0].remove_cancellation(anti_task) test_equal(len(collection_model.transient_tasks), 0) test_equal(len(collection_model.recurring_tasks[0].generate_recurrence_datetimes()), 2)