mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 02:30:01 -03:30
move code linting to a stricter pep8-esque auto-formatting tool, black
This commit is contained in:
@@ -7,7 +7,6 @@ from awxkit.cli import run, CLI
|
||||
|
||||
|
||||
class MockedCLI(CLI):
|
||||
|
||||
def fetch_version_root(self):
|
||||
pass
|
||||
|
||||
@@ -17,9 +16,7 @@ class MockedCLI(CLI):
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
return {
|
||||
'users': None
|
||||
}
|
||||
return {'users': None}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('help_param', ['-h', '--help'])
|
||||
@@ -29,10 +26,7 @@ def test_help(capfd, help_param):
|
||||
out, err = capfd.readouterr()
|
||||
|
||||
assert "usage:" in out
|
||||
for snippet in (
|
||||
'--conf.host https://example.awx.org]',
|
||||
'-v, --verbose'
|
||||
):
|
||||
for snippet in ('--conf.host https://example.awx.org]', '-v, --verbose'):
|
||||
assert snippet in out
|
||||
|
||||
|
||||
@@ -59,8 +53,5 @@ def test_list_resources(capfd, resource):
|
||||
_, out = capfd.readouterr()
|
||||
|
||||
assert "usage:" in out
|
||||
for snippet in (
|
||||
'--conf.host https://example.awx.org]',
|
||||
'-v, --verbose'
|
||||
):
|
||||
for snippet in ('--conf.host https://example.awx.org]', '-v, --verbose'):
|
||||
assert snippet in out
|
||||
|
||||
@@ -4,16 +4,15 @@ 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'}
|
||||
)
|
||||
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'])
|
||||
@@ -21,43 +20,30 @@ def test_host_from_argv():
|
||||
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'
|
||||
}
|
||||
)
|
||||
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'
|
||||
])
|
||||
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'
|
||||
}
|
||||
)
|
||||
cli.parse_args(['awx', '--conf.username', 'mary', '--conf.password', 'secret'], env={'TOWER_USERNAME': 'IGNORE', 'TOWER_PASSWORD': 'IGNORE'})
|
||||
with pytest.raises(ConnectionError):
|
||||
cli.connect()
|
||||
|
||||
|
||||
@@ -11,19 +11,17 @@ from awxkit.cli.resource import Import
|
||||
|
||||
|
||||
def test_json_empty_list():
|
||||
page = Page.from_json({
|
||||
'results': []
|
||||
})
|
||||
page = Page.from_json({'results': []})
|
||||
formatted = format_response(page)
|
||||
assert json.loads(formatted) == {'results': []}
|
||||
|
||||
|
||||
def test_yaml_empty_list():
|
||||
page = Page.from_json({
|
||||
'results': []
|
||||
})
|
||||
page = Page.from_json({'results': []})
|
||||
formatted = format_response(page, fmt='yaml')
|
||||
assert yaml.safe_load(formatted) == {'results': []}
|
||||
|
||||
|
||||
def test_json_list():
|
||||
users = {
|
||||
'results': [
|
||||
@@ -36,6 +34,7 @@ def test_json_list():
|
||||
formatted = format_response(page)
|
||||
assert json.loads(formatted) == users
|
||||
|
||||
|
||||
def test_yaml_list():
|
||||
users = {
|
||||
'results': [
|
||||
|
||||
@@ -11,13 +11,11 @@ from awxkit.cli.options import ResourceOptionsParser
|
||||
|
||||
|
||||
class ResourceOptionsParser(ResourceOptionsParser):
|
||||
|
||||
def get_allowed_options(self):
|
||||
self.allowed_options = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']
|
||||
|
||||
|
||||
class OptionsPage(Page):
|
||||
|
||||
def options(self):
|
||||
return self
|
||||
|
||||
@@ -33,30 +31,31 @@ class OptionsPage(Page):
|
||||
|
||||
|
||||
class TestOptions(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
_parser = argparse.ArgumentParser()
|
||||
self.parser = _parser.add_subparsers(help='action')
|
||||
|
||||
def test_list(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
ResourceOptionsParser(None, page, 'users', self.parser)
|
||||
assert 'list' in self.parser.choices
|
||||
|
||||
def test_list_filtering(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {
|
||||
'first_name': {'type': 'string'}
|
||||
},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {'first_name': {'type': 'string'}},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
options = ResourceOptionsParser(None, page, 'users', self.parser)
|
||||
options.build_query_arguments('list', 'POST')
|
||||
assert 'list' in self.parser.choices
|
||||
@@ -66,14 +65,14 @@ class TestOptions(unittest.TestCase):
|
||||
assert '--first_name TEXT' in out.getvalue()
|
||||
|
||||
def test_list_not_filterable(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {
|
||||
'middle_name': {'type': 'string', 'filterable': False}
|
||||
},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {'middle_name': {'type': 'string', 'filterable': False}},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
options = ResourceOptionsParser(None, page, 'users', self.parser)
|
||||
options.build_query_arguments('list', 'POST')
|
||||
assert 'list' in self.parser.choices
|
||||
@@ -83,16 +82,18 @@ class TestOptions(unittest.TestCase):
|
||||
assert '--middle_name' not in out.getvalue()
|
||||
|
||||
def test_creation_optional_argument(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'POST': {
|
||||
'first_name': {
|
||||
'type': 'string',
|
||||
'help_text': 'Please specify your first name',
|
||||
}
|
||||
},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'POST': {
|
||||
'first_name': {
|
||||
'type': 'string',
|
||||
'help_text': 'Please specify your first name',
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
options = ResourceOptionsParser(None, page, 'users', self.parser)
|
||||
options.build_query_arguments('create', 'POST')
|
||||
assert 'create' in self.parser.choices
|
||||
@@ -102,17 +103,13 @@ class TestOptions(unittest.TestCase):
|
||||
assert '--first_name TEXT Please specify your first name' in out.getvalue()
|
||||
|
||||
def test_creation_required_argument(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'POST': {
|
||||
'username': {
|
||||
'type': 'string',
|
||||
'help_text': 'Please specify a username',
|
||||
'required': True
|
||||
}
|
||||
},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'POST': {'username': {'type': 'string', 'help_text': 'Please specify a username', 'required': True}},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
options = ResourceOptionsParser(None, page, 'users', self.parser)
|
||||
options.build_query_arguments('create', 'POST')
|
||||
assert 'create' in self.parser.choices
|
||||
@@ -122,13 +119,13 @@ class TestOptions(unittest.TestCase):
|
||||
assert '--username TEXT Please specify a username'
|
||||
|
||||
def test_integer_argument(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'POST': {
|
||||
'max_hosts': {'type': 'integer'}
|
||||
},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'POST': {'max_hosts': {'type': 'integer'}},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
options = ResourceOptionsParser(None, page, 'organizations', self.parser)
|
||||
options.build_query_arguments('create', 'POST')
|
||||
assert 'create' in self.parser.choices
|
||||
@@ -138,13 +135,13 @@ class TestOptions(unittest.TestCase):
|
||||
assert '--max_hosts INTEGER' in out.getvalue()
|
||||
|
||||
def test_boolean_argument(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'POST': {
|
||||
'diff_mode': {'type': 'boolean'}
|
||||
},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'POST': {'diff_mode': {'type': 'boolean'}},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
options = ResourceOptionsParser(None, page, 'users', self.parser)
|
||||
options.build_query_arguments('create', 'POST')
|
||||
assert 'create' in self.parser.choices
|
||||
@@ -154,23 +151,25 @@ class TestOptions(unittest.TestCase):
|
||||
assert '--diff_mode BOOLEAN' in out.getvalue()
|
||||
|
||||
def test_choices(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'POST': {
|
||||
'verbosity': {
|
||||
'type': 'integer',
|
||||
'choices': [
|
||||
(0, '0 (Normal)'),
|
||||
(1, '1 (Verbose)'),
|
||||
(2, '2 (More Verbose)'),
|
||||
(3, '3 (Debug)'),
|
||||
(4, '4 (Connection Debug)'),
|
||||
(5, '5 (WinRM Debug)'),
|
||||
]
|
||||
}
|
||||
},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'POST': {
|
||||
'verbosity': {
|
||||
'type': 'integer',
|
||||
'choices': [
|
||||
(0, '0 (Normal)'),
|
||||
(1, '1 (Verbose)'),
|
||||
(2, '2 (More Verbose)'),
|
||||
(3, '3 (Debug)'),
|
||||
(4, '4 (Connection Debug)'),
|
||||
(5, '5 (WinRM Debug)'),
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
options = ResourceOptionsParser(None, page, 'users', self.parser)
|
||||
options.build_query_arguments('create', 'POST')
|
||||
assert 'create' in self.parser.choices
|
||||
@@ -181,9 +180,7 @@ class TestOptions(unittest.TestCase):
|
||||
|
||||
def test_actions_with_primary_key(self):
|
||||
for method in ('get', 'modify', 'delete'):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {'GET': {}, 'POST': {}}
|
||||
})
|
||||
page = OptionsPage.from_json({'actions': {'GET': {}, 'POST': {}}})
|
||||
ResourceOptionsParser(None, page, 'jobs', self.parser)
|
||||
assert method in self.parser.choices
|
||||
|
||||
@@ -193,19 +190,20 @@ class TestOptions(unittest.TestCase):
|
||||
|
||||
|
||||
class TestSettingsOptions(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
_parser = argparse.ArgumentParser()
|
||||
self.parser = _parser.add_subparsers(help='action')
|
||||
|
||||
def test_list(self):
|
||||
page = OptionsPage.from_json({
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {},
|
||||
'PUT': {},
|
||||
page = OptionsPage.from_json(
|
||||
{
|
||||
'actions': {
|
||||
'GET': {},
|
||||
'POST': {},
|
||||
'PUT': {},
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
page.endpoint = '/settings/all/'
|
||||
ResourceOptionsParser(None, page, 'settings', self.parser)
|
||||
assert 'list' in self.parser.choices
|
||||
|
||||
Reference in New Issue
Block a user