Repository: cloudtools/troposphere
Pull request #1948 (2021-08-27 11:40:24)

Remove duplicate TargetTrackingScalingPolicyConfiguration from dynamodb.py
The duplicate TargetTrackingScalingPolicyConfiguration class defined in dynamodb causes type assertions to fail


`TypeError: <class 'troposphere.dynamodb.CapacityAutoScalingSettings'>: None.TargetTrackingScalingPolicyConfiguration is <class 'troposphere.dynamodb.TargetTrackingScalingPolicyConfiguration'>, expected <class 'troposphere.dynamodb.TargetTrackingScalingPolicyConfiguration'>`


Patch:
diff --git a/troposphere/dynamodb.py b/troposphere/dynamodb.py
index a88a9846..1b80bc42 100644
--- a/troposphere/dynamodb.py
+++ b/troposphere/dynamodb.py
@@ -143,15 +143,6 @@ class CapacityAutoScalingSettings(AWSProperty):
     }
 
 
-class TargetTrackingScalingPolicyConfiguration(AWSProperty):
-    props = {
-        "DisableScaleIn": (boolean, False),
-        "ScaleInCooldown": (integer, False),
-        "ScaleOutCooldown": (integer, False),
-        "TargetValue": (double, True),
-    }
-
-
 class ReadProvisionedThroughputSettings(AWSProperty):
     props = {
         "ReadCapacityAutoScalingSettings": (CapacityAutoScalingSettings, False),
diff --git a/troposphere/logs.py b/troposphere/logs.py
index 306b9707..08ab8a8f 100644
--- a/troposphere/logs.py
+++ b/troposphere/logs.py
@@ -1,8 +1,9 @@
+import json
+
 from . import AWSObject, AWSProperty
 from .compat import policytypes
 from .constants import LOGS_ALLOWED_RETENTION_DAYS as RETENTION_DAYS
 from .validators import integer_list_item, json_checker
-import json
 
 policytypes = policytypes + (str,)
 
@@ -93,7 +94,7 @@ class ResourcePolicy(AWSObject):
     resource_type = "AWS::Logs::ResourcePolicy"
 
     props = {
-        "PolicyDocument": (str, True),
+        "PolicyDocument": (validate_resource_policy, True),
         "PolicyName": (str, True),
     }
 
@@ -107,12 +108,3 @@ class SubscriptionFilter(AWSObject):
         "LogGroupName": (str, True),
         "RoleArn": (str, False),
     }
-
-
-class LogResourcePolicy(AWSObject):
-    resource_type = "AWS::Logs::ResourcePolicy"
-
-    props = {
-        "PolicyDocument": (validate_resource_policy, True),
-        "PolicyName": (str, True),
-    }


Test patch:
diff --git a/tests/test_logs.py b/tests/test_logs.py
index 3fdce641..24b0cafe 100644
--- a/tests/test_logs.py
+++ b/tests/test_logs.py
@@ -1,7 +1,12 @@
 import unittest
 
 from troposphere import Retain
-from troposphere.logs import Destination, LogGroup, validate_resource_policy, LogResourcePolicy
+from troposphere.logs import (
+    Destination,
+    LogGroup,
+    ResourcePolicy,
+    validate_resource_policy,
+)
 
 
 class TestLogs(unittest.TestCase):
@@ -36,18 +41,30 @@ class TestLogs(unittest.TestCase):
         self.assertIn("Properties", log_destination_json)
 
     def test_validate_resource_policy(self):
-        for s in ["{ \"Version\": \"2012-10-17\", \"Statement\": [ { \"Sid\": \"Route53LogsToCloudWatchLogs\", \"Effect\": \"Allow\", \"Principal\": { \"Service\": [ \"route53.amazonaws.com\" ] }, \"Action\":\"logs:PutLogEvents\", \"Resource\": \"logArn\" } ] }", {'Version': '2012-10-17', 'Statement': [{'Sid': 'Route53LogsToCloudWatchLogs', 'Effect': 'Allow', 'Principal': {'Service': ['route53.amazonaws.com']}, 'Action': 'logs:PutLogEvents', 'Resource': 'logArn'}]}]:
+        for s in [
+            '{ "Version": "2012-10-17", "Statement": [ { "Sid": "Route53LogsToCloudWatchLogs", "Effect": "Allow", "Principal": { "Service": [ "route53.amazonaws.com" ] }, "Action":"logs:PutLogEvents", "Resource": "logArn" } ] }',
+            {
+                "Version": "2012-10-17",
+                "Statement": [
+                    {
+                        "Sid": "Route53LogsToCloudWatchLogs",
+                        "Effect": "Allow",
+                        "Principal": {"Service": ["route53.amazonaws.com"]},
+                        "Action": "logs:PutLogEvents",
+                        "Resource": "logArn",
+                    }
+                ],
+            },
+        ]:
             validate_resource_policy(s)
-            log_policy = LogResourcePolicy(
-                "TestLogPolicy",
-                PolicyName='TestLogPolicy',
-                PolicyDocument=s
+            log_policy = ResourcePolicy(
+                "TestLogPolicy", PolicyName="TestLogPolicy", PolicyDocument=s
             )
             expected = log_policy.to_dict()
-            properties = expected['Properties']
-            self.assertEqual(properties.get('PolicyDocument'), s)
+            properties = expected["Properties"]
+            self.assertEqual(properties.get("PolicyDocument"), s)
 
-        for s in ["", "H"*5121, "TEXT", {}]:
+        for s in ["", "H" * 5121, "TEXT", {}]:
             with self.assertRaises(ValueError):
                 validate_resource_policy(s)