@@ -186,69 +186,117 @@ def test_campaign():
186
186
assert actual == expected
187
187
188
188
189
- def test_metadata ():
189
+ def test_recipient_attributes ():
190
190
email_message = EmailMessage (
191
191
to = [
192
192
{
193
193
194
+ 'substitution_data' : {
195
+ 'sub' : 'value'
196
+ },
194
197
'metadata' : {
195
- 'key' : 'value'
196
- }
198
+ 'meta' : 'value'
199
+ },
200
+ 'tags' : ['tag1' ]
197
201
}
198
202
],
199
203
200
204
)
205
+
201
206
email_message .template = 'template-id'
202
- email_message .metadata = {'key2' : 'value2' }
203
207
actual = SparkPostMessage (email_message )
204
208
205
209
expected = dict (
206
210
recipients = [
207
211
{
208
212
213
+ 'substitution_data' : {
214
+ 'sub' : 'value'
215
+ },
209
216
'metadata' : {
210
- 'key' : 'value'
211
- }
217
+ 'meta' : 'value'
218
+ },
219
+ 'tags' : ['tag1' ]
212
220
}
213
221
],
214
222
223
+ template = 'template-id'
224
+ )
225
+
226
+ assert actual == expected
227
+
228
+
229
+ def test_pass_through_attr ():
230
+
231
+ pass_through_attributes = {
232
+ 'substitution_data' : {'sub' : 'vale' },
233
+ 'metadata' : {'meta' : 'value' },
234
+ 'description' : 'a description' ,
235
+ 'return_path' :
'[email protected] ' ,
236
+ 'ip_pool' : 'pool-id' ,
237
+ 'inline_css' : True ,
238
+ 'transactional' : True ,
239
+ 'start_time' : 'YYYY-MM-DDTHH:MM:SS+-HH:MM' ,
240
+ 'skip_suppression' : True
241
+ }
242
+
243
+ email_message = EmailMessage (
244
+ to = [{
'address' :
'[email protected] ' }],
245
+
246
+ )
247
+ email_message .template = 'template-id'
248
+
249
+ for key , value in pass_through_attributes .items ():
250
+ setattr (email_message , key , value )
251
+
252
+ actual = SparkPostMessage (email_message )
253
+
254
+ expected = dict (
255
+ recipients = [{
'address' :
'[email protected] ' }],
256
+
215
257
template = 'template-id' ,
216
- metadata = {'key2' : 'value2' }
217
258
)
218
259
260
+ for key , value in pass_through_attributes .items ():
261
+ expected [key ] = value
262
+
219
263
assert actual == expected
220
264
221
265
222
- def test_substitution_data ():
266
+ def test_transform_attr ():
267
+
268
+ attributes_to_transform = {
269
+ 'sandbox' : True ,
270
+ 'open_tracking' : False ,
271
+ 'click_tracking' : False ,
272
+ }
273
+
223
274
email_message = EmailMessage (
224
- to = [
225
- {
226
-
227
- 'substitution_data' : {
228
- 'key' : 'value'
229
- }
230
- }
231
- ],
275
+ to = [{
'address' :
'[email protected] ' }],
232
276
233
277
)
234
278
email_message .template = 'template-id'
235
- email_message .substitution_data = {'key2' : 'value2' }
279
+
280
+ for key , value in attributes_to_transform .items ():
281
+ setattr (email_message , key , value )
282
+
236
283
actual = SparkPostMessage (email_message )
237
284
238
285
expected = dict (
239
- recipients = [
240
- {
241
-
242
- 'substitution_data' : {
243
- 'key' : 'value'
244
- }
245
- }
246
- ],
286
+ recipients = [{
'address' :
'[email protected] ' }],
247
287
248
288
template = 'template-id' ,
249
- substitution_data = {'key2' : 'value2' }
250
289
)
251
290
291
+ transformed_attributes = {
292
+ 'use_sandbox' : True ,
293
+ 'track_opens' : False ,
294
+ 'track_clicks' : False
295
+ }
296
+
297
+ for key , value in transformed_attributes .items ():
298
+ expected [key ] = value
299
+
252
300
assert actual == expected
253
301
254
302
0 commit comments