Skip to content

Commit

Permalink
test: add unit test for get workday
Browse files Browse the repository at this point in the history
  • Loading branch information
Will413028 committed Feb 2, 2024
1 parent b3c4bab commit da13416
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions test/test_service.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -11,14 +11,32 @@ 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)


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)
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()

0 comments on commit da13416

Please sign in to comment.