您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test_customer.py 1.2KB

12345678910111213141516171819202122232425262728293031323334
  1. from django.test import TestCase
  2. from oscar.apps.customer.models import CommunicationEventType
  3. from oscar.core.compat import get_user_model
  4. User = get_user_model()
  5. class CommunicationTypeTest(TestCase):
  6. keys = ('body', 'html', 'sms', 'subject')
  7. def test_no_templates_returns_empty_string(self):
  8. et = CommunicationEventType()
  9. messages = et.get_messages()
  10. for key in self.keys:
  11. self.assertEqual('', messages[key])
  12. def test_field_template_render(self):
  13. et = CommunicationEventType(email_subject_template='Hello {{ name }}')
  14. ctx = {'name': 'world'}
  15. messages = et.get_messages(ctx)
  16. self.assertEqual('Hello world', messages['subject'])
  17. def test_new_line_in_subject_is_removed(self):
  18. subjects = [
  19. ('Subject with a newline\r\n', 'Subject with a newline'),
  20. ('New line is in \n the middle', 'New line is in the middle'),
  21. ('\rStart with the new line', 'Start with the new line'),
  22. ]
  23. for original, modified in subjects:
  24. et = CommunicationEventType(email_subject_template=original)
  25. messages = et.get_messages()
  26. self.assertEqual(modified, messages['subject'])