Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrooot committed Sep 12, 2024
1 parent ddc1121 commit f061336
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tests/providers/aws/aws_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def test_generate_regional_clients_all_enabled_regions(self):
aws_provider = AwsProvider()
response = aws_provider.generate_regional_clients("ec2")

assert len(response.keys()) == 30
assert len(response.keys()) == 29

@mock_aws
def test_generate_regional_clients_with_enabled_regions(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_list_event_buses(self):
)
aws_provider = set_mocked_aws_provider()
eventbridge = EventBridge(aws_provider)
assert len(eventbridge.buses) == 31 # 1 per region
assert len(eventbridge.buses) == 30 # 1 per region
for bus in eventbridge.buses.values():
if bus.name == "test":
assert (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from unittest import mock
from uuid import uuid4

from boto3 import client
from moto import mock_aws

from tests.providers.aws.utils import (
AWS_ACCOUNT_ARN,
AWS_ACCOUNT_NUMBER,
AWS_REGION_EU_WEST_1,
set_mocked_aws_provider,
)

DETECTOR_ID = str(uuid4())
Expand All @@ -17,39 +16,20 @@
class Test_guardduty_is_enabled_fixer:
@mock_aws
def test_guardduty_is_enabled_fixer(self):
from prowler.providers.aws.services.guardduty.guardduty_service import GuardDuty

aws_provider = set_mocked_aws_provider(
audited_regions=[AWS_REGION_EU_WEST_1],
fixer_config={
"guardduty_is_enabled": {
"DetectorId": DETECTOR_ID,
},
},
)

guardduty = client("guardduty", region_name=AWS_REGION_EU_WEST_1)
guardduty.create_detector(
Enable=True,
FindingPublishingFrequency="FIFTEEN_MINUTES",
DataSources={
"S3Logs": {
"Enable": True,
},
},
)
regional_client = mock.MagicMock()
guardduty_client = mock.MagicMock
guardduty_client.region = AWS_REGION_EU_WEST_1
guardduty_client.detectors = []
guardduty_client.audited_account_arn = AWS_ACCOUNT_ARN
regional_client.create_detector.return_value = None
guardduty_client.regional_clients = {AWS_REGION_EU_WEST_1: regional_client}

with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
"prowler.providers.aws.services.guardduty.guardduty_service.GuardDuty",
guardduty_client,
):
with mock.patch(
"prowler.providers.aws.services.guardduty.guardduty_is_enabled.guardduty_is_enabled_fixer.guardduty_client",
new=GuardDuty(aws_provider),
):
# Test Check
from prowler.providers.aws.services.guardduty.guardduty_is_enabled.guardduty_is_enabled_fixer import (
fixer,
)
from prowler.providers.aws.services.guardduty.guardduty_is_enabled.guardduty_is_enabled_fixer import (
fixer,
)

assert fixer(AWS_REGION_EU_WEST_1)
assert fixer(AWS_REGION_EU_WEST_1)

0 comments on commit f061336

Please sign in to comment.