示例#1
0
def test_compute_hourly_count_active_0_minutes():
    t1 = Timestamp(2017, 4, 12, 10, 0, 0)
    t2 = Timestamp(2017, 4, 12, 10, 30, 0)
    model = Model(
        StubDataStore(session_events=[(t1, INACTIVE)], desk_events=[]))
    result = model.compute_hourly_count(t1, t2)
    assert result.counts.sum() == 0
示例#2
0
def client(mocker, loop, aiohttp_client):
    time_service = mocker.patch('autodesk.application.timeservice.TimeService',
                                autospec=True)
    time_service.min = Timestamp.min
    time_service.now.return_value = Timestamp(2019, 4, 25, 12, 0)

    model = Model(
        StubDataStore(session_events=SESSION_EVENTS, desk_events=DESK_EVENTS))

    button_pin = NoopPin(4)
    timer = mocker.patch('autodesk.timer.Timer', autospec=True)
    desk_controller = DeskController(0, NoopPin(0), NoopPin(1), NoopPin(3))
    light_controller = LightController(NoopPin(2))
    operation = Operation()
    limits = (Timedelta(minutes=30), Timedelta(minutes=30))
    scheduler = Scheduler(limits)
    session_service = SessionService(model, light_controller, time_service)
    desk_service = DeskService(operation, model, desk_controller, time_service)
    service = AutoDeskService(operation, scheduler, timer, time_service,
                              session_service, desk_service)

    factory = mocker.patch(
        'autodesk.application.autodeskservicefactory.AutoDeskServiceFactory',
        autospec=True)
    factory.create.return_value = service

    return loop.run_until_complete(
        aiohttp_client(api.setup_app(button_pin, factory)))
示例#3
0
def test_get_active_time_active_20_minutes_with_changed_desk_state():
    t1 = Timestamp(2018, 1, 1, 0, 0, 0)
    t2 = Timestamp(2018, 1, 1, 0, 10, 0)
    t3 = Timestamp(2018, 1, 1, 0, 20, 0)
    model = Model(
        StubDataStore(session_events=[(t1, ACTIVE)], desk_events=[(t2, UP)]))
    assert model.get_active_time(Timestamp.min, t3) == Timedelta(minutes=10)
示例#4
0
def test_get_session_spans_empty():
    t1 = Timestamp.min
    t2 = Timestamp.max
    model = Model(StubDataStore.empty())

    result = model.get_session_spans(t1, t2)

    expected = make_spans([(t1, t2, INACTIVE)])
    assert_frame_equal(result, expected)
示例#5
0
def test_get_session_spans_one_active_span():
    t1 = Timestamp(2018, 1, 1)
    t2 = Timestamp(2018, 1, 2)
    t3 = Timestamp(2018, 1, 3)
    model = Model(StubDataStore(session_events=[(t2, ACTIVE)], desk_events=[]))

    result = model.get_session_spans(t1, t3)

    expected = make_spans([(t1, t2, INACTIVE), (t2, t3, ACTIVE)])
    assert_frame_equal(result, expected)
示例#6
0
def test_get_desk_spans_one_up_span():
    t1 = Timestamp(2018, 1, 1)
    t2 = Timestamp(2018, 1, 2)
    t3 = Timestamp(2018, 1, 3)
    model = Model(StubDataStore(session_events=[], desk_events=[(t2, UP)]))

    result = model.get_desk_spans(t1, t3)

    expected = make_spans([(t1, t2, DOWN), (t2, t3, UP)])
    assert_frame_equal(result, expected)
示例#7
0
def test_compute_hourly_count_active_30_minutes():
    t1 = Timestamp(2017, 4, 12, 10, 0, 0)
    t2 = Timestamp(2017, 4, 12, 10, 30, 0)
    model = Model(
        StubDataStore(session_events=[(t1, ACTIVE), (t2, INACTIVE)],
                      desk_events=[]))
    result = model.compute_hourly_count(t1, t2)
    specific_hour = result[(result.weekday == 'Wednesday')
                           & (result.hour == 10)]
    assert specific_hour.counts.iloc[0] == 1
示例#8
0
def test_get_active_time_just_after_desk_change():
    t1 = Timestamp(2018, 1, 1, 0, 0, 0)
    t2 = Timestamp(2018, 1, 1, 0, 10, 0)
    model = Model(
        StubDataStore(session_events=[(t1, ACTIVE)], desk_events=[(t2, UP)]))
    assert model.get_active_time(Timestamp.min, t2) == Timedelta(0)
示例#9
0
def test_get_active_time_active_for_10_minutes():
    t1 = Timestamp(2018, 1, 1, 0, 0, 0)
    t2 = Timestamp(2018, 1, 1, 0, 10, 0)
    model = Model(StubDataStore(session_events=[(t1, ACTIVE)], desk_events=[]))
    assert model.get_active_time(Timestamp.min, t2) == Timedelta(minutes=10)
示例#10
0
def test_get_active_time_active_zero():
    t = Timestamp(2018, 1, 1)
    model = Model(StubDataStore(session_events=[(t, ACTIVE)], desk_events=[]))
    assert model.get_active_time(Timestamp.min, t) == Timedelta(0)
示例#11
0
def test_get_active_time_empty():
    model = Model(StubDataStore.empty())
    assert model.get_active_time(Timestamp.min, Timestamp.max) == Timedelta(0)
示例#12
0
def test_get_desk_state_empty():
    model = Model(StubDataStore.empty())
    assert model.get_desk_state() == DOWN
示例#13
0
def test_get_session_state_empty():
    model = Model(StubDataStore.empty())
    assert model.get_session_state() == INACTIVE