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

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