You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_dispatcher.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from django.test import TestCase
  2. from django.core import mail
  3. from oscar.core.compat import get_user_model
  4. from oscar.apps.customer.utils import Dispatcher
  5. from oscar.apps.customer.models import CommunicationEventType
  6. from oscar.test.factories import create_order
  7. User = get_user_model()
  8. class TestDispatcher(TestCase):
  9. def test_sending_a_order_related_messages(self):
  10. email = 'testuser@example.com'
  11. user = User.objects.create_user('testuser', email,
  12. 'somesimplepassword')
  13. order_number = '12345'
  14. order = create_order(number=order_number, user=user)
  15. et = CommunicationEventType.objects.create(code="ORDER_PLACED",
  16. name="Order Placed",
  17. category="Order related")
  18. messages = et.get_messages({
  19. 'order': order,
  20. 'lines': order.lines.all()
  21. })
  22. self.assertIn(order_number, messages['body'])
  23. self.assertIn(order_number, messages['html'])
  24. dispatcher = Dispatcher()
  25. dispatcher.dispatch_order_messages(order, messages, et)
  26. self.assertEqual(len(mail.outbox), 1)
  27. message = mail.outbox[0]
  28. self.assertIn(order_number, message.body)