mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
MANUALLY STARTING A PATCHER AND NOT STOPPING IT HAS CONSEQUENCES FOR THE WHOLE TEST RUN
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
ac34089d5d
commit
7a59410c2d
8 changed files with 151 additions and 576 deletions
|
@ -1,9 +1,7 @@
|
|||
"""
|
||||
Tests for the spm install utility
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -30,6 +28,7 @@ class SPMInstallTest(SPMCase):
|
|||
self.webserver = Webserver()
|
||||
self.webserver.root = self.spm_build_dir
|
||||
self.webserver.start()
|
||||
self.addCleanup(self.webserver.stop)
|
||||
self.repo_dir = self.config["spm_repos_config"] + ".d"
|
||||
self.repo = os.path.join(self.repo_dir, "spm.repo")
|
||||
url = {"my_repo": {"url": self.webserver.url("")[:-1]}}
|
||||
|
@ -84,8 +83,3 @@ class SPMInstallTest(SPMCase):
|
|||
sls = os.path.join(self.config["formula_path"], "apache", "apache.sls")
|
||||
|
||||
self.assertTrue(os.path.exists(sls))
|
||||
|
||||
def tearDown(self):
|
||||
if "http" in self.id():
|
||||
self.webserver.stop()
|
||||
shutil.rmtree(self._tmp_spm)
|
||||
|
|
|
@ -56,9 +56,8 @@ class Mockwinapi:
|
|||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
mock_pythoncom = types.ModuleType(salt.utils.stringutils.to_str("pythoncom"))
|
||||
sys_modules_patcher = patch.dict("sys.modules", {"pythoncom": mock_pythoncom})
|
||||
sys_modules_patcher.start()
|
||||
return {win_dns_client: {"wmi": wmi}}
|
||||
with patch.dict("sys.modules", {"pythoncom": mock_pythoncom}):
|
||||
yield {win_dns_client: {"wmi": wmi}}
|
||||
|
||||
|
||||
def test_get_dns_servers():
|
||||
|
|
|
@ -56,8 +56,17 @@ class GlobalConfig:
|
|||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session_instance():
|
||||
with patch("boto3.session.Session") as patched_session:
|
||||
yield patched_session()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def global_config():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
params = GlobalConfig()
|
||||
return params
|
||||
|
||||
|
@ -94,17 +103,10 @@ def configure_loader_modules(minion_opts):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_trail_does_not_exist(global_config):
|
||||
def test_present_when_trail_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests present on a trail that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -129,14 +131,7 @@ def test_present_when_trail_does_not_exist(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_trail_exists(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_trail_exists(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -158,14 +153,7 @@ def test_present_when_trail_exists(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_with_failure(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_with_failure(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -190,17 +178,10 @@ def test_present_with_failure(global_config):
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_trail_does_not_exist(global_config):
|
||||
def test_absent_when_trail_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on a trail that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -210,14 +191,7 @@ def test_absent_when_trail_does_not_exist(global_config):
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_trail_exists(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_trail_exists(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -229,14 +203,7 @@ def test_absent_when_trail_exists(global_config):
|
|||
assert result["changes"]["new"]["trail"] is None
|
||||
|
||||
|
||||
def test_absent_with_failure(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_failure(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
|
|
@ -44,8 +44,17 @@ class GlobalConfig:
|
|||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session_instance():
|
||||
with patch("boto3.session.Session") as patched_session:
|
||||
yield patched_session()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def global_config():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
params = GlobalConfig()
|
||||
return params
|
||||
|
||||
|
@ -81,16 +90,10 @@ def configure_loader_modules(minion_opts):
|
|||
}
|
||||
|
||||
|
||||
def test_present_when_failing_to_describe_rule(global_config):
|
||||
def test_present_when_failing_to_describe_rule(global_config, session_instance):
|
||||
"""
|
||||
Tests exceptions when checking rule existence
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.side_effect = botocore.exceptions.ClientError(
|
||||
|
@ -108,17 +111,11 @@ def test_present_when_failing_to_describe_rule(global_config):
|
|||
assert "error on list rules" in result.get("comment", {})
|
||||
|
||||
|
||||
def test_present_when_failing_to_create_a_new_rule(global_config):
|
||||
def test_present_when_failing_to_create_a_new_rule(global_config, session_instance):
|
||||
"""
|
||||
Tests present on a rule name that doesn't exist and
|
||||
an error is thrown on creation.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -137,17 +134,11 @@ def test_present_when_failing_to_create_a_new_rule(global_config):
|
|||
assert "put_rule" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_present_when_failing_to_describe_the_new_rule(global_config):
|
||||
def test_present_when_failing_to_describe_the_new_rule(global_config, session_instance):
|
||||
"""
|
||||
Tests present on a rule name that doesn't exist and
|
||||
an error is thrown when adding targets.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -167,17 +158,13 @@ def test_present_when_failing_to_describe_the_new_rule(global_config):
|
|||
assert "describe_rule" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_present_when_failing_to_create_a_new_rules_targets(global_config):
|
||||
def test_present_when_failing_to_create_a_new_rules_targets(
|
||||
global_config, session_instance
|
||||
):
|
||||
"""
|
||||
Tests present on a rule name that doesn't exist and
|
||||
an error is thrown when adding targets.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -198,17 +185,11 @@ def test_present_when_failing_to_create_a_new_rules_targets(global_config):
|
|||
assert "put_targets" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_present_when_rule_does_not_exist(global_config):
|
||||
def test_present_when_rule_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests the successful case of creating a new rule, and updating its
|
||||
targets
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -226,16 +207,12 @@ def test_present_when_rule_does_not_exist(global_config):
|
|||
assert result.get("result") is True
|
||||
|
||||
|
||||
def test_present_when_failing_to_update_an_existing_rule(global_config):
|
||||
def test_present_when_failing_to_update_an_existing_rule(
|
||||
global_config, session_instance
|
||||
):
|
||||
"""
|
||||
Tests present on an existing rule where an error is thrown on updating the pool properties.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": [global_config.rule_ret]}
|
||||
|
@ -254,17 +231,11 @@ def test_present_when_failing_to_update_an_existing_rule(global_config):
|
|||
assert "describe_rule" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_present_when_failing_to_get_targets(global_config):
|
||||
def test_present_when_failing_to_get_targets(global_config, session_instance):
|
||||
"""
|
||||
Tests present on an existing rule where put_rule succeeded, but an error
|
||||
is thrown on getting targets
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": [global_config.rule_ret]}
|
||||
|
@ -285,17 +256,11 @@ def test_present_when_failing_to_get_targets(global_config):
|
|||
assert "list_targets" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_present_when_failing_to_put_targets(global_config):
|
||||
def test_present_when_failing_to_put_targets(global_config, session_instance):
|
||||
"""
|
||||
Tests present on an existing rule where put_rule succeeded, but an error
|
||||
is thrown on putting targets
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -317,17 +282,11 @@ def test_present_when_failing_to_put_targets(global_config):
|
|||
assert "put_targets" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_present_when_putting_targets(global_config):
|
||||
def test_present_when_putting_targets(global_config, session_instance):
|
||||
"""
|
||||
Tests present on an existing rule where put_rule succeeded, and targets
|
||||
must be added
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -346,17 +305,11 @@ def test_present_when_putting_targets(global_config):
|
|||
assert result.get("result") is True
|
||||
|
||||
|
||||
def test_present_when_removing_targets(global_config):
|
||||
def test_present_when_removing_targets(global_config, session_instance):
|
||||
"""
|
||||
Tests present on an existing rule where put_rule succeeded, and targets
|
||||
must be removed
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -375,16 +328,10 @@ def test_present_when_removing_targets(global_config):
|
|||
assert result.get("result") is True
|
||||
|
||||
|
||||
def test_absent_when_failing_to_describe_rule(global_config):
|
||||
def test_absent_when_failing_to_describe_rule(global_config, session_instance):
|
||||
"""
|
||||
Tests exceptions when checking rule existence
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.side_effect = botocore.exceptions.ClientError(
|
||||
|
@ -399,16 +346,10 @@ def test_absent_when_failing_to_describe_rule(global_config):
|
|||
assert "error on list rules" in result.get("comment", {})
|
||||
|
||||
|
||||
def test_absent_when_rule_does_not_exist(global_config):
|
||||
def test_absent_when_rule_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on an non-existing rule
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": []}
|
||||
|
@ -421,16 +362,10 @@ def test_absent_when_rule_does_not_exist(global_config):
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_failing_to_list_targets(global_config):
|
||||
def test_absent_when_failing_to_list_targets(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on an rule when the list_targets call fails
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": [global_config.rule_ret]}
|
||||
|
@ -446,16 +381,12 @@ def test_absent_when_failing_to_list_targets(global_config):
|
|||
assert "list_targets" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_absent_when_failing_to_remove_targets_exception(global_config):
|
||||
def test_absent_when_failing_to_remove_targets_exception(
|
||||
global_config, session_instance
|
||||
):
|
||||
"""
|
||||
Tests absent on an rule when the remove_targets call fails
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": [global_config.rule_ret]}
|
||||
|
@ -472,16 +403,12 @@ def test_absent_when_failing_to_remove_targets_exception(global_config):
|
|||
assert "remove_targets" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_absent_when_failing_to_remove_targets_nonexception(global_config):
|
||||
def test_absent_when_failing_to_remove_targets_nonexception(
|
||||
global_config, session_instance
|
||||
):
|
||||
"""
|
||||
Tests absent on an rule when the remove_targets call fails
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": [global_config.rule_ret]}
|
||||
|
@ -495,16 +422,10 @@ def test_absent_when_failing_to_remove_targets_nonexception(global_config):
|
|||
assert result.get("result") is False
|
||||
|
||||
|
||||
def test_absent_when_failing_to_delete_rule(global_config):
|
||||
def test_absent_when_failing_to_delete_rule(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on an rule when the delete_rule call fails
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": [global_config.rule_ret]}
|
||||
|
@ -522,16 +443,10 @@ def test_absent_when_failing_to_delete_rule(global_config):
|
|||
assert "delete_rule" in result.get("comment", "")
|
||||
|
||||
|
||||
def test_absent(global_config):
|
||||
def test_absent(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on an rule
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_rules.return_value = {"Rules": [global_config.rule_ret]}
|
||||
|
|
|
@ -50,6 +50,15 @@ class GlobalConfig:
|
|||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session_instance():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
with patch("boto3.session.Session") as patched_session:
|
||||
yield patched_session()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules(minion_opts):
|
||||
minion_opts["grains"] = salt.loader.grains(minion_opts)
|
||||
|
@ -81,13 +90,7 @@ def configure_loader_modules(minion_opts):
|
|||
}
|
||||
|
||||
|
||||
def test_present_when_domain_does_not_exist():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_domain_does_not_exist(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_elasticsearch_domain.side_effect = GlobalConfig.not_found_error
|
||||
|
@ -105,13 +108,7 @@ def test_present_when_domain_does_not_exist():
|
|||
assert result["changes"]["new"]["domain"]["ElasticsearchClusterConfig"] is None
|
||||
|
||||
|
||||
def test_present_when_domain_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_domain_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_elasticsearch_domain.return_value = {
|
||||
|
@ -133,13 +130,7 @@ def test_present_when_domain_exists():
|
|||
}
|
||||
|
||||
|
||||
def test_present_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_elasticsearch_domain.side_effect = GlobalConfig.not_found_error
|
||||
|
@ -156,16 +147,10 @@ def test_present_with_failure():
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_domain_does_not_exist():
|
||||
def test_absent_when_domain_does_not_exist(session_instance):
|
||||
"""
|
||||
Tests absent on a domain that does not exist.
|
||||
"""
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_elasticsearch_domain.side_effect = GlobalConfig.not_found_error
|
||||
|
@ -176,13 +161,7 @@ def test_absent_when_domain_does_not_exist():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_domain_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_domain_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_elasticsearch_domain.return_value = {
|
||||
|
@ -198,13 +177,7 @@ def test_absent_when_domain_exists():
|
|||
assert result["changes"]["new"]["domain"] is None
|
||||
|
||||
|
||||
def test_absent_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_elasticsearch_domain.return_value = {
|
||||
|
|
|
@ -94,6 +94,15 @@ class GlobalConfig:
|
|||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session_instance():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
with patch("boto3.session.Session") as patched_session:
|
||||
yield patched_session()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules(minion_opts):
|
||||
minion_opts["grains"] = salt.loader.grains(minion_opts)
|
||||
|
@ -125,13 +134,7 @@ def configure_loader_modules(minion_opts):
|
|||
}
|
||||
|
||||
|
||||
def test_present_when_thing_type_does_not_exist():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_thing_type_does_not_exist(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_thing_type.side_effect = [
|
||||
|
@ -153,13 +156,7 @@ def test_present_when_thing_type_does_not_exist():
|
|||
)
|
||||
|
||||
|
||||
def test_present_when_thing_type_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_thing_type_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_thing_type.return_value = GlobalConfig.thing_type_ret
|
||||
|
@ -175,13 +172,7 @@ def test_present_when_thing_type_exists():
|
|||
assert conn.create_thing_type.call_count == 0
|
||||
|
||||
|
||||
def test_present_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_thing_type.side_effect = [
|
||||
|
@ -202,13 +193,7 @@ def test_present_with_failure():
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_thing_type_does_not_exist():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_thing_type_does_not_exist(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_thing_type.side_effect = GlobalConfig.not_found_error
|
||||
|
@ -220,13 +205,7 @@ def test_absent_when_thing_type_does_not_exist():
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_absent_when_thing_type_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_thing_type_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_thing_type.return_value = GlobalConfig.deprecated_thing_type_ret
|
||||
|
@ -238,13 +217,7 @@ def test_absent_when_thing_type_exists():
|
|||
assert conn.deprecate_thing_type.call_count == 0
|
||||
|
||||
|
||||
def test_absent_with_deprecate_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_deprecate_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_thing_type.return_value = GlobalConfig.thing_type_ret
|
||||
|
@ -260,13 +233,7 @@ def test_absent_with_deprecate_failure():
|
|||
assert conn.delete_thing_type.call_count == 0
|
||||
|
||||
|
||||
def test_absent_with_delete_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_delete_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.describe_thing_type.return_value = GlobalConfig.deprecated_thing_type_ret
|
||||
|
@ -282,13 +249,7 @@ def test_absent_with_delete_failure():
|
|||
assert conn.deprecate_thing_type.call_count == 0
|
||||
|
||||
|
||||
def test_present_when_policy_does_not_exist():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_policy_does_not_exist(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_policy.side_effect = [
|
||||
|
@ -309,13 +270,7 @@ def test_present_when_policy_does_not_exist():
|
|||
)
|
||||
|
||||
|
||||
def test_present_when_policy_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_policy_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_policy.return_value = GlobalConfig.policy_ret
|
||||
|
@ -329,13 +284,7 @@ def test_present_when_policy_exists():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_present_again_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_again_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_policy.side_effect = [
|
||||
|
@ -354,13 +303,7 @@ def test_present_again_with_failure():
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_policy_does_not_exist():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_policy_does_not_exist(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_policy.side_effect = GlobalConfig.not_found_error
|
||||
|
@ -369,13 +312,7 @@ def test_absent_when_policy_does_not_exist():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_policy_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_policy_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_policy.return_value = GlobalConfig.policy_ret
|
||||
|
@ -387,13 +324,7 @@ def test_absent_when_policy_exists():
|
|||
assert result["changes"]["new"]["policy"] is None
|
||||
|
||||
|
||||
def test_absent_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_policy.return_value = GlobalConfig.policy_ret
|
||||
|
@ -408,13 +339,7 @@ def test_absent_with_failure():
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_attached_when_policy_not_attached():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_attached_when_policy_not_attached(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_principal_policies.return_value = {"policies": []}
|
||||
|
@ -425,13 +350,7 @@ def test_attached_when_policy_not_attached():
|
|||
assert result["changes"]["new"]["attached"]
|
||||
|
||||
|
||||
def test_attached_when_policy_attached():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_attached_when_policy_attached(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_principal_policies.return_value = {"policies": [GlobalConfig.policy_ret]}
|
||||
|
@ -442,13 +361,7 @@ def test_attached_when_policy_attached():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_attached_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_attached_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_principal_policies.return_value = {"policies": []}
|
||||
|
@ -462,13 +375,7 @@ def test_attached_with_failure():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_detached_when_policy_not_detached():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_detached_when_policy_not_detached(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_principal_policies.return_value = {"policies": [GlobalConfig.policy_ret]}
|
||||
|
@ -480,13 +387,7 @@ def test_detached_when_policy_not_detached():
|
|||
assert not result["changes"]["new"]["attached"]
|
||||
|
||||
|
||||
def test_detached_when_policy_detached():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_detached_when_policy_detached(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_principal_policies.return_value = {"policies": []}
|
||||
|
@ -497,13 +398,7 @@ def test_detached_when_policy_detached():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_detached_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_detached_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.list_principal_policies.return_value = {"policies": [GlobalConfig.policy_ret]}
|
||||
|
@ -517,13 +412,7 @@ def test_detached_with_failure():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_present_when_topic_rule_does_not_exist():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_topic_rule_does_not_exist(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_topic_rule.side_effect = [
|
||||
|
@ -547,13 +436,7 @@ def test_present_when_topic_rule_does_not_exist():
|
|||
)
|
||||
|
||||
|
||||
def test_present_when_next_policy_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_next_policy_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_topic_rule.return_value = {"rule": GlobalConfig.topic_rule_ret}
|
||||
|
@ -570,13 +453,7 @@ def test_present_when_next_policy_exists():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_present_next_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_next_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_topic_rule.side_effect = [
|
||||
|
@ -598,13 +475,7 @@ def test_present_next_with_failure():
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_topic_rule_does_not_exist():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_topic_rule_does_not_exist(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_topic_rule.side_effect = GlobalConfig.topic_rule_not_found_error
|
||||
|
@ -613,13 +484,7 @@ def test_absent_when_topic_rule_does_not_exist():
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_topic_rule_exists():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_topic_rule_exists(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_topic_rule.return_value = GlobalConfig.topic_rule_ret
|
||||
|
@ -630,13 +495,7 @@ def test_absent_when_topic_rule_exists():
|
|||
assert result["changes"]["new"]["rule"] is None
|
||||
|
||||
|
||||
def test_absent_next_with_failure():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_next_with_failure(session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
conn.get_topic_rule.return_value = GlobalConfig.topic_rule_ret
|
||||
|
|
|
@ -68,10 +68,19 @@ class GlobalConfig:
|
|||
|
||||
@pytest.fixture
|
||||
def global_config():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
params = GlobalConfig()
|
||||
return params
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session_instance():
|
||||
with patch("boto3.session.Session") as patched_session:
|
||||
yield patched_session()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules(minion_opts):
|
||||
minion_opts["grains"] = salt.loader.grains(minion_opts)
|
||||
|
@ -104,16 +113,10 @@ def configure_loader_modules(minion_opts):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_function_does_not_exist_func(global_config):
|
||||
def test_present_when_function_does_not_exist_func(global_config, session_instance):
|
||||
"""
|
||||
Tests present on a function that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -144,13 +147,7 @@ def test_present_when_function_does_not_exist_func(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_function_exists_func(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_function_exists_func(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -185,13 +182,7 @@ def test_present_when_function_exists_func(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_with_failure_func(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_with_failure_func(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -229,16 +220,10 @@ def test_present_with_failure_func(global_config):
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_function_does_not_exist_func(global_config):
|
||||
def test_absent_when_function_does_not_exist_func(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on a function that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -248,13 +233,7 @@ def test_absent_when_function_does_not_exist_func(global_config):
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_function_exists_func(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_function_exists_func(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -266,13 +245,7 @@ def test_absent_when_function_exists_func(global_config):
|
|||
assert result["changes"]["new"]["function"] is None
|
||||
|
||||
|
||||
def test_absent_with_failure_func(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_failure_func(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -288,13 +261,9 @@ def test_absent_with_failure_func(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_function_exists_and_permissions_func(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_function_exists_and_permissions_func(
|
||||
global_config, session_instance
|
||||
):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -363,16 +332,10 @@ def test_present_when_function_exists_and_permissions_func(global_config):
|
|||
}
|
||||
|
||||
|
||||
def test_present_when_alias_does_not_exist(global_config):
|
||||
def test_present_when_alias_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests present on a alias that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -392,13 +355,7 @@ def test_present_when_alias_does_not_exist(global_config):
|
|||
assert result["changes"]["new"]["alias"]["Name"] == global_config.alias_ret["Name"]
|
||||
|
||||
|
||||
def test_present_when_alias_exists(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_alias_exists(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -416,13 +373,7 @@ def test_present_when_alias_exists(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_with_failure_glob(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_with_failure_glob(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -443,16 +394,10 @@ def test_present_with_failure_glob(global_config):
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_alias_does_not_exist(global_config):
|
||||
def test_absent_when_alias_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on a alias that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -464,13 +409,7 @@ def test_absent_when_alias_does_not_exist(global_config):
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_alias_exists(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_alias_exists(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -482,13 +421,7 @@ def test_absent_when_alias_exists(global_config):
|
|||
assert result["changes"]["new"]["alias"] is None
|
||||
|
||||
|
||||
def test_absent_with_failure(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_failure(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -503,16 +436,12 @@ def test_absent_with_failure(global_config):
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_present_when_event_source_mapping_does_not_exist(global_config):
|
||||
def test_present_when_event_source_mapping_does_not_exist(
|
||||
global_config, session_instance
|
||||
):
|
||||
"""
|
||||
Tests present on a event_source_mapping that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -538,13 +467,7 @@ def test_present_when_event_source_mapping_does_not_exist(global_config):
|
|||
)
|
||||
|
||||
|
||||
def test_present_when_event_source_mapping_exists(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_event_source_mapping_exists(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -567,13 +490,7 @@ def test_present_when_event_source_mapping_exists(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_with_failure(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_with_failure(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -596,16 +513,12 @@ def test_present_with_failure(global_config):
|
|||
assert "An error occurred" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_event_source_mapping_does_not_exist(global_config):
|
||||
def test_absent_when_event_source_mapping_does_not_exist(
|
||||
global_config, session_instance
|
||||
):
|
||||
"""
|
||||
Tests absent on a event_source_mapping that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -619,13 +532,7 @@ def test_absent_when_event_source_mapping_does_not_exist(global_config):
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_event_source_mapping_exists(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_event_source_mapping_exists(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -642,13 +549,7 @@ def test_absent_when_event_source_mapping_exists(global_config):
|
|||
assert result["changes"]["new"]["event_source_mapping"] is None
|
||||
|
||||
|
||||
def test_absent_with_failure_glob(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_failure_glob(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
|
|
@ -175,10 +175,19 @@ class GlobalConfig:
|
|||
|
||||
@pytest.fixture
|
||||
def global_config():
|
||||
GlobalConfig.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
params = GlobalConfig()
|
||||
return params
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session_instance():
|
||||
with patch("boto3.session.Session") as patched_session:
|
||||
yield patched_session()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules(minion_opts):
|
||||
ctx = {}
|
||||
|
@ -210,16 +219,10 @@ def configure_loader_modules(minion_opts):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_bucket_does_not_exist(global_config):
|
||||
def test_present_when_bucket_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests present on a bucket that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -244,13 +247,7 @@ def test_present_when_bucket_does_not_exist(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_bucket_exists_no_mods(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_bucket_exists_no_mods(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -270,13 +267,7 @@ def test_present_when_bucket_exists_no_mods(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_when_bucket_exists_all_mods(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_when_bucket_exists_all_mods(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -298,13 +289,7 @@ def test_present_when_bucket_exists_all_mods(global_config):
|
|||
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_present_with_failure(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_present_with_failure(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -324,16 +309,10 @@ def test_present_with_failure(global_config):
|
|||
assert "Failed to create bucket" in result["comment"]
|
||||
|
||||
|
||||
def test_absent_when_bucket_does_not_exist(global_config):
|
||||
def test_absent_when_bucket_does_not_exist(global_config, session_instance):
|
||||
"""
|
||||
Tests absent on a bucket that does not exist.
|
||||
"""
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -343,13 +322,7 @@ def test_absent_when_bucket_does_not_exist(global_config):
|
|||
assert result["changes"] == {}
|
||||
|
||||
|
||||
def test_absent_when_bucket_exists(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_when_bucket_exists(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
@ -358,13 +331,7 @@ def test_absent_when_bucket_exists(global_config):
|
|||
assert result["changes"]["new"]["bucket"] is None
|
||||
|
||||
|
||||
def test_absent_with_failure(global_config):
|
||||
global_config.conn_parameters["key"] = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
|
||||
)
|
||||
patcher = patch("boto3.session.Session")
|
||||
mock_session = patcher.start()
|
||||
session_instance = mock_session.return_value
|
||||
def test_absent_with_failure(global_config, session_instance):
|
||||
conn = MagicMock()
|
||||
session_instance.client.return_value = conn
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue