mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 02:47:36 -02:30
import awxkit
Co-authored-by: Christopher Wang <cwang@ansible.com> Co-authored-by: Jake McDermott <jmcdermott@ansible.com> Co-authored-by: Jim Ladd <jladd@redhat.com> Co-authored-by: Elijah DeLee <kdelee@redhat.com> Co-authored-by: Alan Rominger <arominge@redhat.com> Co-authored-by: Yanis Guenane <yanis@guenane.org>
This commit is contained in:
65
awxkit/test/cli/test_config.py
Normal file
65
awxkit/test/cli/test_config.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import pytest
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
from awxkit.cli import CLI
|
||||
from awxkit import config
|
||||
|
||||
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'
|
||||
|
||||
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'
|
||||
|
||||
def test_username_and_password_from_environment():
|
||||
cli = CLI()
|
||||
cli.parse_args(
|
||||
['awx'],
|
||||
env={
|
||||
'TOWER_USERNAME': 'mary',
|
||||
'TOWER_PASSWORD': 'secret'
|
||||
}
|
||||
)
|
||||
with pytest.raises(ConnectionError):
|
||||
cli.connect()
|
||||
|
||||
assert config.credentials.default.username == 'mary'
|
||||
assert config.credentials.default.password == 'secret'
|
||||
|
||||
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'
|
||||
|
||||
def test_config_precedence():
|
||||
cli = CLI()
|
||||
cli.parse_args(
|
||||
[
|
||||
'awx', '--conf.username', 'mary', '--conf.password', 'secret'
|
||||
],
|
||||
env={
|
||||
'TOWER_USERNAME': 'IGNORE',
|
||||
'TOWER_PASSWORD': 'IGNORE'
|
||||
}
|
||||
)
|
||||
with pytest.raises(ConnectionError):
|
||||
cli.connect()
|
||||
|
||||
assert config.credentials.default.username == 'mary'
|
||||
assert config.credentials.default.password == 'secret'
|
||||
Reference in New Issue
Block a user