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_notification.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from django.test import TestCase
  2. from oscar.apps.communication.models import Notification
  3. from oscar.core.compat import get_user_model
  4. from oscar.core.loading import get_class
  5. from oscar.test.factories import UserFactory
  6. User = get_user_model()
  7. Dispatcher = get_class('communication.utils', 'Dispatcher')
  8. class TestANewNotification(TestCase):
  9. def setUp(self):
  10. self.notification = Notification(
  11. recipient=UserFactory(),
  12. subject="Hello")
  13. def test_is_in_a_users_inbox(self):
  14. assert Notification.INBOX == self.notification.location
  15. def test_is_not_read(self):
  16. assert not self.notification.is_read
  17. class TestANotification(TestCase):
  18. def setUp(self):
  19. self.notification = Notification.objects.create(
  20. recipient=UserFactory(),
  21. subject="Hello")
  22. def test_can_be_archived(self):
  23. self.notification.archive()
  24. assert Notification.ARCHIVE == self.notification.location
  25. class NotificationServiceTestCase(TestCase):
  26. def test_notify_a_single_user(self):
  27. user = UserFactory()
  28. subj = "Hello you!"
  29. body = "This is the notification body."
  30. Dispatcher().notify_user(user, subj, body=body)
  31. user_notification = Notification.objects.get(recipient=user)
  32. assert user_notification.subject == subj
  33. assert user_notification.body == body
  34. def test_notify_a_set_of_users(self):
  35. users = UserFactory.create_batch(3)
  36. subj = "Hello everyone!"
  37. body = "This is the notification body."
  38. Dispatcher().notify_users(User.objects.all(), subj, body=body)
  39. for user in users:
  40. user_notification = Notification.objects.get(recipient=user)
  41. assert user_notification.subject == subj
  42. assert user_notification.body == body