Beispiel #1
0
def test__wait_for_snapshot_status_failed(input, expected):
    spec = {"get_waiter.side_effect": [WaiterError(None, None, None)]}
    client = MagicMock(**spec)
    module = MagicMock()

    rds.wait_for_snapshot_status(client, module, "test", input)
    module.fail_json_aws.assert_called_once
    module.fail_json_aws.call_args[1]["msg"] == expected
Beispiel #2
0
    def setUp(self):
        self.sts_client = MagicMock()
        self.iam_client = MagicMock()
        self.module = MagicMock()
        clients = {'sts': self.sts_client, 'iam': self.iam_client}

        def get_client(*args, **kwargs):
            return clients[args[0]]

        self.module.client.side_effect = get_client
        self.module.fail_json_aws.side_effect = SystemExit(1)
        self.module.fail_json.side_effect = SystemExit(2)
Beispiel #3
0
def test_validate_bucket_name():
    module = MagicMock()

    assert s3.validate_bucket_name(module, "docexamplebucket1") is True
    assert not module.fail_json.called
    assert s3.validate_bucket_name(module, "log-delivery-march-2020") is True
    assert not module.fail_json.called
    assert s3.validate_bucket_name(module, "my-hosted-content") is True
    assert not module.fail_json.called

    assert s3.validate_bucket_name(module, "docexamplewebsite.com") is True
    assert not module.fail_json.called
    assert s3.validate_bucket_name(module, "www.docexamplewebsite.com") is True
    assert not module.fail_json.called
    assert s3.validate_bucket_name(module, "my.example.s3.bucket") is True
    assert not module.fail_json.called

    module.fail_json.reset_mock()
    s3.validate_bucket_name(module, "doc_example_bucket")
    assert module.fail_json.called

    module.fail_json.reset_mock()
    s3.validate_bucket_name(module, "DocExampleBucket")
    assert module.fail_json.called
    module.fail_json.reset_mock()
    s3.validate_bucket_name(module, "doc-example-bucket-")
    assert module.fail_json.called
Beispiel #4
0
def test__handle_errors_failed(method_name, exception, expected, error):
    module = MagicMock()

    with error:
        rds.handle_errors(module, exception, method_name,
                          {"Engine": "fake_engine"})
        module.fail_json_aws.assert_called_once
        module.fail_json_aws.call_args[1]["msg"] == expected
Beispiel #5
0
def test__wait_for_snapshot_status(waiter_name):
    rds.wait_for_snapshot_status(MagicMock(), MagicMock(), "test", waiter_name)
Beispiel #6
0
def test__handle_errors(method_name, exception, expected):
    assert rds.handle_errors(MagicMock(), exception, method_name,
                             {}) == expected
Beispiel #7
0
def error(*args, **kwargs):
    return MagicMock(), pytest.raises(*args, **kwargs)
Beispiel #8
0
def test__get_final_identifier(method_name, params, expected):
    module = MagicMock()
    module.params = params
    module.check_mode = False

    assert rds.get_final_identifier(method_name, module) == expected
Beispiel #9
0
def test__get_rds_method_attribute(input, expected, error):
    with error:
        assert rds.get_rds_method_attribute(input, MagicMock()) == expected
Beispiel #10
0
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible_collections.amazon.aws.tests.unit.compat.mock import MagicMock
from ansible.utils.path import unfrackpath


mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x)
Beispiel #11
0
    def setUp(self):
        self.connection = MagicMock(name="connection")
        self.module = MagicMock(name="module")

        self.module.params = dict()

        self.conn_paginator = MagicMock(name="connection.paginator")
        self.paginate = MagicMock(name="paginator.paginate")

        self.connection.get_paginator.return_value = self.conn_paginator
        self.conn_paginator.paginate.return_value = self.paginate

        self.loadbalancer = {
            "Type":
            "application",
            "Scheme":
            "internet-facing",
            "IpAddressType":
            "ipv4",
            "VpcId":
            "vpc-3ac0fb5f",
            "AvailabilityZones": [{
                "ZoneName": "us-west-2a",
                "SubnetId": "subnet-8360a9e7"
            }, {
                "ZoneName": "us-west-2b",
                "SubnetId": "subnet-b7d581c0"
            }],
            "CreatedTime":
            "2016-03-25T21:26:12.920Z",
            "CanonicalHostedZoneId":
            "Z2P70J7EXAMPLE",
            "DNSName":
            "my-load-balancer-424835706.us-west-2.elb.amazonaws.com",
            "SecurityGroups": ["sg-5943793c"],
            "LoadBalancerName":
            "my-load-balancer",
            "State": {
                "Code": "active"
            },
            "LoadBalancerArn":
            "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"
        }
        self.paginate.build_full_result.return_value = {
            'LoadBalancers': [self.loadbalancer]
        }

        self.connection.describe_load_balancer_attributes.return_value = {
            "Attributes": [{
                "Value": "false",
                "Key": "access_logs.s3.enabled"
            }, {
                "Value": "",
                "Key": "access_logs.s3.bucket"
            }, {
                "Value": "",
                "Key": "access_logs.s3.prefix"
            }, {
                "Value": "60",
                "Key": "idle_timeout.timeout_seconds"
            }, {
                "Value": "false",
                "Key": "deletion_protection.enabled"
            }, {
                "Value": "true",
                "Key": "routing.http2.enabled"
            }]
        }
        self.connection.describe_tags.return_value = {
            "TagDescriptions": [{
                "ResourceArn":
                "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188",
                "Tags": [{
                    "Value": "ansible",
                    "Key": "project"
                }, {
                    "Value": "RedHat",
                    "Key": "company"
                }]
            }]
        }
        self.elbv2obj = elbv2.ElasticLoadBalancerV2(self.connection,
                                                    self.module)