Skip to content

Commit

Permalink
Unit tests - post-move quick fixes (ansible-collections#394)
Browse files Browse the repository at this point in the history
* Fix aws_api_gateway unit tests - imports moved
* Fix aws_direct_connect_confirm_connection unit tests - imports moved
* Fix aws_acm unit tests - fixtures moved
* Fix ec2_win_password unit tests - imports moved
* Fix iam_password_policy unit tests - imports moved
* Fix lambda unit tests - imports moved
* Fix lambda_policy unit tests - imports moved
* Fix route53_zone unit tests - imports moved
* Fix s3_bucket_notification unit tests - imports moved
* Fix ec2_win_password unit tests - fixtures moved
* Fix lambda unit tests - fixtures moved
  • Loading branch information
tremble authored Feb 5, 2021
1 parent 1cf83b1 commit 468b6d2
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tests/unit/plugins/modules/test_aws_acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_chain_compare():
# And if they do, fail_json is not applicable
module = None

fixture_suffix = 'tests/unit/modules/fixtures/certs'
fixture_suffix = 'tests/unit/plugins/modules/fixtures/certs'

# Test chain split function on super simple (invalid) certs
expected = ['aaa', 'bbb', 'ccc']
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/plugins/modules/test_aws_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
__metaclass__ = type

import sys

import pytest

from ansible_collections.amazon.aws.plugins.module_utils import core
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3
from ansible_collections.community.aws.tests.unit.modules.utils import set_module_args
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args

import ansible_collections.community.aws.plugins.modules.aws_api_gateway as agw

if not HAS_BOTO3:
pytestmark = pytest.mark.skip("test_api_gateway.py requires the `boto3` and `botocore` modules")

import ansible_collections.community.aws.plugins.modules.aws_api_gateway as agw
from ansible_collections.amazon.aws.plugins.module_utils import core


exit_return_dict = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock, patch, call
from ansible_collections.community.aws.tests.unit.modules.utils import (AnsibleExitJson,
AnsibleFailJson,
ModuleTestCase,
set_module_args)
from ansible_collections.community.aws.plugins.modules import aws_direct_connect_confirm_connection
import pytest
try:
from botocore.exceptions import ClientError
except ImportError:
pass

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3
from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock
from ansible_collections.community.aws.tests.unit.compat.mock import patch
from ansible_collections.community.aws.tests.unit.compat.mock import call
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleExitJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleFailJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import ModuleTestCase
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args

from ansible_collections.community.aws.plugins.modules import aws_direct_connect_confirm_connection

if not HAS_BOTO3:
pytestmark = pytest.mark.skip("test_aws_direct_connect_confirm_connection.py requires the `boto3` and `botocore` modules")


@patch('ansible_collections.amazon.aws.plugins.module_utils.core.HAS_BOTO3', new=True)
@patch.object(aws_direct_connect_confirm_connection.AnsibleAWSModule, "client")
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/plugins/modules/test_ec2_win_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
string_cipher = base64.b64encode(base64_cipher)
'''

from ansible.module_utils._text import to_bytes, to_text
from ansible_collections.community.aws.plugins.modules.ec2_win_password import setup_module_object, ec2_win_password
from ansible.module_utils._text import to_bytes
from ansible.module_utils._text import to_text
from ansible_collections.community.aws.tests.unit.compat.mock import patch
from ansible_collections.community.aws.tests.unit.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleExitJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import ModuleTestCase
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args

fixture_prefix = 'tests/unit/modules/fixtures/certs'
from ansible_collections.community.aws.plugins.modules.ec2_win_password import setup_module_object
from ansible_collections.community.aws.plugins.modules.ec2_win_password import ec2_win_password

fixture_prefix = 'tests/unit/plugins/modules/fixtures/certs'


class TestEc2WinPasswordModule(ModuleTestCase):
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/plugins/modules/test_iam_password_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

import pytest

from ansible_collections.community.aws.tests.unit.modules.utils import set_module_args
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3

from ansible_collections.community.aws.plugins.modules import iam_password_policy

if not HAS_BOTO3:
pytestmark = pytest.mark.skip("iam_password_policy.py requires the `boto3` and `botocore` modules")
else:
import boto3
from ansible_collections.community.aws.plugins.modules import iam_password_policy


def test_warn_if_state_not_specified():
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/plugins/modules/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
import copy
import pytest

from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock, Mock, patch
from ansible.module_utils import basic
from ansible_collections.community.aws.tests.unit.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args

boto3 = pytest.importorskip("boto3")
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3
from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock
from ansible_collections.community.aws.tests.unit.compat.mock import Mock
from ansible_collections.community.aws.tests.unit.compat.mock import patch
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleExitJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleFailJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import ModuleTestCase
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args

if not HAS_BOTO3:
pytestmark = pytest.mark.skip("lambda.py requires the `boto3` and `botocore` modules")

# lambda is a keyword so we have to hack this.
_temp = __import__('ansible_collections.community.aws.plugins.modules.lambda')
Expand Down Expand Up @@ -46,7 +53,7 @@
"region": "us-west-1",
"name": "lambda_name",
"state": "present",
"zip_file": "tests/unit/modules/fixtures/thezip.zip",
"zip_file": "tests/unit/plugins/modules/fixtures/thezip.zip",
"runtime": 'python2.7',
"role": 'arn:aws:iam::987654321012:role/lambda_basic_execution',
"memory_size": 128,
Expand Down
18 changes: 8 additions & 10 deletions tests/unit/plugins/modules/test_lambda_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@
__metaclass__ = type

import copy

import pytest

try:
from botocore.exceptions import ClientError
except ImportError:
pass

from ansible_collections.amazon.aws.plugins.module_utils.core import HAS_BOTO3
from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock
from ansible_collections.community.aws.tests.unit.modules.utils import set_module_args
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.aws.plugins.modules import lambda_policy
from ansible_collections.community.aws.plugins.modules.lambda_policy import setup_module_object

if not HAS_BOTO3:
pytestmark = pytest.mark.skip("test_api_gateway.py requires the `boto3` and `botocore` modules")

# these are here cause ... boto!
from ansible_collections.community.aws.plugins.modules import lambda_policy
from ansible_collections.community.aws.plugins.modules.lambda_policy import setup_module_object
try:
from botocore.exceptions import ClientError
except ImportError:
pass


base_module_args = {
"region": "us-west-1",
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/plugins/modules/test_route53_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

from ansible_collections.community.aws.plugins.modules import route53_zone
from ansible_collections.community.aws.tests.unit.compat import unittest
from ansible_collections.community.aws.tests.unit.compat.mock import patch, call
from ansible_collections.community.aws.tests.unit.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.aws.tests.unit.compat.mock import call
from ansible_collections.community.aws.tests.unit.compat.mock import patch
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleExitJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleFailJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import ModuleTestCase
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args


def parameterized(params_list):
Expand Down
21 changes: 15 additions & 6 deletions tests/unit/plugins/modules/test_s3_bucket_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
__metaclass__ = type

import pytest

from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock, patch
from ansible_collections.community.aws.tests.unit.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args

from ansible_collections.community.aws.plugins.modules.s3_bucket_notification import AmazonBucket, Config
from ansible_collections.community.aws.plugins.modules import s3_bucket_notification
try:
from botocore.exceptions import ClientError
except ImportError:
pass

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3
from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock
from ansible_collections.community.aws.tests.unit.compat.mock import patch
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleExitJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleFailJson
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import ModuleTestCase
from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args

from ansible_collections.community.aws.plugins.modules.s3_bucket_notification import AmazonBucket
from ansible_collections.community.aws.plugins.modules.s3_bucket_notification import Config
from ansible_collections.community.aws.plugins.modules import s3_bucket_notification

if not HAS_BOTO3:
pytestmark = pytest.mark.skip("s3_bucket_notification.py requires the `boto3` and `botocore` modules")


class TestAmazonBucketOperations:
def test_current_config(self):
Expand Down

0 comments on commit 468b6d2

Please sign in to comment.