def test_calendar_get_free_periods_2(): appointment = Appointment('2020-10-01T10:00:00', '2020-10-01T12:00:00') calendar = Calendar() calendar.add_appointment(appointment) free_periods = calendar.get_free_periods() assert len(free_periods) == 2 assert Period.fromIsoFormat( '2020-10-01T08:00:00', '2020-10-01T10:00:00') in free_periods assert Period.fromIsoFormat( '2020-10-01T12:00:00', '2020-10-01T18:00:00') in free_periods
def test_merge_3(): period1 = Period.fromIsoFormat( '2020-10-01T10:00:00', '2020-10-01T14:00:00') period2 = Period.fromIsoFormat( '2020-10-01T13:00:00', '2020-10-01T18:00:00') merged = merge([period2, period1]) expected_period = Period.fromIsoFormat( '2020-10-01T10:00:00', '2020-10-01T18:00:00') assert len(merged) == 1 assert expected_period in merged
def test_subtract_2(): period = Period.fromIsoFormat('2000-10-01T10:00:00', '2000-10-01T18:00:00') subtract = Period.fromIsoFormat( '2000-10-01T14:00:00', '2000-10-01T15:00:00') subtracted = period.subtract([subtract]) expected_1 = Period.fromIsoFormat( '2000-10-01T10:00:00', '2000-10-01T14:00:00') expected_2 = Period.fromIsoFormat( '2000-10-01T15:00:00', '2000-10-01T18:00:00') assert len(subtracted) == 2 assert expected_1 in subtracted assert expected_2 in subtracted
def test_subtract(): period = Period.fromIsoFormat('2000-10-01T10:00:00', '2000-10-01T14:00:00') subtracted = period.subtract([]) assert len(subtracted) == 1 assert period in subtracted
def test_merge_4(): period1 = Period.fromIsoFormat( '2020-10-01T08:00:00', '2020-10-01T12:00:00') period2 = Period.fromIsoFormat( '2020-10-01T14:00:00', '2020-10-01T15:00:00') period3 = Period.fromIsoFormat( '2020-10-01T12:00:00', '2020-10-01T18:00:00') merged = merge([period2, period3, period1]) expected_1 = Period.fromIsoFormat( '2020-10-01T08:00:00', '2020-10-01T18:00:00') assert len(merged) == 1 assert expected_1 in merged
def test_appointment(): appointment = Appointment('2020-10-01T08:00:00', '2020-10-01T12:00:00') period = appointment.get_period() assert period is not None assert period == Period.fromIsoFormat('2020-10-01T08:00:00', '2020-10-01T12:00:00')
def test_calendar_get_free_periods_for_date_2(): calendar = Calendar() calendar.set_opening_times('THURSDAY', '08:00:00', '18:00:00') appointment1 = Appointment( start='2020-10-01T10:00:00', end='2020-10-01T12:00:00') calendar.add_appointment(appointment1) target_date = date.fromisoformat('2020-10-01') free_periods = calendar.get_free_periods_for_date(target_date) assert len(free_periods) == 2 assert Period.fromIsoFormat( '2020-10-01T08:00:00', '2020-10-01T10:00:00') in free_periods assert Period.fromIsoFormat( '2020-10-01T12:00:00', '2020-10-01T18:00:00') in free_periods
def test_calendar_get_free_periods_3(): appointment1 = Appointment( start='2020-10-01T10:00:00', end='2020-10-01T12:00:00') appointment2 = Appointment( start='2020-10-01T14:00:00', end='2020-10-01T15:00:00') appointment3 = Appointment( start='2020-10-01T14:00:00', end='2020-10-01T18:00:00') calendar = Calendar() calendar.add_appointment(appointment1) calendar.add_appointment(appointment2) calendar.add_appointment(appointment3) free_periods = calendar.get_free_periods() assert len(free_periods) == 2 assert Period.fromIsoFormat( '2020-10-01T08:00:00', '2020-10-01T10:00:00') in free_periods assert Period.fromIsoFormat( '2020-10-01T12:00:00', '2020-10-01T14:00:00') in free_periods
def test_merge_4(): period1 = Period.fromIsoFormat( '2020-10-01T10:00:00', '2020-10-01T14:00:00') period2 = Period.fromIsoFormat( '2020-10-01T13:00:00', '2020-10-01T18:00:00') period3 = Period.fromIsoFormat( '2020-10-01T20:00:00', '2020-10-01T21:00:00') merged = merge([period2, period3, period1]) expected_1 = Period.fromIsoFormat( '2020-10-01T10:00:00', '2020-10-01T18:00:00') expected_2 = Period.fromIsoFormat( '2020-10-01T20:00:00', '2020-10-01T21:00:00') assert len(merged) == 2 assert expected_1 in merged assert expected_2 in merged
def test_calendar_get_free_periods_for_date(): calendar = Calendar() calendar.set_opening_times('THURSDAY', '08:00:00', '18:00:00') target_date = date.fromisoformat('2020-10-01') free_periods = calendar.get_free_periods_for_date(target_date) assert len(free_periods) == 1 assert Period.fromIsoFormat( '2020-10-01T08:00:00', '2020-10-01T18:00:00') in free_periods
def test_subtract_3(): period = Period.fromIsoFormat('2000-10-01T10:00:00', '2000-10-01T22:00:00') subtract_1 = Period.fromIsoFormat( '2000-10-01T14:00:00', '2000-10-01T15:00:00') subtract_2 = Period.fromIsoFormat( '2000-10-01T17:00:00', '2000-10-01T18:00:00') subtracted = period.subtract([subtract_1, subtract_2]) expected_1 = Period.fromIsoFormat( '2000-10-01T10:00:00', '2000-10-01T14:00:00') expected_2 = Period.fromIsoFormat( '2000-10-01T15:00:00', '2000-10-01T17:00:00') expected_3 = Period.fromIsoFormat( '2000-10-01T18:00:00', '2000-10-01T22:00:00') assert len(subtracted) == 3 assert expected_1 in subtracted assert expected_2 in subtracted assert expected_3 in subtracted
def __init__(self, start, end): self.period = Period.fromIsoFormat(start, end)