|
10 | 10 | EmailMessage = message.Message
|
11 | 11 |
|
12 | 12 | from sendgrid.helpers.mail import (
|
13 |
| - Asm, ApiKeyIncludedException, Attachment, BccSettings, |
14 |
| - BypassListManagement, Category, ClickTracking, Content, CustomArg, |
15 |
| - DynamicTemplateData, Email, FooterSettings, From, Ganalytics, Header, |
16 |
| - Mail, MailSettings, OpenTracking, Personalization, SandBoxMode, Section, |
17 |
| - SendGridException, SpamCheck, Subject, SubscriptionTracking, Substitution, |
18 |
| - TrackingSettings, To, ValidateApiKey |
| 13 | + Asm, Attachment, |
| 14 | + ClickTracking, Content, |
| 15 | + DynamicTemplateData, Email, From, |
| 16 | + Mail, Personalization, |
| 17 | + Subject, Substitution, To, TrackingSettings |
19 | 18 | )
|
20 | 19 |
|
21 | 20 |
|
@@ -210,18 +209,18 @@ def test_multiple_emails_to_multiple_recipients(self):
|
210 | 209 |
|
211 | 210 | to_emails = [
|
212 | 211 |
|
213 |
| - name='Example Name 0', |
214 |
| - substitutions=[ |
215 |
| - Substitution('-name-', 'Example Name Substitution 0'), |
216 |
| - Substitution('-github-', 'https://example.com/test0'), |
217 |
| - ], |
218 |
| - subject=Subject('Override Global Subject')), |
| 212 | + name='Example Name 0', |
| 213 | + substitutions=[ |
| 214 | + Substitution('-name-', 'Example Name Substitution 0'), |
| 215 | + Substitution('-github-', 'https://example.com/test0'), |
| 216 | + ], |
| 217 | + subject=Subject('Override Global Subject')), |
219 | 218 |
|
220 |
| - name='Example Name 1', |
221 |
| - substitutions=[ |
222 |
| - Substitution('-name-', 'Example Name Substitution 1'), |
223 |
| - Substitution('-github-', 'https://example.com/test1'), |
224 |
| - ]) |
| 219 | + name='Example Name 1', |
| 220 | + substitutions=[ |
| 221 | + Substitution('-name-', 'Example Name Substitution 1'), |
| 222 | + Substitution('-github-', 'https://example.com/test1'), |
| 223 | + ]) |
225 | 224 | ]
|
226 | 225 | global_substitutions = Substitution('-time-', '2019-01-01 00:00:00')
|
227 | 226 | message = Mail(
|
@@ -285,6 +284,70 @@ def test_multiple_emails_to_multiple_recipients(self):
|
285 | 284 | }''')
|
286 | 285 | )
|
287 | 286 |
|
| 287 | + def test_dynamic_template_data(self): |
| 288 | + self.maxDiff = None |
| 289 | + |
| 290 | + to_emails = [ |
| 291 | + |
| 292 | + name='Example To 0 Name', |
| 293 | + dynamic_template_data=DynamicTemplateData({'name': 'Example 0 Name'})), |
| 294 | + |
| 295 | + name='Example To 1 Name', |
| 296 | + dynamic_template_data={'name': 'Example 1 Name'}) |
| 297 | + ] |
| 298 | + message = Mail( |
| 299 | + from_email=From( '[email protected]', 'Example From Name'), |
| 300 | + to_emails=to_emails, |
| 301 | + subject=Subject('Hi!'), |
| 302 | + plain_text_content='Hello!', |
| 303 | + html_content='<strong>Hello!</strong>', |
| 304 | + is_multiple=True) |
| 305 | + |
| 306 | + self.assertEqual( |
| 307 | + message.get(), |
| 308 | + json.loads(r'''{ |
| 309 | + "content": [ |
| 310 | + { |
| 311 | + "type": "text/plain", |
| 312 | + "value": "Hello!" |
| 313 | + }, |
| 314 | + { |
| 315 | + "type": "text/html", |
| 316 | + "value": "<strong>Hello!</strong>" |
| 317 | + } |
| 318 | + ], |
| 319 | + "from": { |
| 320 | + |
| 321 | + "name": "Example From Name" |
| 322 | + }, |
| 323 | + "personalizations": [ |
| 324 | + { |
| 325 | + "dynamic_template_data": { |
| 326 | + "name": "Example 1 Name" |
| 327 | + }, |
| 328 | + "to": [ |
| 329 | + { |
| 330 | + |
| 331 | + "name": "Example To 1 Name" |
| 332 | + } |
| 333 | + ] |
| 334 | + }, |
| 335 | + { |
| 336 | + "dynamic_template_data": { |
| 337 | + "name": "Example 0 Name" |
| 338 | + }, |
| 339 | + "to": [ |
| 340 | + { |
| 341 | + |
| 342 | + "name": "Example To 0 Name" |
| 343 | + } |
| 344 | + ] |
| 345 | + } |
| 346 | + ], |
| 347 | + "subject": "Hi!" |
| 348 | + }''') |
| 349 | + ) |
| 350 | + |
288 | 351 | def test_kitchen_sink(self):
|
289 | 352 | from sendgrid.helpers.mail import (
|
290 | 353 | Mail, From, To, Cc, Bcc, Subject, Substitution, Header,
|
|
0 commit comments