mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 20:01:05 -05:00
Merge pull request #62 from expa/master
add subaccount support to djrill
This commit is contained in:
@@ -50,6 +50,8 @@ class DjrillBackend(BaseEmailBackend):
|
|||||||
self.api_key = getattr(settings, "MANDRILL_API_KEY", None)
|
self.api_key = getattr(settings, "MANDRILL_API_KEY", None)
|
||||||
self.api_url = MANDRILL_API_URL
|
self.api_url = MANDRILL_API_URL
|
||||||
|
|
||||||
|
self.subaccount = getattr(settings, "MANDRILL_SUBACCOUNT", None)
|
||||||
|
|
||||||
if not self.api_key:
|
if not self.api_key:
|
||||||
raise ImproperlyConfigured("You have not set your mandrill api key "
|
raise ImproperlyConfigured("You have not set your mandrill api key "
|
||||||
"in the settings.py file.")
|
"in the settings.py file.")
|
||||||
@@ -187,6 +189,10 @@ class DjrillBackend(BaseEmailBackend):
|
|||||||
'tags', 'preserve_recipients', 'view_content_link', 'subaccount',
|
'tags', 'preserve_recipients', 'view_content_link', 'subaccount',
|
||||||
'google_analytics_domains', 'google_analytics_campaign',
|
'google_analytics_domains', 'google_analytics_campaign',
|
||||||
'metadata']
|
'metadata']
|
||||||
|
|
||||||
|
if self.subaccount:
|
||||||
|
msg_dict['subaccount'] = self.subaccount
|
||||||
|
|
||||||
for attr in mandrill_attrs:
|
for attr in mandrill_attrs:
|
||||||
if hasattr(message, attr):
|
if hasattr(message, attr):
|
||||||
msg_dict[attr] = getattr(message, attr)
|
msg_dict[attr] = getattr(message, attr)
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ from djrill.tests.test_legacy import *
|
|||||||
from djrill.tests.test_mandrill_send import *
|
from djrill.tests.test_mandrill_send import *
|
||||||
from djrill.tests.test_mandrill_send_template import *
|
from djrill.tests.test_mandrill_send_template import *
|
||||||
from djrill.tests.test_mandrill_webhook import *
|
from djrill.tests.test_mandrill_webhook import *
|
||||||
|
from djrill.tests.test_mandrill_subaccounts import *
|
||||||
|
|||||||
36
djrill/tests/test_mandrill_subaccounts.py
Normal file
36
djrill/tests/test_mandrill_subaccounts.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
from django.core import mail
|
||||||
|
|
||||||
|
from djrill.tests.mock_backend import DjrillBackendMockAPITestCase
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
class DjrillMandrillSubaccountTests(DjrillBackendMockAPITestCase):
|
||||||
|
"""Test Djrill backend support for Mandrill subaccounts"""
|
||||||
|
|
||||||
|
def test_send_basic(self):
|
||||||
|
mail.send_mail('Subject here', 'Here is the message.',
|
||||||
|
'from@example.com', ['to@example.com'], fail_silently=False)
|
||||||
|
self.assert_mandrill_called("/messages/send.json")
|
||||||
|
data = self.get_api_call_data()
|
||||||
|
self.assertEqual(data['message']['subject'], "Subject here")
|
||||||
|
self.assertEqual(data['message']['text'], "Here is the message.")
|
||||||
|
self.assertFalse('from_name' in data['message'])
|
||||||
|
self.assertEqual(data['message']['from_email'], "from@example.com")
|
||||||
|
self.assertEqual(len(data['message']['to']), 1)
|
||||||
|
self.assertEqual(data['message']['to'][0]['email'], "to@example.com")
|
||||||
|
self.assertFalse('subaccount' in data['message'])
|
||||||
|
|
||||||
|
def test_send_from_subaccount(self):
|
||||||
|
settings.MANDRILL_SUBACCOUNT = "test_subaccount"
|
||||||
|
|
||||||
|
mail.send_mail('Subject here', 'Here is the message.',
|
||||||
|
'from@example.com', ['to@example.com'], fail_silently=False)
|
||||||
|
self.assert_mandrill_called("/messages/send.json")
|
||||||
|
data = self.get_api_call_data()
|
||||||
|
self.assertEqual(data['message']['subject'], "Subject here")
|
||||||
|
self.assertEqual(data['message']['text'], "Here is the message.")
|
||||||
|
self.assertFalse('from_name' in data['message'])
|
||||||
|
self.assertEqual(data['message']['from_email'], "from@example.com")
|
||||||
|
self.assertEqual(len(data['message']['to']), 1)
|
||||||
|
self.assertEqual(data['message']['to'][0]['email'], "to@example.com")
|
||||||
|
self.assertEqual(data['message']['subaccount'], settings.MANDRILL_SUBACCOUNT)
|
||||||
Reference in New Issue
Block a user