Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Jul 2, 2024
1 parent eeab947 commit 533dc4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion changelogs/fragments/20240107-refactor_ec2_ami-modules.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
minor_changes:
- ec2_ami - refactored code to use ``AnsibleEC2Error`` as well as moving shared code into module_utils.ec2 (https://github.com/ansible-collections/amazon.aws/pull/2164). - ec2_ami_info - refactored code to use ``AnsibleEC2Error`` as well as moving shared code into module_utils.ec2 (https://github.com/ansible-collections/amazon.aws/pull/2164).
- ec2_ami - refactored code to use ``AnsibleEC2Error`` as well as moving shared code into module_utils.ec2 (https://github.com/ansible-collections/amazon.aws/pull/2164).
- ec2_ami_info - refactored code to use ``AnsibleEC2Error`` as well as moving shared code into module_utils.ec2 (https://github.com/ansible-collections/amazon.aws/pull/2164).
10 changes: 5 additions & 5 deletions tests/unit/plugins/modules/test_ec2_ami_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from unittest.mock import call
from unittest.mock import patch

import botocore.exceptions
import pytest

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
Expand Down Expand Up @@ -183,13 +182,14 @@ def test_main_success(m_AnsibleAWSModule):
m_module.exit_json.assert_called_with(images=[])


def a_boto_exception():
return botocore.exceptions.UnknownServiceError(service_name="Whoops", known_service_names="Oula")
def a_ami_info_exception():
return ec2_ami_info.AnsibleEC2Error(message="Whoops")


def test_api_failure_get_images(ec2_client):
@patch(module_name + ".describe_images")
def test_api_failure_get_images(m_describe_images):
request_args = {}
ec2_client.describe_images.side_effect = a_boto_exception()
m_describe_images.side_effect = a_ami_info_exception()

with pytest.raises(ec2_ami_info.AmiInfoFailure):
ec2_ami_info.get_images(ec2_client, request_args)

0 comments on commit 533dc4c

Please sign in to comment.