@@ -64,6 +64,9 @@ def test_send_mail(self):
6464 # make sure backend assigned a Message-ID for event tracking
6565 email_headers = json .loads (data ['headers' ])
6666 self .assertRegex (email_headers ['Message-ID' ], r'\<.+@sender\.example\.com\>' ) # id uses from_email's domain
67+ # make sure we added the unquoted Message-ID to unique_args for event notification
68+ smtpapi = self .get_smtpapi ()
69+ self .assertEqual (email_headers ['Message-ID' ], '<{}>' .format (smtpapi ['unique_args' ]['smtp-id' ]))
6770
6871 @override_settings (ANYMAIL = {'SENDGRID_USERNAME' : 'sg_username' , 'SENDGRID_PASSWORD' : 'sg_password' })
6972 def test_user_pass_auth (self ):
@@ -124,6 +127,10 @@ def test_email_message(self):
124127125128 'X-MyHeader' : 'my value' ,
126129 })
130+ # make sure custom Message-ID also added to unique_args
131+ self .assertJSONEqual (data ['x-smtpapi' ], {
132+ 'unique_args' : {
'smtp-id' :
'[email protected] ' }
133+ })
127134
128135 def test_html_message (self ):
129136 text_content = 'This is an important message.'
@@ -347,6 +354,7 @@ def test_metadata(self):
347354 self .message .metadata = {'user_id' : "12345" , 'items' : 6 }
348355 self .message .send ()
349356 smtpapi = self .get_smtpapi ()
357+ smtpapi ['unique_args' ].pop ('smtp-id' , None ) # remove Message-ID we added as tracking workaround
350358 self .assertEqual (smtpapi ['unique_args' ], {'user_id' : "12345" , 'items' : 6 })
351359
352360 def test_send_at (self ):
@@ -401,6 +409,7 @@ def test_tracking(self):
401409 self .assertEqual (smtpapi ['filters' ]['clicktrack' ], {'settings' : {'enable' : 1 }})
402410 self .assertEqual (smtpapi ['filters' ]['opentrack' ], {'settings' : {'enable' : 0 }})
403411
412+ @override_settings (ANYMAIL_SENDGRID_GENERATE_MESSAGE_ID = False ) # else we force unique_args
404413 def test_default_omits_options (self ):
405414 """Make sure by default we don't send any ESP-specific options.
406415
@@ -508,6 +517,7 @@ def test_send_defaults(self):
508517 data = self .get_api_call_data ()
509518 smtpapi = self .get_smtpapi ()
510519 # All these values came from ANYMAIL_SEND_DEFAULTS:
520+ smtpapi ['unique_args' ].pop ('smtp-id' , None ) # remove Message-ID we added as tracking workaround
511521 self .assertEqual (smtpapi ['unique_args' ], {'global' : 'globalvalue' , 'other' : 'othervalue' })
512522 self .assertEqual (smtpapi ['category' ], ['globaltag' ])
513523 self .assertEqual (smtpapi ['filters' ]['clicktrack' ]['settings' ]['enable' ], 1 )
@@ -525,6 +535,7 @@ def test_merge_message_with_send_defaults(self):
525535 data = self .get_api_call_data ()
526536 smtpapi = self .get_smtpapi ()
527537 # All these values came from ANYMAIL_SEND_DEFAULTS + message.*:
538+ smtpapi ['unique_args' ].pop ('smtp-id' , None ) # remove Message-ID we added as tracking workaround
528539 self .assertEqual (smtpapi ['unique_args' ], {
529540 'global' : 'globalvalue' ,
530541 'message' : 'messagevalue' , # additional metadata
@@ -547,6 +558,7 @@ def test_esp_send_defaults(self):
547558 data = self .get_api_call_data ()
548559 smtpapi = self .get_smtpapi ()
549560 # All these values came from ANYMAIL_SEND_DEFAULTS plus ANYMAIL_SENDGRID_SEND_DEFAULTS:
561+ smtpapi ['unique_args' ].pop ('smtp-id' , None ) # remove Message-ID we added as tracking workaround
550562 self .assertEqual (smtpapi ['unique_args' ], {'esp' : 'espvalue' }) # entire metadata overridden
551563 self .assertCountEqual (smtpapi ['category' ], ['esptag' ]) # entire tags overridden
552564 self .assertEqual (smtpapi ['filters' ]['clicktrack' ]['settings' ]['enable' ], 1 ) # no override
0 commit comments