From da13416957e705d09fa587f2a79aca215c5a7511 Mon Sep 17 00:00:00 2001 From: will Date: Fri, 2 Feb 2024 17:48:10 +0800 Subject: [PATCH] test: add unit test for get workday --- test/test_service.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/test/test_service.py b/test/test_service.py index 8358d67..94be308 100644 --- a/test/test_service.py +++ b/test/test_service.py @@ -1,6 +1,6 @@ -from datetime import datetime +from datetime import datetime, timedelta -from service import is_leave_early +from service import is_leave_early, get_workday def test_leave_early(): @@ -11,9 +11,9 @@ def test_leave_early(): def test_just_meet_minimum_hours(): - time_in = datetime(2024, 2, 2, 9) # 早上 9 點上班 + time_in = datetime(2024, 2, 2, 9) minimum_working_hours = 8 - current_time = datetime(2024, 2, 2, 17) # 下午 5 點離開,工作了 8 小時 + current_time = datetime(2024, 2, 2, 17) assert not is_leave_early(time_in, minimum_working_hours, current_time) @@ -21,4 +21,22 @@ def test_work_more_than_minimum_hours(): time_in = datetime(2024, 2, 2, 9) minimum_working_hours = 8 current_time = datetime(2024, 2, 2, 18) - assert not is_leave_early(time_in, minimum_working_hours, current_time) \ No newline at end of file + assert not is_leave_early(time_in, minimum_working_hours, current_time) + + +def test_get_workday_at_cutoff(): + date_time = datetime(2024, 2, 3, 8, 0) + workday_cutoff_str = '08:00' + assert get_workday(date_time, workday_cutoff_str) == datetime(2024, 2, 3).date() + + +def test_get_workday_after_cutoff(): + date_time = datetime(2024, 2, 3, 8, 1) + workday_cutoff_str = '08:00' + assert get_workday(date_time, workday_cutoff_str) == datetime(2024, 2, 3).date() + + +def test_get_workday_before_cutoff(): + date_time = datetime(2024, 2, 3, 7, 59) + workday_cutoff_str = '08:00' + assert get_workday(date_time, workday_cutoff_str) == datetime(2024, 2, 2).date()