def test_remove_scheduling_systemd_not_found(run_command_get_output):
    schedule = sched.InsightsSchedulerSystemd()
    run_command_get_output.reset_mock()

    unscheduled = schedule.remove_scheduling()
    assert unscheduled == {}
    run_command_get_output.assert_not_called()
def test_active_systemd_active(run_command_get_output, outputs):
    run_command_get_output.side_effect = ({
        "status": 0,
        "output": output
    } for output in outputs)
    schedule = sched.InsightsSchedulerSystemd()
    assert schedule.active is True
def test_remove_scheduling_systemd_init_error(run_command_get_output):
    schedule = sched.InsightsSchedulerSystemd()
    run_command_get_output.reset_mock()

    unscheduled = schedule.remove_scheduling()
    assert unscheduled is None
    run_command_get_output.assert_not_called()
def test_schedule_systemd_not_found(run_command_get_output):
    schedule = sched.InsightsSchedulerSystemd()
    run_command_get_output.reset_mock()

    scheduled = schedule.schedule()
    assert scheduled == {}
    run_command_get_output.assert_not_called()
def test_schedule_systemd_success(run_command_get_output, outputs):
    run_command_get_output.side_effect = ({
        "status": 0,
        "output": output
    } for output in outputs)
    schedule = sched.InsightsSchedulerSystemd()
    scheduled = schedule.schedule()
    assert scheduled is True
def test_init_calls(run_command_get_output):
    sched.InsightsSchedulerSystemd()
    calls = (
        call("systemctl show --property LoadState insights-client.timer"),
        call(
            "systemctl show --property LoadState insights-client-checkin.timer"
        ),
    )
    run_command_get_output.assert_has_calls(calls)
def test_init_systemd_loaded_timers(run_command_get_output, load_states,
                                    loaded_timers):
    run_command_get_output.side_effect = ({
        "status":
        0,
        "output":
        "LoadState=%s\n" % load_state
    } for load_state in load_states)
    scheduler = sched.InsightsSchedulerSystemd()
    assert scheduler.loaded_timers == loaded_timers
def test_active_systemd_calls(run_command_get_output, outputs, calls):
    run_command_get_output.side_effect = ({
        "status": 0,
        "output": output
    } for output in outputs)

    schedule = sched.InsightsSchedulerSystemd()
    run_command_get_output.reset_mock()
    schedule.active

    run_command_get_output.assert_has_calls(calls)
def test_init_systemd_error(run_command_get_output, side_effect):
    run_command_get_output.side_effect = side_effect
    scheduler = sched.InsightsSchedulerSystemd()
    assert scheduler.loaded_timers is None
def test_active_systemd_init_error(run_command_get_output):
    schedule = sched.InsightsSchedulerSystemd()
    run_command_get_output.reset_mock()

    assert schedule.active is None
    run_command_get_output.assert_not_called()
def test_active_systemd_error(run_command_get_output, side_effect):
    run_command_get_output.side_effect = side_effect
    schedule = sched.InsightsSchedulerSystemd()
    assert schedule.active is None
def test_remove_scheduling_systemd_error(run_command_get_output, side_effect):
    run_command_get_output.side_effect = side_effect

    schedule = sched.InsightsSchedulerSystemd()
    unscheduled = schedule.remove_scheduling()
    assert unscheduled is None
def test_schedule_systemd_call_error(run_command_get_output, side_effect):
    run_command_get_output.side_effect = side_effect

    schedule = sched.InsightsSchedulerSystemd()
    scheduled = schedule.schedule()
    assert scheduled is None
def test_schedule_systemd_inactive(run_command_get_output, side_effect):
    run_command_get_output.side_effect = side_effect

    schedule = sched.InsightsSchedulerSystemd()
    scheduled = schedule.schedule()
    assert scheduled is False