Exemplo n.º 1
0
def test_username_and_password_argv():
    cli = CLI()
    cli.parse_args(
        ['awx', '--conf.username', 'mary', '--conf.password', 'secret'])
    with pytest.raises(ConnectionError):
        cli.connect()

    assert config.credentials.default.username == 'mary'
    assert config.credentials.default.password == 'secret'
Exemplo n.º 2
0
def test_username_and_password_from_environment():
    cli = CLI()
    cli.parse_args(['awx'],
                   env={
                       'TOWER_USERNAME': '******',
                       'TOWER_PASSWORD': '******'
                   })
    with pytest.raises(ConnectionError):
        cli.connect()

    assert config.credentials.default.username == 'mary'
    assert config.credentials.default.password == 'secret'
Exemplo n.º 3
0
def test_config_precedence():
    cli = CLI()
    cli.parse_args(
        ['awx', '--conf.username', 'mary', '--conf.password', 'secret'],
        env={
            'TOWER_USERNAME': '******',
            'TOWER_PASSWORD': '******'
        })
    with pytest.raises(ConnectionError):
        cli.connect()

    assert config.credentials.default.username == 'mary'
    assert config.credentials.default.password == 'secret'
Exemplo n.º 4
0
def test_config_file_precedence():
    """Ignores AWXKIT_CREDENTIAL_FILE if cli args are set"""
    os.makedirs('/tmp/awx-test/', exist_ok=True)
    with open('/tmp/awx-test/config.json', 'w') as f:
        json.dump({'default': {'username': '******', 'password': '******'}}, f)

    cli = CLI()
    cli.parse_args(
        ['awx', '--conf.username', 'mary', '--conf.password', 'secret'],
        env={
            'AWXKIT_CREDENTIAL_FILE': '/tmp/awx-test/config.json',
        },
    )
    with pytest.raises(ConnectionError):
        cli.connect()

    assert config.credentials.default.username == 'mary'
    assert config.credentials.default.password == 'secret'
Exemplo n.º 5
0
def test_config_file():
    """Reads username and password from AWXKIT_CREDENTIAL_FILE."""
    os.makedirs('/tmp/awx-test/', exist_ok=True)
    with open('/tmp/awx-test/config.json', 'w') as f:
        json.dump({'default': {'username': '******', 'password': '******'}}, f)

    cli = CLI()
    cli.parse_args(
        ['awx'],
        env={
            'AWXKIT_CREDENTIAL_FILE': '/tmp/awx-test/config.json',
        },
    )
    with pytest.raises(ConnectionError):
        cli.connect()

    assert config.credentials.default.username == 'mary'
    assert config.credentials.default.password == 'secret'
Exemplo n.º 6
0
def test_host_from_environment():
    cli = CLI()
    cli.parse_args(['awx'], env={'TOWER_HOST': 'https://xyz.local'})
    with pytest.raises(ConnectionError):
        cli.connect()
    assert config.base_url == 'https://xyz.local'
Exemplo n.º 7
0
def test_host_from_argv():
    cli = CLI()
    cli.parse_args(['awx', '--conf.host', 'https://xyz.local'])
    with pytest.raises(ConnectionError):
        cli.connect()
    assert config.base_url == 'https://xyz.local'
Exemplo n.º 8
0
def test_connection_error(capfd):
    cli = CLI()
    cli.parse_args(['awx'])
    with pytest.raises(ConnectionError):
        cli.connect()