From 5087ce9273424c7df3571ccf7c1026f01ee8bb1c Mon Sep 17 00:00:00 2001 From: "Ryan S. Brown" Date: Mon, 4 Dec 2017 09:57:40 -0500 Subject: [PATCH] Remove botocore from top-level execution in lambda_policy tests Even though the tests are skipped, the `ClientError` uses outside the test cause a failure even though the tests never run --- test/units/modules/cloud/amazon/test_lambda_policy.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/units/modules/cloud/amazon/test_lambda_policy.py b/test/units/modules/cloud/amazon/test_lambda_policy.py index 67a1cb7ac3c..0bae3bc812b 100644 --- a/test/units/modules/cloud/amazon/test_lambda_policy.py +++ b/test/units/modules/cloud/amazon/test_lambda_policy.py @@ -31,9 +31,13 @@ if not HAS_BOTO3: pytestmark = pytest.mark.skip("test_api_gateway.py requires the `boto3` and `botocore` modules") # these are here cause ... boto! -from botocore.exceptions import ClientError import ansible.modules.cloud.amazon.lambda_policy as lambda_policy from ansible.modules.cloud.amazon.lambda_policy import setup_module_object +try: + from botocore.exceptions import ClientError +except ImportError: + pass + base_module_args = { "region": "us-west-1", @@ -100,13 +104,12 @@ fake_policy_return = { error_response = {'Error': {'Code': 'ResourceNotFoundException', 'Message': 'Fake Testing Error'}} operation_name = 'FakeOperation' -resource_not_found_e = ClientError(error_response, operation_name) def test_manage_state_adds_missing_permissions(): lambda_client_double = MagicMock() # Policy actually: not present Requested State: present Should: create - lambda_client_double.get_policy.side_effect = resource_not_found_e + lambda_client_double.get_policy.side_effect = ClientError(error_response, operation_name) fake_module_params = copy.deepcopy(fake_module_params_present) module_double.params = fake_module_params lambda_policy.manage_state(module_double, lambda_client_double) @@ -154,7 +157,7 @@ def test_manage_state_removes_unwanted_permissions(): def test_manage_state_leaves_already_removed_permissions(): lambda_client_double = MagicMock() # Policy actually: absent Requested State: absent Should: do nothing - lambda_client_double.get_policy.side_effect = resource_not_found_e + lambda_client_double.get_policy.side_effect = ClientError(error_response, operation_name) fake_module_params = copy.deepcopy(fake_module_params_absent) module_double.params = fake_module_params lambda_policy.manage_state(module_double, lambda_client_double)