mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Migrate integration.shell.test_cloud
to PyTest
This commit is contained in:
parent
00efe11874
commit
d8facfa16b
5 changed files with 67 additions and 96 deletions
|
@ -117,10 +117,10 @@ salt/client/*:
|
|||
- integration.client.test_standard
|
||||
|
||||
salt/cloud/*:
|
||||
- integration.shell.test_cloud
|
||||
- pytests.functional.cli.test_salt_cloud
|
||||
|
||||
salt/cloud/__init__.py:
|
||||
- integration.cloud.test_cloud
|
||||
- pytests.functional.cli.test_salt_cloud
|
||||
|
||||
salt/grains/*:
|
||||
- integration.grains.test_custom
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
integration.cli_test
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
CLI related unit testing
|
||||
|
||||
:codeauthor: Pedro Algarvio (pedro@algarvio.me)
|
||||
"""
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
# pylint: disable=import-error
|
||||
from salt.ext.six.moves import range # pylint: disable=redefined-builtin
|
||||
from tests.support.case import ShellCase
|
||||
from tests.support.helpers import slowTest
|
||||
from tests.support.mixins import ShellCaseCommonTestsMixin
|
||||
from tests.support.unit import skipIf
|
||||
|
||||
try:
|
||||
import libcloud # pylint: disable=unused-import
|
||||
|
||||
HAS_LIBCLOUD = True
|
||||
except ImportError:
|
||||
HAS_LIBCLOUD = False
|
||||
# pylint: enable=import-error
|
||||
|
||||
|
||||
@skipIf(HAS_LIBCLOUD is False, "salt-cloud requires >= libcloud 0.11.4")
|
||||
class SaltCloudCliTest(ShellCase, ShellCaseCommonTestsMixin):
|
||||
|
||||
_call_binary_ = "salt-cloud"
|
||||
|
||||
@slowTest
|
||||
def test_function_arguments(self):
|
||||
self.assertIn(
|
||||
"error: --function expects two arguments: " "<function-name> <provider>",
|
||||
"\n".join(self.run_cloud("--function show_image -h", catch_stderr=True)[1]),
|
||||
)
|
||||
|
||||
@slowTest
|
||||
def test_list_providers_accepts_no_arguments(self):
|
||||
self.assertIn(
|
||||
"error: '--list-providers' does not accept any " "arguments",
|
||||
"\n".join(self.run_cloud("--list-providers ec2", catch_stderr=True)[1]),
|
||||
)
|
||||
|
||||
@slowTest
|
||||
def test_mutually_exclusive_query_options(self):
|
||||
test_options = ["--query", "--full-query", "--select-query", "--list-providers"]
|
||||
while True:
|
||||
for idx in range(1, len(test_options)):
|
||||
self.assertIn(
|
||||
"error: The options {0}/{1} are mutually "
|
||||
"exclusive. Please only choose one of them".format(
|
||||
test_options[0], test_options[idx]
|
||||
),
|
||||
"\n".join(
|
||||
self.run_cloud(
|
||||
"{0} {1}".format(test_options[0], test_options[idx]),
|
||||
catch_stderr=True,
|
||||
)[1]
|
||||
),
|
||||
)
|
||||
# Remove the first option from the list
|
||||
test_options.pop(0)
|
||||
if len(test_options) <= 1:
|
||||
# Only one left? Stop iterating
|
||||
break
|
||||
|
||||
@slowTest
|
||||
def test_mutually_exclusive_list_options(self):
|
||||
test_options = ["--list-locations", "--list-images", "--list-sizes"]
|
||||
while True:
|
||||
for idx in range(1, len(test_options)):
|
||||
output = self.run_cloud(
|
||||
"{0} ec2 {1} ec2".format(test_options[0], test_options[idx]),
|
||||
catch_stderr=True,
|
||||
)
|
||||
try:
|
||||
self.assertIn(
|
||||
"error: The options {0}/{1} are mutually "
|
||||
"exclusive. Please only choose one of them".format(
|
||||
test_options[0], test_options[idx]
|
||||
),
|
||||
"\n".join(output[1]),
|
||||
)
|
||||
except AssertionError:
|
||||
print(output)
|
||||
raise
|
||||
# Remove the first option from the list
|
||||
test_options.pop(0)
|
||||
if len(test_options) <= 1:
|
||||
# Only one left? Stop iterating
|
||||
break
|
0
tests/pytests/functional/cli/__init__.py
Normal file
0
tests/pytests/functional/cli/__init__.py
Normal file
9
tests/pytests/functional/cli/conftest.py
Normal file
9
tests/pytests/functional/cli/conftest.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def salt_cloud_cli(salt_master_factory):
|
||||
"""
|
||||
The ``salt-cloud`` CLI as a fixture against the running master
|
||||
"""
|
||||
return salt_master_factory.get_salt_cloud_cli()
|
56
tests/pytests/functional/cli/test_salt_cloud.py
Normal file
56
tests/pytests/functional/cli/test_salt_cloud.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
"""
|
||||
tests.pytests.integration.cli.test_salt_cloud
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
"""
|
||||
import pytest
|
||||
|
||||
pytest.importorskip("libcloud", reason="salt-cloud requires >= libcloud 0.11.4")
|
||||
|
||||
|
||||
def test_function_arguments(salt_cloud_cli):
|
||||
ret = salt_cloud_cli.run("--function", "show_image", "-h")
|
||||
assert ret.exitcode != 0
|
||||
assert (
|
||||
"error: --function expects two arguments: <function-name> <provider>"
|
||||
in ret.stderr
|
||||
)
|
||||
|
||||
|
||||
def test_list_providers_accepts_no_arguments(salt_cloud_cli):
|
||||
ret = salt_cloud_cli.run("--list-providers", "ec2")
|
||||
assert ret.exitcode != 0
|
||||
assert "error: '--list-providers' does not accept any arguments" in ret.stderr
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"query_option", ["--query", "--full-query", "--select-query", "--list-providers"]
|
||||
)
|
||||
def test_mutually_exclusive_query_options(salt_cloud_cli, query_option):
|
||||
if query_option != "--query":
|
||||
conflicting_option = "--query"
|
||||
elif query_option != "--full-query":
|
||||
conflicting_option = "--full-query"
|
||||
elif query_option != "--select-query":
|
||||
conflicting_option = "--select-query"
|
||||
elif query_option != "--list-providers":
|
||||
conflicting_option = "--list-providers"
|
||||
|
||||
ret = salt_cloud_cli.run(query_option, conflicting_option)
|
||||
assert ret.exitcode != 0
|
||||
assert "are mutually exclusive. Please only choose one of them" in ret.stderr
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"list_option", ["--list-locations", "--list-images", "--list-sizes"]
|
||||
)
|
||||
def test_mutually_exclusive_list_options(salt_cloud_cli, list_option):
|
||||
if list_option != "--list-locations":
|
||||
conflicting__option = "--list-locations"
|
||||
elif list_option != "--list-images":
|
||||
conflicting__option = "--list-images"
|
||||
elif list_option != "--list-sizes":
|
||||
conflicting__option = "--list-sizes"
|
||||
|
||||
ret = salt_cloud_cli.run(list_option, "ec2", conflicting__option, "ec2")
|
||||
assert ret.exitcode != 0
|
||||
assert "are mutually exclusive. Please only choose one of them" in ret.stderr
|
Loading…
Add table
Reference in a new issue