def test_set_desk_down_denied_timer_not_scheduled(mocker, session, now): (timer_mock, _, _, service) = create_service(mocker, now, session, Timedelta(0), UP) service.set_desk(DOWN) timer_mock.schedule.assert_not_called()
def test_set_session_inactive_timer_cancelled(mocker): (timer_mock, _, _, service) = create_service( mocker, TIME_ALLOWED, ACTIVE, Timedelta(0), UP) service.set_session(INACTIVE) timer_mock.cancel.assert_called_once()
def test_init_active_denied_timer_not_scheduled(mocker): (timer_mock, _, _, service) = create_service(mocker, TIME_DENIED, ACTIVE, Timedelta(0), DOWN) service.init() timer_mock.schedule.assert_not_called()
def test_init_inactive_operation_allowed_timer_not_scheduled(mocker): (timer_mock, _, _, service) = create_service(mocker, TIME_ALLOWED, INACTIVE, Timedelta(0), DOWN) service.init() timer_mock.schedule.assert_not_called()
def test_toggle_session_from_active(mocker): (_, session_service_mock, _, service) = create_service( mocker, TIME_ALLOWED, ACTIVE, Timedelta(10), DOWN, limits=(Timedelta(20), Timedelta(30))) service.toggle_session() session_service_mock.set.assert_called_with(INACTIVE)
def test_set_session_active_desk_down_timer_scheduled_right_time(mocker): (timer_mock, _, _, service) = create_service( mocker, TIME_ALLOWED, INACTIVE, Timedelta(10), DOWN, limits=(Timedelta(20), Timedelta(30))) service.set_session(ACTIVE) timer_mock.schedule.assert_called_with(Timedelta(10), mocker.ANY)
def test_set_session_hardware_error_timer_cancelled(mocker): (timer_mock, session_service_stub, _, service) = create_service( mocker, TIME_ALLOWED, INACTIVE, Timedelta(0), DOWN) session_service_stub.set.side_effect = HardwareError(RuntimeError()) service.set_session(ACTIVE) timer_mock.cancel.assert_called_once()
def test_set_session_timer_lambda_called_model_updated(mocker): (timer_stub, _, desk_service_mock, service) = create_service( mocker, TIME_ALLOWED, ACTIVE, Timedelta(0), UP) service.set_session(ACTIVE) timer_stub.schedule.call_args[0][1]() desk_service_mock.set.assert_called_with(DOWN)
def test_set_desk_hardware_error_timer_cancelled(mocker, desk): (timer_mock, _, desk_service_stub, service) = create_service(mocker, TIME_ALLOWED, ACTIVE, Timedelta(0), desk.next()) desk_service_stub.set.side_effect = HardwareError(RuntimeError()) service.set_desk(desk) timer_mock.cancel.assert_called_once()
def test_set_desk_up_allowed_timer_scheduled_right_time(mocker): (timer_mock, _, _, service) = create_service(mocker, TIME_ALLOWED, ACTIVE, Timedelta(10), UP, limits=(Timedelta(20), Timedelta(30))) service.set_desk(UP) timer_mock.schedule.assert_called_with(Timedelta(20), mocker.ANY)
def test_init_active_operation_allowed_timer_scheduled(mocker): (timer_mock, _, _, service) = create_service(mocker, TIME_ALLOWED, ACTIVE, Timedelta(0), DOWN, limits=(Timedelta(10), Timedelta(20))) service.init() timer_mock.schedule.assert_called_with(Timedelta(10), mocker.ANY)