Correct name/content lists for template_content, merge_vars, global_merge_vars.

Fixes #24.
This commit is contained in:
medmunds
2013-01-13 08:16:40 -08:00
parent 6480e4f361
commit ed3249cede
3 changed files with 13 additions and 13 deletions

View File

@@ -173,12 +173,12 @@ class DjrillBackend(BaseEmailBackend):
def _expand_merge_vars(self, vars): def _expand_merge_vars(self, vars):
"""Convert a Python dict to an array of name-value used by Mandrill. """Convert a Python dict to an array of name-content used by Mandrill.
{ name: value, ... } --> [ {'name': name, 'value': value }, ... ] { name: value, ... } --> [ {'name': name, 'content': value }, ... ]
""" """
# For testing reproducibility, we sort the keys # For testing reproducibility, we sort the keys
return [ { 'name': name, 'value': vars[name] } return [ { 'name': name, 'content': vars[name] }
for name in sorted(vars.keys()) ] for name in sorted(vars.keys()) ]
def _add_alternatives(self, message, msg_dict): def _add_alternatives(self, message, msg_dict):

View File

@@ -249,7 +249,7 @@ class DjrillMandrillFeatureTests(DjrillBackendMockAPITestCase):
self.assertEqual(data['message']['preserve_recipients'], True) self.assertEqual(data['message']['preserve_recipients'], True)
def test_merge(self): def test_merge(self):
# Djrill expands simple python dicts into the more-verbose name/value # Djrill expands simple python dicts into the more-verbose name/content
# structures the Mandrill API uses # structures the Mandrill API uses
self.message.global_merge_vars = { 'GREETING': "Hello", self.message.global_merge_vars = { 'GREETING': "Hello",
'ACCOUNT_TYPE': "Basic" } 'ACCOUNT_TYPE': "Basic" }
@@ -261,14 +261,14 @@ class DjrillMandrillFeatureTests(DjrillBackendMockAPITestCase):
self.message.send() self.message.send()
data = self.get_api_call_data() data = self.get_api_call_data()
self.assertEqual(data['message']['global_merge_vars'], self.assertEqual(data['message']['global_merge_vars'],
[ {'name': 'ACCOUNT_TYPE', 'value': "Basic"}, [ {'name': 'ACCOUNT_TYPE', 'content': "Basic"},
{'name': "GREETING", 'value': "Hello"} ]) {'name': "GREETING", 'content': "Hello"} ])
self.assertEqual(data['message']['merge_vars'], self.assertEqual(data['message']['merge_vars'],
[ { 'rcpt': "customer@example.com", [ { 'rcpt': "customer@example.com",
'vars': [{ 'name': 'ACCOUNT_TYPE', 'value': "Premium" }, 'vars': [{ 'name': 'ACCOUNT_TYPE', 'content': "Premium" },
{ 'name': "GREETING", 'value': "Dear Customer"}] }, { 'name': "GREETING", 'content': "Dear Customer"}] },
{ 'rcpt': "guest@example.com", { 'rcpt': "guest@example.com",
'vars': [{ 'name': "GREETING", 'value': "Dear Guest"}] } 'vars': [{ 'name': "GREETING", 'content': "Dear Guest"}] }
]) ])
def test_tags(self): def test_tags(self):
@@ -291,7 +291,7 @@ class DjrillMandrillFeatureTests(DjrillBackendMockAPITestCase):
self.message.metadata = { 'batch_num': "12345", 'type': "Receipts" } self.message.metadata = { 'batch_num': "12345", 'type': "Receipts" }
self.message.recipient_metadata = { self.message.recipient_metadata = {
# Djrill expands simple python dicts into the more-verbose # Djrill expands simple python dicts into the more-verbose
# name/value structures the Mandrill API uses # rcpt/values structures the Mandrill API uses
"customer@example.com": { 'cust_id': "67890", 'order_id': "54321" }, "customer@example.com": { 'cust_id': "67890", 'order_id': "54321" },
"guest@example.com": { 'cust_id': "94107", 'order_id': "43215" } "guest@example.com": { 'cust_id': "94107", 'order_id': "43215" }
} }

View File

@@ -18,13 +18,13 @@ class DjrillMandrillSendTemplateTests(DjrillBackendMockAPITestCase):
self.assert_mandrill_called("/messages/send-template.json") self.assert_mandrill_called("/messages/send-template.json")
data = self.get_api_call_data() data = self.get_api_call_data()
self.assertEqual(data['template_name'], "PERSONALIZED_SPECIALS") self.assertEqual(data['template_name'], "PERSONALIZED_SPECIALS")
# Djrill expands simple python dicts into the more-verbose name/value # Djrill expands simple python dicts into the more-verbose name/content
# structures the Mandrill API uses # structures the Mandrill API uses
self.assertEqual(data['template_content'], self.assertEqual(data['template_content'],
[ {'name': "HEADLINE", [ {'name': "HEADLINE",
'value': "<h1>Specials Just For *|FNAME|*</h1>"}, 'content': "<h1>Specials Just For *|FNAME|*</h1>"},
{'name': "OFFER_BLOCK", {'name': "OFFER_BLOCK",
'value': "<p><em>Half off</em> all fruit</p>"} ] 'content': "<p><em>Half off</em> all fruit</p>"} ]
) )
def test_no_template_content(self): def test_no_template_content(self):