예제 #1
0
def test_elite_run_action_failed(monkeypatch, printer):
    helpers.patch_root_runtime(monkeypatch)

    class MyAction(Action):
        def process(self):
            raise ActionError('oh no')

    elite = Elite(printer)
    elite.register_action('my_action', MyAction)
    with pytest.raises(EliteError):
        elite.my_action()
예제 #2
0
def test_elite_run_action_changed(monkeypatch, printer):
    helpers.patch_root_runtime(monkeypatch)

    class MyAction(Action):
        def process(self):
            return self.changed()

    elite = Elite(printer)
    elite.register_action('my_action', MyAction)
    assert elite.my_action() == EliteResponse(changed=True, ok=True)
예제 #3
0
def test_elite_options_ignore_failed(monkeypatch, printer):
    helpers.patch_root_runtime(monkeypatch)

    class MyAction(Action):
        def process(self):
            raise ActionError('oh no')

    elite = Elite(printer)
    elite.register_action('my_action', MyAction)
    with elite.options(ignore_failed=True):
        assert elite.my_action() == EliteResponse(changed=False,
                                                  ok=False,
                                                  failed_message='oh no')
예제 #4
0
def test_elite_options_env(monkeypatch, printer):
    helpers.patch_root_runtime(monkeypatch)

    class MyAction(Action):
        def process(self):
            return self.ok(favourite_animal=os.environ['FAVOURITE_ANIMAL'],
                           enjoy_mooing=bool(os.environ['ENJOY_MOOING']))

    elite = Elite(printer)
    elite.register_action('my_action', MyAction)
    with elite.options(env={'FAVOURITE_ANIMAL': 'cows', 'ENJOY_MOOING': '1'}):
        assert elite.my_action() == EliteResponse(changed=False,
                                                  ok=True,
                                                  data={
                                                      'favourite_animal':
                                                      'cows',
                                                      'enjoy_mooing': True
                                                  })
예제 #5
0
def test_elite_options_sudo(seteuid_mock, setegid_mock, demote_mock,
                            monkeypatch, printer):
    helpers.patch_root_runtime(monkeypatch)

    class MyAction(Action):
        def process(self):
            return self.ok()

    elite = Elite(printer)
    elite.register_action('my_action', MyAction)
    with elite.options(sudo=True):
        assert elite.my_action() == EliteResponse(changed=False, ok=True)

    assert seteuid_mock.call_args_list == [
        mock.call(501), mock.call(0),
        mock.call(501)
    ]
    assert setegid_mock.call_args_list == [
        mock.call(20), mock.call(0),
        mock.call(20)
    ]
    assert demote_mock.call_args == mock.call(0, 0)
예제 #6
0
def test_elite_run_action_inexistent(monkeypatch, printer):
    helpers.patch_root_runtime(monkeypatch)

    elite = Elite(printer)
    with pytest.raises(AttributeError):
        elite.my_action()