コード例 #1
0
def test_register_parameters(mocker, capfd, mock_request, patch_rhn, testcase):
    # successful execution, no output
    mocker.patch.object(basic.AnsibleModule,
                        'run_command',
                        return_value=(0, '', ''))
    mock_is_registered = mocker.patch.object(
        rhn_register.Rhn, 'is_registered',
        mocker.PropertyMock(return_value=testcase['is_registered']))
    mocker.patch.object(rhn_register.Rhn, 'enable')
    mock_systemid = mocker.patch.object(
        rhn_register.Rhn, 'systemid', mocker.PropertyMock(return_value=12345))
    mocker.patch('os.unlink', return_value=True)

    with pytest.raises(SystemExit):
        rhn_register.main()

    assert basic.AnsibleModule.run_command.call_count == testcase[
        'run_command.call_count']
    if basic.AnsibleModule.run_command.call_count:
        assert basic.AnsibleModule.run_command.call_args[0][0][0] == testcase[
            'run_command.call_args']

    assert mock_is_registered.call_count == testcase[
        'is_registered.call_count']
    assert rhn_register.Rhn.enable.call_count == testcase['enable.call_count']
    assert mock_systemid.call_count == testcase['systemid.call_count']
    assert xmlrpc_client.Transport.request.called == testcase['request_called']
    assert os.unlink.call_count == testcase['unlink.call_count']

    out, err = capfd.readouterr()
    results = json.loads(out)
    assert results.get('changed') == testcase.get('changed')
    assert results.get('failed') == testcase.get('failed')
    assert results['msg'] == testcase['msg']
    assert not testcase['calls']  # all calls should have been consumed
コード例 #2
0
def test_register_parameters(mocker, capfd, mock_request, patch_rhn, testcase):
    # successful execution, no output
    mocker.patch.object(basic.AnsibleModule, 'run_command', return_value=(0, '', ''))
    mock_is_registered = mocker.patch.object(rhn_register.Rhn, 'is_registered', mocker.PropertyMock(return_value=testcase['is_registered']))
    mocker.patch.object(rhn_register.Rhn, 'enable')
    mock_systemid = mocker.patch.object(rhn_register.Rhn, 'systemid', mocker.PropertyMock(return_value=12345))
    mocker.patch('os.unlink', return_value=True)

    with pytest.raises(SystemExit):
        rhn_register.main()

    assert basic.AnsibleModule.run_command.call_count == testcase['run_command.call_count']
    if basic.AnsibleModule.run_command.call_count:
        assert basic.AnsibleModule.run_command.call_args[0][0][0] == testcase['run_command.call_args']

    assert mock_is_registered.call_count == testcase['is_registered.call_count']
    assert rhn_register.Rhn.enable.call_count == testcase['enable.call_count']
    assert mock_systemid.call_count == testcase['systemid.call_count']
    assert xmlrpc_client.Transport.request.called == testcase['request_called']
    assert os.unlink.call_count == testcase['unlink.call_count']

    out, err = capfd.readouterr()
    results = json.loads(out)
    assert results.get('changed') == testcase.get('changed')
    assert results.get('failed') == testcase.get('failed')
    assert results['msg'] == testcase['msg']
    assert not testcase['calls']  # all calls should have been consumed
コード例 #3
0
def test_without_required_parameters(capfd, patch_rhn):
    """Failure must occurs when all parameters are missing"""

    with pytest.raises(SystemExit):
        rhn_register.main()
    out, err = capfd.readouterr()
    results = json.loads(out)
    assert results['failed']
    assert 'Missing arguments' in results['msg']
コード例 #4
0
def test_without_required_parameters(capfd, patch_rhn):
    """Failure must occurs when all parameters are missing"""

    with pytest.raises(SystemExit):
        rhn_register.main()
    out, err = capfd.readouterr()
    results = json.loads(out)
    assert results['failed']
    assert 'Missing arguments' in results['msg']
コード例 #5
0
def test_systemid_requirements_missing(capfd, mocker, patch_rhn, import_libxml):
    """Check that missing dependencies are detected"""

    mocker.patch('os.path.isfile', return_value=True)
    mocker.patch('ansible.modules.packaging.os.rhn_register.open', mock_open(read_data=SYSTEMID), create=True)

    with pytest.raises(SystemExit):
        rhn_register.main()

    out, err = capfd.readouterr()
    results = json.loads(out)
    assert results['failed']
    assert 'Missing arguments' in results['msg']