Ejemplo n.º 1
0
def test_stop_no_arguments() -> None:
    main.DATAFILE = "2020-09-timesheet.json"
    with freeze_time("2020-09-26 08:07"):  # A Saturday
        handle_command("start 08:00")
        handle_command("stop")

        assert load_timesheet().today.last_work_block.stop == "08:07:00"
Ejemplo n.º 2
0
def test_timeoff_more_than_a_workday() -> None:
    main.DATAFILE = "2021-04-timesheet.json"
    with freeze_time("2021-04-02"):  # A Friday
        with pytest.raises(
            ValueError,
            match="Invalid timeoff value, must be an int between 0 and 8 inclusive.",
        ):
            handle_command("timeoff 9")
Ejemplo n.º 3
0
def test_timeoff_full_day() -> None:
    main.DATAFILE = "2021-04-timesheet.json"
    with freeze_time("2021-04-02"):  # A Friday
        handle_command("timeoff 8")

        ts = load_timesheet()
        assert ts.today.time_off_minutes == 8 * 60
        assert ts.today.flex_minutes == 0
Ejemplo n.º 4
0
def test_flextime_correct_during_weekend() -> None:
    main.DATAFILE = "2020-09-timesheet.json"
    with freeze_time("2020-09-26"):  # A Saturday
        handle_command("start 08:00")
        handle_command("stop 09:02")

        assert load_timesheet().today.flex_minutes == 62
        assert calc_total_flex() == 62
Ejemplo n.º 5
0
def test_flex_for_today_output_is_wrong(capsys) -> None:
    with freeze_time("2020-09-22"):  # A Tuesday
        handle_command("start 08:12")
        handle_command("stop 16:05")
        captured = capsys.readouterr()
        assert "Flex for today is negative: 0 hours 7 mins" in captured.out

        ts = load_timesheet()
        assert ts.today.flex_minutes == -7
Ejemplo n.º 6
0
def test_workblock_that_is_already_started_cannot_be_started_again(capsys) -> None:
    handle_command("start 08:00")
    ts = load_timesheet()

    handle_command("start 08:01")

    assert ts == load_timesheet()
    assert len(ts.today.work_blocks) == 1
    captured = capsys.readouterr()
    assert (
        "Workblock already started, stop it before starting another one" in captured.out
    )
Ejemplo n.º 7
0
def test_view_today_with_workblock_not_ended(capsys) -> None:
    main.DATAFILE = "2020-11-timesheet.json"
    with freeze_time("2020-11-24"):  # A Tuesday
        handle_command("start 08:02")
        capsys.readouterr()

        handle_command("view")  # Act
    captured = capsys.readouterr()

    expected = [
        "2020-11-24 | lunch: 0min | daily flex: 0min",
        "  08:02-",
    ]
    assert "\n".join(expected) in captured.out
Ejemplo n.º 8
0
def test_running_stop_twice_will_not_overwrite_last_stop() -> None:
    handle_command("start 08:01")
    handle_command("stop 08:03")
    assert load_timesheet().today.last_work_block.stop == "08:03:00"

    handle_command("stop 08:05")
    assert load_timesheet().today.last_work_block.stop == "08:03:00"
Ejemplo n.º 9
0
def test_two_workblocks_20_min_lunch_estimated_endtime_is_wrong(capsys) -> None:
    with freeze_time("2020-11-20"):  # A Friday
        handle_command("start 07:45")
        handle_command("lunch 20")
        handle_command("stop 13:54")  # 5h 49 min -> -2h 11 min flex
        captured = capsys.readouterr()
        assert "Flex for today is negative: 2 hours 11 mins" in captured.out
        ts = load_timesheet()
        assert ts.today.flex_minutes == -(2 * 60 + 11)

        # workblock #2
        handle_command("start 15:00")
        handle_command("stop 17:00")
        captured = capsys.readouterr()

        # This assert asserts the testcase
        assert (
            "Estimated end time for today with 20 min lunch is 17:11:00" in captured.out
        )
        assert "Flex for today is negative: 0 hours 11 mins" in captured.out
        ts = load_timesheet()
        assert ts.today.flex_minutes == -11
