Example #1
0
def test_raises_when_instance_not_created(patched_main, patched_logger_error,
                                          molecule_instance):
    c = check.Check([], dict(), molecule_instance)

    with pytest.raises(SystemExit):
        c.execute()

    msg = ('ERROR: Instance(s) not created, `check` should be run against '
           'created instance(s)')
    patched_logger_error.assert_called_once_with(msg)
Example #2
0
def test_execute_raises_when_instance_not_created(
        patched_check_main, patched_print_error, molecule_instance):
    c = check.Check({}, {}, molecule_instance)

    with pytest.raises(SystemExit):
        c.execute()

    msg = ('Instance(s) not created, `check` should be run against '
           'created instance(s).')
    patched_print_error.assert_called_once_with(msg)
Example #3
0
def test_execute(mocker, patched_logger_info, _patched_ansible_check,
                 patched_config_validate, config_instance):
    c = check.Check(config_instance)
    c.execute()

    x = [
        mocker.call("Scenario: 'default'"),
        mocker.call("Action: 'check'"),
    ]
    assert x == patched_logger_info.mock_calls

    _patched_ansible_check.assert_called_once_with()
Example #4
0
def test_execute_does_not_execute(patched_check_main, patched_ansible_playbook,
                                  molecule_instance):
    molecule_instance.disabled = ['command_check']
    molecule_instance.state.change_state('created', True)
    molecule_instance.state.change_state('converged', True)

    c = check.Check({}, {}, molecule_instance)
    result = c.execute()

    assert not patched_ansible_playbook.called

    assert (None, None) == result
Example #5
0
def test_execute(mocker, patched_logger_info, patched_ansible_check,
                 config_instance):
    c = check.Check(config_instance)
    c.execute()
    x = [
        mocker.call('Scenario: [default]'),
        mocker.call('Provisioner: [ansible]'),
        mocker.call('Dry-Run of Playbook: [playbook.yml]')
    ]

    assert x == patched_logger_info.mock_calls

    patched_ansible_check.assert_called_once_with()
Example #6
0
def test_execute(
    mocker,
    patched_logger_info,
    _patched_ansible_check,
    patched_config_validate,
    config_instance,
):
    c = check.Check(config_instance)
    c.execute()

    assert len(patched_logger_info.mock_calls) == 1
    name, args, kwargs = patched_logger_info.mock_calls[0]
    assert "default" in args
    assert "check" in args
Example #7
0
def test_execute(mocker, patched_main, patched_ansible_playbook,
                 patched_print_info, molecule_instance):
    molecule_instance.state.change_state('created', True)
    molecule_instance.state.change_state('converged', True)
    molecule_instance._driver = mocker.Mock(
        ansible_connection_params={'debug': True})
    patched_ansible_playbook.return_value = 'returned'

    c = check.Check([], dict(), molecule_instance)
    result = c.execute()

    msg = 'Performing a "Dry Run" of playbook ...'
    patched_print_info.assert_called_once_with(msg)
    patched_ansible_playbook.assert_called_once_with(hide_errors=True)
    assert 'returned' == result