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_yaml_import():
    class MockedV2:
        def import_assets(self, data):
            self._parsed_data = data

    def _dummy_authenticate():
        pass

    yaml_fd = io.StringIO("""
        workflow_job_templates:
          - name: Workflow1
        """)
    cli = CLI(stdin=yaml_fd)
    cli.parse_args(['--conf.format', 'yaml'])
    cli.v2 = MockedV2()
    cli.authenticate = _dummy_authenticate

    Import().handle(cli, None)
    assert cli.v2._parsed_data['workflow_job_templates'][0]['name']
Exemplo n.º 7
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.º 8
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.º 9
0
def test_connection_error(capfd):
    cli = CLI()
    cli.parse_args(['awx'])
    with pytest.raises(ConnectionError):
        cli.connect()