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.

notification_tests.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from django.test import TestCase
  2. from django.contrib.auth.models import User
  3. from django_dynamic_fixture import G
  4. from oscar.apps.customer.models import Notification
  5. from oscar.apps.customer.notifications import services
  6. class TestANewNotification(TestCase):
  7. def setUp(self):
  8. # Don't save models for speed
  9. self.notification = Notification(
  10. recipient=User(),
  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=G(User),
  20. subject="Hello")
  21. def test_can_be_archived(self):
  22. self.notification.archive()
  23. self.assertEqual(Notification.ARCHIVE, self.notification.location)
  24. class TestAServiceExistsTo(TestCase):
  25. def test_notify_a_single_user(self):
  26. user = G(User)
  27. services.notify_user(user, "Hello you!")
  28. self.assertEqual(1, Notification.objects.filter(
  29. recipient=user).count())
  30. def test_notify_a_set_of_users(self):
  31. users = [G(User) for i in range(5)]
  32. services.notify_users(User.objects.all(), "Hello everybody!")
  33. for user in users:
  34. self.assertEqual(1, Notification.objects.filter(
  35. recipient=user).count())