1
- from unittest .mock import Mock , patch
2
1
from unittest import TestCase
3
2
4
3
from samtranslator .model .eventsources .push import Schedule
5
4
from samtranslator .model .lambda_ import LambdaFunction
6
5
from samtranslator .model .exceptions import InvalidEventException
6
+ from parameterized import parameterized
7
7
8
8
9
9
class ScheduleEventSource (TestCase ):
@@ -13,6 +13,27 @@ def setUp(self):
13
13
self .schedule_event_source .Schedule = "rate(1 minute)"
14
14
self .func = LambdaFunction ("func" )
15
15
16
+ def test_to_cloudformation_returns_permission_and_schedule_resources (self ):
17
+ resources = self .schedule_event_source .to_cloudformation (function = self .func )
18
+ self .assertEqual (len (resources ), 2 )
19
+ self .assertEqual (resources [0 ].resource_type , "AWS::Events::Rule" )
20
+ self .assertEqual (resources [1 ].resource_type , "AWS::Lambda::Permission" )
21
+
22
+ schedule = resources [0 ]
23
+ self .assertEqual (schedule .ScheduleExpression , "rate(1 minute)" )
24
+ self .assertIsNone (schedule .State )
25
+
26
+ def test_to_cloudformation_transforms_enabled_boolean_to_state (self ):
27
+ self .schedule_event_source .Enabled = True
28
+ resources = self .schedule_event_source .to_cloudformation (function = self .func )
29
+ schedule = resources [0 ]
30
+ self .assertEqual (schedule .State , "ENABLED" )
31
+
32
+ self .schedule_event_source .Enabled = False
33
+ resources = self .schedule_event_source .to_cloudformation (function = self .func )
34
+ schedule = resources [0 ]
35
+ self .assertEqual (schedule .State , "DISABLED" )
36
+
16
37
def test_to_cloudformation_with_retry_policy (self ):
17
38
retry_policy = {"MaximumRetryAttempts" : "10" , "MaximumEventAgeInSeconds" : "300" }
18
39
self .schedule_event_source .RetryPolicy = retry_policy
@@ -70,3 +91,19 @@ def test_to_cloudformation_with_dlq_generated_with_intrinsic_function_custom_log
70
91
self .schedule_event_source .DeadLetterConfig = dead_letter_config
71
92
with self .assertRaises (InvalidEventException ):
72
93
self .schedule_event_source .to_cloudformation (function = self .func )
94
+
95
+ @parameterized .expand (
96
+ [
97
+ (True , "Enabled" ),
98
+ (True , "Disabled" ),
99
+ (True , {"FN:FakeIntrinsic" : "something" }),
100
+ (False , "Enabled" ),
101
+ (False , "Disabled" ),
102
+ (False , {"FN:FakeIntrinsic" : "something" }),
103
+ ]
104
+ )
105
+ def test_to_cloudformation_invalid_defined_both_enabled_and_state_provided (self , enabled_value , state_value ):
106
+ self .schedule_event_source .Enabled = enabled_value
107
+ self .schedule_event_source .State = state_value
108
+ with self .assertRaises (InvalidEventException ):
109
+ self .schedule_event_source .to_cloudformation (function = self .func )
0 commit comments