mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
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>
61 lines
1.3 KiB
Python
61 lines
1.3 KiB
Python
from io import StringIO
|
|
|
|
import pytest
|
|
from requests.exceptions import ConnectionError
|
|
|
|
from awxkit.cli import run, CLI
|
|
|
|
|
|
class MockedCLI(CLI):
|
|
|
|
def fetch_version_root(self):
|
|
pass
|
|
|
|
@property
|
|
def v2(self):
|
|
return MockedCLI()
|
|
|
|
@property
|
|
def json(self):
|
|
return {
|
|
'users': None
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize('help_param', ['-h', '--help'])
|
|
def test_help(capfd, help_param):
|
|
with pytest.raises(SystemExit):
|
|
run(['awx {}'.format(help_param)])
|
|
out, err = capfd.readouterr()
|
|
|
|
assert "usage:" in out
|
|
for snippet in (
|
|
'--conf.host https://example.awx.org]',
|
|
'-v, --verbose'
|
|
):
|
|
assert snippet in out
|
|
|
|
|
|
def test_connection_error(capfd):
|
|
cli = CLI()
|
|
cli.parse_args(['awx'])
|
|
with pytest.raises(ConnectionError):
|
|
cli.connect()
|
|
|
|
|
|
@pytest.mark.parametrize('resource', ['', 'invalid'])
|
|
def test_list_resources(capfd, resource):
|
|
# if a valid resource isn't specified, print --help
|
|
cli = MockedCLI()
|
|
cli.parse_args(['awx {}'.format(resource)])
|
|
cli.connect()
|
|
|
|
cli.parse_resource()
|
|
out, err = capfd.readouterr()
|
|
assert "usage:" in out
|
|
for snippet in (
|
|
'--conf.host https://example.awx.org]',
|
|
'-v, --verbose'
|
|
):
|
|
assert snippet in out
|