Ejemplo n.º 10
0
def test_lunch_fails_if_day_is_not_started(capsys) -> None:
    handle_command("lunch")
    assert load_timesheet().today.lunch == 0
    captured = capsys.readouterr()
    assert "Could not find today in timesheet, did you start the day?" in captured.out

    handle_command("start")
    handle_command("lunch")
    assert load_timesheet().today.lunch == 30
Ejemplo n.º 11
0
def test_timeoff_half_day() -> None:
    main.DATAFILE = "2021-04-timesheet.json"
    with freeze_time("2021-04-02"):  # A Friday
        handle_command("timeoff 4")
        handle_command("start 08:00")
        handle_command("stop 12:02")

        ts = load_timesheet()
        assert ts.today.time_off_minutes == 4 * 60
        assert ts.today.flex_minutes == 2
Ejemplo n.º 12
0
def test_stop_fails_if_last_workblock_is_not_started(capsys) -> None:
    handle_command("stop")
    assert not load_timesheet().today.last_work_block.stopped()
    captured = capsys.readouterr()
    assert "Could not stop workblock, is your last workblock started?" in captured.out

    handle_command("start 08:05")
    handle_command("stop 08:10")
    assert load_timesheet().today.last_work_block.stop == "08:10:00"
    assert load_timesheet().today.last_work_block.stopped()
Ejemplo n.º 13
0
def test_flex(capsys, stop_time, flex) -> None:
    with freeze_time("2020-09-23"):  # A Wednesday
        handle_command("start 08:00")
        handle_command("lunch")
        handle_command("stop " + stop_time)

        ts = load_timesheet()
        assert ts.today.flex_minutes == flex

        captured = capsys.readouterr()
        assert (
            "Estimated end time for today with 30 min lunch is 16:30:00" in captured.out
        )
Ejemplo n.º 14
0
def test_multiple_start_and_end(capsys) -> None:
    with freeze_time("2020-09-25"):  # A Friday
        # Working 30 min first section
        handle_command("start 08:30")
        captured = capsys.readouterr()
        assert (
            "Estimated end time for today with 30 min lunch is 17:00:00" in captured.out
        )
        handle_command("stop 09:00")
        ts = load_timesheet()
        assert ts.today.flex_minutes == -7 * 60 - 30  # Should have -7h 30m as flex

        # Working 1h 30 min more
        handle_command("start 10:30")
        captured = capsys.readouterr()
        assert (
            "Estimated end time for today with 30 min lunch is 18:30:00" in captured.out
        )
        handle_command("stop 12:00")
        ts = load_timesheet()
        assert ts.today.flex_minutes == -6 * 60  # Should have -6h as flex

        # Filling up to the 8 hours
        handle_command("start 13:00")
        captured = capsys.readouterr()
        assert (
            "Estimated end time for today with 30 min lunch is 19:30:00" in captured.out
        )
        handle_command("stop 19:00")
        ts = load_timesheet()
        assert ts.today.flex_minutes == 0  # Should have 0 min as flex

        # Working a few more minutes
        handle_command("start 19:30")
        captured = capsys.readouterr()
        assert (
            "Estimated end time for today with 30 min lunch is 20:00:00" in captured.out
        )
        handle_command("stop 19:35")
        ts = load_timesheet()
        assert ts.today.flex_minutes == 5  # Should have 5 min as flex
Ejemplo n.º 15
0
def test_view_today(capsys) -> None:
    main.DATAFILE = "2020-11-timesheet.json"
    with freeze_time("2020-11-24"):  # A Tuesday
        handle_command("start 08:02")
        handle_command("lunch 25")
        handle_command("stop 14:21")
        handle_command("start 15:01")
        handle_command("stop 17:27")
        capsys.readouterr()

        handle_command("view")  # Act
    captured = capsys.readouterr()

    expected = [
        "2020-11-24 | lunch: 25min | daily flex: 20min",
        "  08:02-14:21 => 6h 19min",
        "  15:01-17:27 => 2h 26min",
    ]
    assert "\n".join(expected) in captured.out
Ejemplo n.º 16
0
def test_running_lunch_twice_will_not_overwrite_first_lunch() -> None:
    handle_command("start")
    handle_command("lunch")
    assert load_timesheet().today.lunch == 30
    handle_command("lunch 25")
    assert load_timesheet().today.lunch == 30