Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

notification_tests.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from django.test import TestCase
  2. from django_dynamic_fixture import G
  3. from oscar.apps.customer.models import Notification
  4. from oscar.apps.customer.notifications import services
  5. from oscar.core.compat import get_user_model
  6. User = get_user_model()
  7. class TestANewNotification(TestCase):
  8. def setUp(self):
  9. # Don't save models for speed
  10. self.notification = Notification(
  11. recipient=User(),
  12. subject="Hello")
  13. def test_is_in_a_users_inbox(self):
  14. self.assertEqual(Notification.INBOX, self.notification.location)
  15. def test_is_not_read(self):
  16. self.assertFalse(self.notification.is_read)
  17. class TestANotification(TestCase):
  18. def setUp(self):
  19. self.notification = Notification.objects.create(
  20. recipient=G(User),
  21. subject="Hello")
  22. def test_can_be_archived(self):
  23. self.notification.archive()
  24. self.assertEqual(Notification.ARCHIVE, self.notification.location)
  25. class TestAServiceExistsTo(TestCase):
  26. def test_notify_a_single_user(self):
  27. user = G(User)
  28. services.notify_user(user, "Hello you!")
  29. self.assertEqual(1, Notification.objects.filter(
  30. recipient=user).count())
  31. def test_notify_a_set_of_users(self):
  32. users = [G(User) for i in range(5)]
  33. services.notify_users(User.objects.all(), "Hello everybody!")
  34. for user in users:
  35. self.assertEqual(1, Notification.objects.filter(
  36. recipient=user).count())