@@ -75,19 +75,119 @@ def test_orchestration_trigger_has_implicit_return(self):
75
75
OrchestrationTriggerConverter .has_implicit_output ()
76
76
)
77
77
78
- def test_activity_trigger_accepts_any_types (self ):
79
- datum_set = {
80
- Datum ('string' , str ),
81
- Datum (123 , int ),
82
- Datum (1234.56 , float ),
83
- Datum ('string' .encode ('utf-8' ), bytes ),
84
- Datum (Datum ('{ "json": true }' , str ), Datum )
85
- }
86
-
87
- for datum in datum_set :
88
- out = ActivityTriggerConverter .decode (datum , trigger_metadata = None )
89
- self .assertEqual (out , datum .value )
90
- self .assertEqual (type (out ), datum .type )
78
+ def test_activity_trigger_inputs (self ):
79
+ # Activity Trigger only accept string type from durable extensions
80
+ # It will be JSON deserialized into expected data type
81
+ data = [
82
+ {
83
+ 'input' : Datum ('sample' , 'string' ),
84
+ 'expected_value' : 'sample' ,
85
+ 'expected_type' : str
86
+ },
87
+ {
88
+ 'input' : Datum ('123' , 'string' ),
89
+ 'expected_value' : 123 ,
90
+ 'expected_type' : int
91
+ },
92
+ {
93
+ 'input' : Datum ('1234.56' , 'string' ),
94
+ 'expected_value' : 1234.56 ,
95
+ 'expected_type' : float
96
+ },
97
+ {
98
+ 'input' : Datum ('[ "do", "re", "mi" ]' , 'string' ),
99
+ 'expected_value' : ["do" , "re" , "mi" ],
100
+ 'expected_type' : list
101
+ },
102
+ {
103
+ 'input' : Datum ('{ "number": "42" }' , 'string' ),
104
+ 'expected_value' : {"number" : "42" },
105
+ 'expected_type' : dict
106
+ }
107
+ ]
108
+
109
+ for datum in data :
110
+ decoded = ActivityTriggerConverter .decode (
111
+ data = datum ['input' ],
112
+ trigger_metadata = None )
113
+ self .assertEqual (decoded , datum ['expected_value' ])
114
+ self .assertEqual (type (decoded ), datum ['expected_type' ])
115
+
116
+ def test_activity_trigger_encode (self ):
117
+ # Activity Trigger allow any JSON serializable as outputs
118
+ # The return value will be carried back to the Orchestrator function
119
+ data = [
120
+ {
121
+ 'output' : str ('sample' ),
122
+ 'expected_value' : Datum ('"sample"' , 'json' ),
123
+ },
124
+ {
125
+ 'output' : int (123 ),
126
+ 'expected_value' : Datum ('123' , 'json' ),
127
+ },
128
+ {
129
+ 'output' : float (1234.56 ),
130
+ 'expected_value' : Datum ('1234.56' , 'json' )
131
+ },
132
+ {
133
+ 'output' : list (["do" , "re" , "mi" ]),
134
+ 'expected_value' : Datum ('["do", "re", "mi"]' , 'json' )
135
+ },
136
+ {
137
+ 'output' : dict ({"number" : "42" }),
138
+ 'expected_value' : Datum ('{"number": "42"}' , 'json' )
139
+ }
140
+ ]
141
+
142
+ for datum in data :
143
+ encoded = ActivityTriggerConverter .encode (
144
+ obj = datum ['output' ],
145
+ expected_type = type (datum ['output' ]))
146
+ self .assertEqual (encoded , datum ['expected_value' ])
147
+
148
+ def test_activity_trigger_decode (self ):
149
+ # Activity Trigger allow inputs to be any JSON serializables
150
+ # The input values to the trigger should be passed into arguments
151
+ data = [
152
+ {
153
+ 'input' : Datum ('sample_string' , 'string' ),
154
+ 'expected_value' : str ('sample_string' )
155
+ },
156
+ {
157
+ 'input' : Datum ('"sample_json_string"' , 'json' ),
158
+ 'expected_value' : str ('sample_json_string' )
159
+ },
160
+ {
161
+ 'input' : Datum ('{ "invalid": "json"' , 'json' ),
162
+ 'expected_value' : str ('{ "invalid": "json"' )
163
+ },
164
+ {
165
+ 'input' : Datum ('true' , 'json' ),
166
+ 'expected_value' : bool (True ),
167
+ },
168
+ {
169
+ 'input' : Datum ('123' , 'json' ),
170
+ 'expected_value' : int (123 ),
171
+ },
172
+ {
173
+ 'input' : Datum ('1234.56' , 'json' ),
174
+ 'expected_value' : float (1234.56 )
175
+ },
176
+ {
177
+ 'input' : Datum ('["do", "re", "mi"]' , 'json' ),
178
+ 'expected_value' : list (["do" , "re" , "mi" ])
179
+ },
180
+ {
181
+ 'input' : Datum ('{"number": "42"}' , 'json' ),
182
+ 'expected_value' : dict ({"number" : "42" })
183
+ }
184
+ ]
185
+
186
+ for datum in data :
187
+ decoded = ActivityTriggerConverter .decode (
188
+ data = datum ['input' ],
189
+ trigger_metadata = None )
190
+ self .assertEqual (decoded , datum ['expected_value' ])
91
191
92
192
def test_activity_trigger_has_implicit_return (self ):
93
193
self .assertTrue (
0 commit comments