Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

test_notification.py 1.3KB

1234567891011121314151617181920212223242526272829303132
  1. from oscar.test.testcases import WebTestCase
  2. from oscar.apps.customer.notifications import services
  3. from oscar.test.factories import UserFactory
  4. from django.urls import reverse
  5. from django.utils.six.moves import http_client
  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)