mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 03:45:01 -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:
60
awxkit/test/cli/test_client.py
Normal file
60
awxkit/test/cli/test_client.py
Normal file
@@ -0,0 +1,60 @@
|
||||
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
|
||||
Reference in New Issue
Block a user