예제 #1
0
def test_calculate_future_events_7_12_shifts(mocker):
    mocker.patch(
        'oncall.bin.scheduler.get_schedule_last_epoch').return_value = None
    mock_dt = datetime.datetime(year=2016, month=9, day=9, hour=10)
    mocker.patch('time.time').return_value = time.mktime(mock_dt.timetuple())
    start = 3 * DAY + 12 * HOUR  # Wednesday at noon
    events = []
    for i in xrange(7):
        events.append({'start': start + DAY * i, 'duration': 12 * HOUR})
    schedule_foo = {
        'timezone': 'US/Eastern',
        'auto_populate_threshold': 7,
        'events': events
    }
    future_events, last_epoch = scheduler.calculate_future_events(
        schedule_foo, None)
    assert len(future_events) == 2
    assert len(future_events[0]) == 7
    assert len(future_events[1]) == 7
    days = range(14, 22)
    for ev, day in zip(future_events[1], days):
        start_dt = utc.localize(datetime.datetime.utcfromtimestamp(
            ev['start']))
        start_dt = start_dt.astimezone(timezone('US/Eastern'))
        assert start_dt.timetuple().tm_year == mock_dt.timetuple().tm_year
        assert start_dt.timetuple().tm_mon == mock_dt.timetuple().tm_mon
        assert start_dt.timetuple().tm_mday == day
        assert start_dt.timetuple().tm_hour == 12
        assert start_dt.timetuple().tm_min == 00
        assert start_dt.timetuple().tm_sec == 00
예제 #2
0
def test_dst_schedule(mocker):
    mocker.patch(
        'oncall.bin.scheduler.get_schedule_last_epoch').return_value = None
    mock_dt = datetime.datetime(year=2016, month=10, day=29, hour=10)
    mocker.patch('time.time').return_value = time.mktime(mock_dt.timetuple())
    start = DAY + 11 * HOUR  # Monday at 11:00 am
    schedule_foo = {
        'timezone':
        'US/Central',
        'auto_populate_threshold':
        14,
        'events': [{
            'start': start,  # 24hr weeklong shift starting Monday at 11:00 am
            'duration': WEEK
        }]
    }
    future_events, last_epoch = scheduler.calculate_future_events(
        schedule_foo, None)

    assert len(future_events) == 3
    dst_events = future_events[1] + future_events[2]
    assert len(dst_events) == 2
    # Make sure that events are consecutive (no gaps)
    assert dst_events[0]['end'] == dst_events[1]['start']
    for ev in dst_events:
        start_dt = utc.localize(datetime.datetime.utcfromtimestamp(
            ev['start']))
        start_dt = start_dt.astimezone(timezone('US/Central'))
        assert start_dt.timetuple().tm_hour == 11
예제 #3
0
def test_calculate_future_events_7_24_shifts(mocker):
    mocker.patch(
        'oncall.bin.scheduler.get_schedule_last_epoch').return_value = None
    mock_dt = datetime.datetime(year=2017, month=2, day=7, hour=10)
    mocker.patch('time.time').return_value = time.mktime(mock_dt.timetuple())
    start = DAY + 10 * HOUR + 30 * MIN  # Monday at 10:30 am
    schedule_foo = {
        'timezone':
        'US/Pacific',
        'auto_populate_threshold':
        21,
        'events': [{
            'start': start,  # 24hr weeklong shift starting Monday at 10:30 am
            'duration': WEEK
        }]
    }
    future_events, last_epoch = scheduler.calculate_future_events(
        schedule_foo, None)
    assert len(future_events) == 4

    mondays = (6, 13, 20, 27)
    for epoch, monday in zip(future_events, mondays):
        assert len(epoch) == 1
        ev = epoch[0]
        start_dt = utc.localize(datetime.datetime.utcfromtimestamp(
            ev['start']))
        start_dt = start_dt.astimezone(timezone('US/Pacific'))
        assert start_dt.timetuple().tm_year == mock_dt.timetuple().tm_year
        assert start_dt.timetuple().tm_mon == mock_dt.timetuple().tm_mon
        assert start_dt.timetuple().tm_mday == monday
        assert start_dt.timetuple().tm_wday == 0  # Monday
        assert start_dt.timetuple().tm_hour == 10  # 10:
        assert start_dt.timetuple().tm_min == 30  # 30 am
        assert start_dt.timetuple().tm_sec == 00
        assert ev['end'] - ev['start'] == WEEK
예제 #4
0
def test_dst_ambiguous_schedule(mocker):
    mocker.patch(
        'oncall.bin.scheduler.get_schedule_last_epoch').return_value = None
    mock_dt = datetime.datetime(year=2016, month=10, day=29, hour=10)
    mocker.patch('time.time').return_value = time.mktime(mock_dt.timetuple())
    start = HOUR + 30 * MIN  # Sunday at 1:30 am
    schedule_foo = {
        'timezone':
        'US/Central',
        'auto_populate_threshold':
        14,
        'events': [{
            'start': start,  # 24hr weeklong shift starting Sunday at 1:30 am
            'duration': WEEK
        }]
    }
    future_events, last_epoch = scheduler.calculate_future_events(
        schedule_foo, None)

    assert len(future_events) == 3
    dst_events = future_events[1] + future_events[2]
    assert len(dst_events) == 2
    # Make sure that events are consecutive (no gaps)
    assert dst_events[0]['end'] == dst_events[1]['start']