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

test_notification.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from http import client as http_client
  2. from django.urls import reverse
  3. from oscar.core.loading import get_class, get_model
  4. from oscar.test.factories import UserFactory
  5. from oscar.test.testcases import WebTestCase
  6. Dispatcher = get_class('communication.utils', 'Dispatcher')
  7. Notification = get_model('communication', 'Notification')
  8. class TestAUserWithUnreadNotifications(WebTestCase):
  9. def setUp(self):
  10. self.user = UserFactory()
  11. Dispatcher().notify_user(self.user, "Test message")
  12. def test_can_see_them_in_page_header(self):
  13. homepage = self.app.get('/', user=self.user)
  14. if homepage.status_code == 302:
  15. homepage = homepage.follow()
  16. self.assertEqual(1, homepage.context['num_unread_notifications'])
  17. def test_notification_list_view_shows_user_notifications(self):
  18. response = self.app.get(reverse('customer:notifications-inbox'), user=self.user)
  19. self.assertEqual(1, len(response.context['notifications']))
  20. self.assertEqual(False, response.context['notifications'][0].is_read)
  21. def test_notification_marked_as_read(self):
  22. n = Notification.objects.first()
  23. path = reverse('customer:notifications-detail', kwargs={'pk': n.id})
  24. response = self.app.get(path, user=self.user)
  25. # notification should be marked as read
  26. self.assertEqual(http_client.OK, response.status_code)
  27. n.refresh_from_db()
  28. self.assertTrue(n.is_read)