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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(recipient=UserFactory(), subject="Hello")
  11. def test_is_in_a_users_inbox(self):
  12. assert Notification.INBOX == self.notification.location
  13. def test_is_not_read(self):
  14. assert not self.notification.is_read
  15. class TestANotification(TestCase):
  16. def setUp(self):
  17. self.notification = Notification.objects.create(
  18. recipient=UserFactory(), subject="Hello"
  19. )
  20. def test_can_be_archived(self):
  21. self.notification.archive()
  22. assert Notification.ARCHIVE == self.notification.location
  23. class NotificationServiceTestCase(TestCase):
  24. def test_notify_a_single_user(self):
  25. user = UserFactory()
  26. subj = "Hello you!"
  27. body = "This is the notification body."
  28. Dispatcher().notify_user(user, subj, body=body)
  29. user_notification = Notification.objects.get(recipient=user)
  30. assert user_notification.subject == subj
  31. assert user_notification.body == body
  32. def test_notify_a_set_of_users(self):
  33. users = UserFactory.create_batch(3)
  34. subj = "Hello everyone!"
  35. body = "This is the notification body."
  36. Dispatcher().notify_users(User.objects.all(), subj, body=body)
  37. for user in users:
  38. user_notification = Notification.objects.get(recipient=user)
  39. assert user_notification.subject == subj
  40. assert user_notification.body == body