Ejemplo n.º 1
0
def test_delete_task_full():
    """
    Test deleting task from a full schedule.
    """

    # Construct session. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules(
    )[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())
    planned = True
    day = 5
    task_index = 0

    # Store pre-delete session values.
    pre_history_pos = session.history_pos
    pre_edit_history = list(session.edit_history)
    original_task = session.get_task(planned=planned,
                                     day=day,
                                     task_index=task_index)

    # Delete task.
    session.delete_task(planned=planned, day=day, task_index=task_index)

    # Test session values.
    assert session.history_pos == pre_history_pos + 1
    assert len(session.edit_history) == len(pre_edit_history) + 1
    assert session.edit_history[:-1] == pre_edit_history
    assert pre_edit_history[-1][0].tasks[2] == original_task
    assert session.edit_history[-1][0].tasks == list_exclude(
        pre_edit_history[-1][0].tasks, 2)
    assert session.edit_history[-1][1] == pre_edit_history[-1][1]
Ejemplo n.º 2
0
def test_redo_filled():
    """
    Test redoing an action on a filled out planned schedule.
    """

    # Set up case. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules(
    )[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())

    # Store pre-edit values.
    old_history_pos = session.history_pos
    old_history_len = len(session.edit_history)
    old_planned, old_actual = session.current_schedules()

    # Undo then redo last action.
    session.undo()
    session.redo()

    # Test session values.
    new_planned, new_actual = session.current_schedules()
    assert session.history_pos == old_history_pos
    assert old_planned == new_planned
    assert old_actual == new_actual
    assert len(session.edit_history) == old_history_len
Ejemplo n.º 3
0
def test_edit_task_time_invalid():
    """
    Edit the time of a single task in an invalid way, i.e. it interferes with other
    tasks.
    """

    # Set up case. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules()[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())
    planned = True
    day = 4
    task_index = 0
    new_values = {
        "start_time": datetime(2020, 5, 1, hour=13),
        "end_time": datetime(2020, 5, 1, hour=14),
    }

    # Edit task in a way that creates overlap, i.e. should throw an error.
    error = False
    try:
        session.edit_task(
            planned=planned, day=day, task_index=task_index, new_values=new_values,
        )
    except:
        error = True

    # Ensure error was thrown.
    assert error
Ejemplo n.º 4
0
def test_delete_task_single_actual():
    """
    Test deleting task from a schedule with only one task in actual.
    """

    # Construct session. Note that we have to manually set the base date of the session
    # in order to access the task, since it has a hard-coded date.
    session = Session("test")
    session.insert_task(
        day=4,
        planned=False,
        name="test",
        priority=1.0,
        start_time=time(hour=12),
        hours=1.5,
    )
    session.base_date = session.current_schedules(
    )[1].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())

    # Delete the task.
    session.delete_task(planned=False, day=4, task_index=0)

    # Test session values.
    assert session.history_pos == 2
    assert len(session.edit_history) == 3
    assert len(session.edit_history[0][0].tasks) == 0
    assert len(session.edit_history[0][1].tasks) == 0
    assert len(session.edit_history[1][0].tasks) == 0
    assert len(session.edit_history[1][1].tasks) == 1
    assert len(session.edit_history[2][0].tasks) == 0
    assert len(session.edit_history[2][1].tasks) == 0
Ejemplo n.º 5
0
def test_undo_filled_planned():
    """
    Test undoing an edit task action on a filled out planned schedule.
    """

    # Set up case. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules(
    )[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())
    planned = True
    day = 4
    task_index = 0
    new_values = {"name": "new_name"}

    # Store pre-edit values.
    old_history_pos = session.history_pos
    old_planned, old_actual = session.current_schedules()

    # Edit task, then undo.
    session.edit_task(
        planned=planned,
        day=day,
        task_index=task_index,
        new_values=new_values,
    )
    session.undo()

    # Test session values.
    new_planned, new_actual = session.current_schedules()
    assert session.history_pos == old_history_pos
    assert old_planned == new_planned
    assert old_actual == new_actual
Ejemplo n.º 6
0
def test_edit_task_time_valid():
    """
    Edit the time of a single task in a valid way, i.e. it doesn't interfere with other
    tasks.
    """

    # Set up case. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules()[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())
    planned = True
    day = 4
    task_index = 0
    new_values = {"start_time": datetime(2020, 5, 1, hour=13)}

    # Store pre-insert session values.
    pre_history_pos = session.history_pos
    pre_edit_history = list(session.edit_history)
    original_task = session.get_task(planned=planned, day=day, task_index=task_index)
    new_task = deepcopy(original_task)
    new_task.start_time = new_values["start_time"]

    # Edit task.
    session.edit_task(
        planned=planned, day=day, task_index=task_index, new_values=new_values,
    )

    # Test session values.
    assert session.history_pos == pre_history_pos + 1
    assert len(session.edit_history) == len(pre_edit_history) + 1
    assert session.edit_history[:-1] == pre_edit_history
    assert pre_edit_history[-1][0].tasks[0] == original_task
    assert session.edit_history[-1][0].tasks[0] == new_task
    assert session.edit_history[-1][1] == pre_edit_history[-1][1]
