SendGrid: merge 'filters' in esp_extra

Previously, setting esp_extra['x-smtpapi']['filters']
would override the entire filters setting, potentially
undoing other Anymail options that use SendGrid
filters (like track_opens).

Now, 'filters' is special-cased, and merged with
any other Anymail filter options.

(We don't do a fully deep merge, because otherwise
there would be no way to use esp_extra to *clear*
Anymail settings.)
This commit is contained in:
medmunds
2016-04-30 10:21:11 -07:00
parent a26d284772
commit 1372ef21eb
4 changed files with 52 additions and 18 deletions

View File

@@ -423,18 +423,35 @@ class SendGridBackendAnymailFeatureTests(SendGridBackendMockAPITestCase):
def test_esp_extra(self):
self.message.tags = ["tag"]
self.message.track_clicks = True
self.message.esp_extra = {
'x-smtpapi': {'asm_group_id': 1},
'x-smtpapi': {
# Most SendMail options go in the 'x-smtpapi' block...
'asm_group_id': 1,
'filters': {
# If you add a filter, you must supply all required settings for it.
'subscriptiontrack': {
'settings': {
'enable': 1,
'replace': '[unsubscribe_url]',
},
},
},
},
'newthing': "some param not supported by Anymail",
}
self.message.send()
# Additional send params:
data = self.get_api_call_data()
self.assertEqual(data['newthing'], "some param not supported by Anymail")
# Should merge x-smtpapi
# Should merge x-smtpapi, and merge filters within x-smtpapi
smtpapi = self.get_smtpapi()
self.assertEqual(smtpapi['category'], ["tag"])
self.assertEqual(smtpapi['asm_group_id'], 1)
self.assertEqual(smtpapi['filters']['subscriptiontrack'],
{'settings': {'enable': 1, 'replace': '[unsubscribe_url]'}}) # esp_extra merged
self.assertEqual(smtpapi['filters']['clicktrack'],
{'settings': {'enable': 1}}) # Anymail message option preserved
# noinspection PyUnresolvedReferences
def test_send_attaches_anymail_status(self):