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_communication.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from django.core import mail
  2. from django.urls import reverse
  3. from oscar.core.loading import get_model
  4. from oscar.test.factories import UserFactory
  5. from oscar.test.testcases import WebTestCase
  6. CommunicationEventType = get_model('communication', 'CommunicationEventType')
  7. class TestAnAdmin(WebTestCase):
  8. def setUp(self):
  9. self.staff = UserFactory(is_staff=True, username='1234')
  10. self.commtype = CommunicationEventType.objects.create(
  11. name="Password reset",
  12. category=CommunicationEventType.USER_RELATED)
  13. def test_can_preview_an_email(self):
  14. list_page = self.app.get(
  15. reverse('dashboard:comms-list'), user=self.staff)
  16. update_page = list_page.click('Edit')
  17. form = update_page.form
  18. form['email_subject_template'] = 'Hello {{ user.username }}'
  19. form['email_body_template'] = 'Hello {{ user.username }}'
  20. form['email_body_html_template'] = 'Hello {{ user.username }}'
  21. preview = form.submit('show_preview')
  22. assert 'Hello 1234' in preview.content.decode('utf8')
  23. def test_can_send_a_preview_email(self):
  24. list_page = self.app.get(
  25. reverse('dashboard:comms-list'), user=self.staff)
  26. update_page = list_page.click('Edit')
  27. form = update_page.form
  28. form['email_subject_template'] = 'Hello {{ user.username }}'
  29. form['email_body_template'] = 'Hello {{ user.username }}'
  30. form['email_body_html_template'] = 'Hello {{ user.username }}'
  31. form['preview_email'] = 'testing@example.com'
  32. form.submit('send_preview')
  33. assert len(mail.outbox) == 1