Ejemplo n.º 7
0
def test_move_tasks_invalid():
    """
    Test moving tasks in an invalid way.
    """

    # Construct session. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules(
    )[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())
    planned = True
    day = 4
    start_task_index = 0
    end_task_index = 1

    # Move task into invalid time slot.
    error = False
    try:
        session.move_tasks(
            planned=planned,
            day=day,
            start_task_index=start_task_index,
            end_task_index=end_task_index,
            time_delta=timedelta(hours=2),
        )
    except:
        error = True

    # Ensure that error was thrown.
    assert error
Ejemplo n.º 8
0
def test_move_week_backward():
    """
    Test moving the displayed week backward.
    """

    # Construct session. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules()[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())

    # Move the week forward.
    session.move_week(forward=False)

    # Test week value.
    assert session.base_date == date(2020, 4, 20)
Ejemplo n.º 9
0
def test_move_tasks_full():
    """
    Test moving multiple tasks in a full schedule.
    """

    # Construct session. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules(
    )[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())
    planned = True
    day = 4
    start_task_index = 0
    end_task_index = 2

    # Store pre-move session values.
    pre_history_pos = session.history_pos
    pre_edit_history = list(session.edit_history)
    original_tasks = [
        session.get_task(planned=planned, day=day, task_index=i)
        for i in range(start_task_index, end_task_index)
    ]

    # Move tasks.
    session.move_tasks(
        planned=planned,
        day=day,
        start_task_index=start_task_index,
        end_task_index=end_task_index,
        time_delta=timedelta(hours=2),
    )

    # Test session values.
    edited_tasks = [deepcopy(task) for task in original_tasks]
    edited_tasks[0].start_time = datetime(2020, 5, 1, hour=14)
    edited_tasks[0].end_time = datetime(2020, 5, 1, hour=15, minute=30)
    edited_tasks[1].start_time = datetime(2020, 5, 1, hour=15, minute=30)
    edited_tasks[1].end_time = datetime(2020, 5, 1, hour=16, minute=30)
    assert session.history_pos == pre_history_pos + 1
    assert len(session.edit_history) == len(pre_edit_history) + 1
    assert session.edit_history[:-1] == pre_edit_history
    assert pre_edit_history[-1][0].tasks[0:2] == original_tasks
    assert session.edit_history[-1][0].tasks[0:2] == edited_tasks
    assert session.edit_history[-1][0].tasks[2:] == pre_edit_history[-1][
        0].tasks[2:]
    assert session.edit_history[-1][1] == pre_edit_history[-1][1]
Ejemplo n.º 10
0
def test_move_tasks_single_planned():
    """
    Test moving a single task from a planned schedule with only a single task.
    """

    # Construct session. Note that we have to manually set the base date of the session
    # in order to access the task, since it has a hard-coded date.
    session = Session("test")
    session.insert_task(
        day=4,
        planned=True,
        name="test",
        priority=1.0,
        start_time=time(hour=12),
        hours=1.5,
    )
    session.base_date = session.current_schedules(
    )[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())

    # Move the task.
    session.move_tasks(
        planned=True,
        day=4,
        start_task_index=0,
        end_task_index=1,
        time_delta=timedelta(hours=2),
    )

    # Test session values.
    assert session.history_pos == 2
    assert len(session.edit_history) == 3
    assert len(session.edit_history[0][0].tasks) == 0
    assert len(session.edit_history[0][1].tasks) == 0
    assert len(session.edit_history[1][0].tasks) == 1
    assert len(session.edit_history[1][1].tasks) == 0
    assert len(session.edit_history[2][0].tasks) == 1
    assert len(session.edit_history[2][1].tasks) == 0
    task = session.edit_history[2][0].tasks[0]
    assert task.name == "test"
    assert task.priority == 1.0
    assert task.start_time.date() == session.base_date + timedelta(days=4)
    assert task.start_time.time() == time(hour=14)
    assert task.end_time.date() == session.base_date + timedelta(days=4)
    assert task.end_time.time() == time(hour=15, minute=30)
Ejemplo n.º 11
0
def test_delete_task_invalid():
    """
    Test deleting a nonexistent task from a full schedule.
    """

    # Construct session. Note that we have to manually set the base date of the session in
    # order to access the task, since it has a hard-coded date.
    session = Session("example", load=True)
    session.base_date = session.current_schedules(
    )[0].tasks[0].start_time.date()
    session.base_date -= timedelta(days=session.base_date.weekday())
    planned = True
    day = 6
    task_index = 1

    # Delete nonexistent task.
    error = False
    try:
        session.delete_task(planned=planned, day=day, task_index=task_index)
    except:
        error = True

    # Ensure that error was thrown.
    assert error