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

test_notification.py 1.3KB

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