Skip to content

Commit

Permalink
fix(dms): fix MagicMock unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danibarranqueroo committed Nov 4, 2024
1 parent c8f60de commit f0809ea
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def test_dms_no_endpoints(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_endpoint_ssl_enabled.dms_endpoint_ssl_enabled import (
dms_endpoint_ssl_enabled,
Expand Down Expand Up @@ -41,6 +44,9 @@ def test_dms_endpoint_ssl_none(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_endpoint_ssl_enabled.dms_endpoint_ssl_enabled import (
dms_endpoint_ssl_enabled,
Expand Down Expand Up @@ -85,6 +91,9 @@ def test_dms_endpoint_ssl_require(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_endpoint_ssl_enabled.dms_endpoint_ssl_enabled import (
dms_endpoint_ssl_enabled,
Expand Down Expand Up @@ -126,6 +135,9 @@ def test_dms_endpoint_ssl_verify_ca(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_endpoint_ssl_enabled.dms_endpoint_ssl_enabled import (
dms_endpoint_ssl_enabled,
Expand Down Expand Up @@ -167,6 +179,9 @@ def test_dms_endpoint_ssl_verify_full(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_endpoint_ssl_enabled.dms_endpoint_ssl_enabled import (
dms_endpoint_ssl_enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def test_dms_no_instances(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_minor_version_upgrade_enabled.dms_instance_minor_version_upgrade_enabled import (
dms_instance_minor_version_upgrade_enabled,
Expand Down Expand Up @@ -47,6 +50,9 @@ def test_dms_minor_version_upgrade_not_enabled(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_minor_version_upgrade_enabled.dms_instance_minor_version_upgrade_enabled import (
dms_instance_minor_version_upgrade_enabled,
Expand Down Expand Up @@ -87,6 +93,9 @@ def test_dms_instance_minor_version_upgrade_enabled(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_minor_version_upgrade_enabled.dms_instance_minor_version_upgrade_enabled import (
dms_instance_minor_version_upgrade_enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def test_dms_no_instances(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_multi_az_enabled.dms_instance_multi_az_enabled import (
dms_instance_multi_az_enabled,
Expand Down Expand Up @@ -47,6 +50,9 @@ def test_dms_instance_multi_az_not_enabled(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_multi_az_enabled.dms_instance_multi_az_enabled import (
dms_instance_multi_az_enabled,
Expand Down Expand Up @@ -87,6 +93,9 @@ def test_dms_instance_multi_az_enabled(self):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_multi_az_enabled.dms_instance_multi_az_enabled import (
dms_instance_multi_az_enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@

class Test_dms_instance_no_public_access:
def test_dms_no_instances(self):
dms_client = mock.MagicMock
dms_client = mock.MagicMock()
dms_client.instances = []

from prowler.providers.aws.services.ec2.ec2_service import EC2

aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])

with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
return_value=set_mocked_aws_provider([AWS_REGION_US_EAST_1]),
):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.rds.rds_instance_no_public_access.rds_instance_no_public_access.ec2_client",
new=EC2(aws_provider),
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_no_public_access.dms_instance_no_public_access import (
dms_instance_no_public_access,
Expand All @@ -46,7 +42,7 @@ def test_dms_no_instances(self):
assert len(result) == 0

def test_dms_private(self):
dms_client = mock.MagicMock
dms_client = mock.MagicMock()
dms_client.instances = []
dms_client.instances.append(
RepInstance(
Expand All @@ -63,15 +59,16 @@ def test_dms_private(self):
)
)

aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])

with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
return_value=set_mocked_aws_provider([AWS_REGION_US_EAST_1]),
):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_no_public_access.dms_instance_no_public_access import (
dms_instance_no_public_access,
Expand All @@ -96,7 +93,7 @@ def test_dms_private(self):
]

def test_dms_public(self):
dms_client = mock.MagicMock
dms_client = mock.MagicMock()
dms_client.instances = []
dms_client.instances.append(
RepInstance(
Expand All @@ -113,15 +110,16 @@ def test_dms_public(self):
)
)

aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])

with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
return_value=set_mocked_aws_provider([AWS_REGION_US_EAST_1]),
):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
):
from prowler.providers.aws.services.dms.dms_instance_no_public_access.dms_instance_no_public_access import (
dms_instance_no_public_access,
Expand Down Expand Up @@ -162,7 +160,7 @@ def test_dms_public_with_public_sg(self):
}
],
)
dms_client = mock.MagicMock
dms_client = mock.MagicMock()
dms_client.instances = []
dms_client.instances.append(
RepInstance(
Expand Down Expand Up @@ -191,7 +189,10 @@ def test_dms_public_with_public_sg(self):
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
"prowler.providers.aws.services.dms.dms_instance_no_public_access.dms_instance_no_public_access.dms_client",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_instance_no_public_access.dms_instance_no_public_access.ec2_client",
Expand Down Expand Up @@ -267,7 +268,10 @@ def test_dms_public_with_filtered_sg(self):
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.dms.dms_service.DMS",
"prowler.providers.aws.services.dms.dms_instance_no_public_access.dms_instance_no_public_access.dms_client",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_client.dms_client",
new=dms_client,
), mock.patch(
"prowler.providers.aws.services.dms.dms_instance_no_public_access.dms_instance_no_public_access.ec2_client",
Expand Down

0 comments on commit f0809ea

Please sign in to comment.