This code adds the ability to add Mako template lookup directories on
the fly, allowing third party add-ons to contribute their own Mako templates.
A new API function for registering Mako templates is introduced::
from edxmako import add_lookup
add_lookup('main', '/path/to/templates')
# Or, specify a package to lookup using pkg_resources. This will
# add the 'templates' directory inside the current package:
add_lookup('main', 'templates', package=__name__)
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""
|
|
Test `massemail` and `massemailtxt` commands.
|
|
"""
|
|
import mock
|
|
import pkg_resources
|
|
|
|
from django.core import mail
|
|
from django.test import TestCase
|
|
|
|
from edxmako import add_lookup
|
|
from ..management.commands import massemail
|
|
from ..management.commands import massemailtxt
|
|
|
|
|
|
class TestMassEmailCommands(TestCase):
|
|
"""
|
|
Test `massemail` and `massemailtxt` commands.
|
|
"""
|
|
|
|
@mock.patch('edxmako.LOOKUP', {})
|
|
def test_massemailtxt(self):
|
|
"""
|
|
Test the `massemailtext` command.
|
|
"""
|
|
add_lookup('main', '', package=__name__)
|
|
userfile = pkg_resources.resource_filename(__name__, 'test_massemail_users.txt')
|
|
command = massemailtxt.Command()
|
|
command.handle(userfile, 'test', '/dev/null', 10)
|
|
self.assertEqual(len(mail.outbox), 2)
|
|
self.assertEqual(mail.outbox[0].to, ["Fred"])
|
|
self.assertEqual(mail.outbox[0].subject, "Test subject.")
|
|
self.assertEqual(mail.outbox[0].body.strip(), "Test body.")
|
|
self.assertEqual(mail.outbox[1].to, ["Barney"])
|
|
self.assertEqual(mail.outbox[1].subject, "Test subject.")
|
|
self.assertEqual(mail.outbox[1].body.strip(), "Test body.")
|
|
|
|
@mock.patch('edxmako.LOOKUP', {})
|
|
@mock.patch('student.management.commands.massemail.User')
|
|
def test_massemail(self, usercls):
|
|
"""
|
|
Test the `massemail` command.
|
|
"""
|
|
add_lookup('main', '', package=__name__)
|
|
fred = mock.Mock()
|
|
barney = mock.Mock()
|
|
usercls.objects.all.return_value = [fred, barney]
|
|
command = massemail.Command()
|
|
command.handle('test')
|
|
fred.email_user.assert_called_once_with('Test subject.', 'Test body.\n')
|
|
barney.email_user.assert_called_once_with('Test subject.', 'Test body.\n')
|