Skip to content

Commit

Permalink
Group magicmocks together
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-griffin committed Dec 13, 2024
1 parent d796718 commit 993b0f8
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ def test_assumes_correct_role_for_cloudfront_access(self, rotator):
}
}

mock_sts = MagicMock()
mock_cloudfront = MagicMock()

mock_sts.assume_role.return_value = mock_credentials

with patch('boto3.client') as mock_boto3_client:
# Set up separate mocks for STS and CloudFront clients
mock_sts = MagicMock()
mock_cloudfront = MagicMock()

mock_boto3_client.side_effect = lambda service, **kwargs: \
mock_sts if service == 'sts' else mock_cloudfront

mock_sts.assume_role.return_value = mock_credentials

client = rotator.get_cloudfront_client()

mock_sts.assume_role.assert_called_once_with(
Expand Down Expand Up @@ -996,7 +995,6 @@ def test_handles_empty_distribution_list_gracefully(self, rotator):
rotator.get_deployed_distributions = MagicMock()
rotator.get_deployed_distributions.return_value = []

boto3.client = MagicMock()
mock_boto_client = MagicMock()
mock_boto_client.assume_role.return_value = mock_credentials
mock_boto_client.get_secret_value.side_effect = [
Expand All @@ -1005,8 +1003,6 @@ def test_handles_empty_distribution_list_gracefully(self, rotator):
]
mock_boto_client.describe_secret.return_value = mock_metadata

boto3.client.return_value = mock_boto_client

rotator.get_waf_acl = MagicMock()
rotator.update_cf_distro = MagicMock()
time.sleep = MagicMock()
Expand Down

0 comments on commit 993b0f8

Please sign in to comment.