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.

test_notification.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435
  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. if homepage.status_code == 302:
  14. homepage = homepage.follow()
  15. self.assertEqual(1, homepage.context['num_unread_notifications'])
  16. def test_notification_list_view_shows_user_notifications(self):
  17. response = self.app.get(reverse('customer:notifications-inbox'), user=self.user)
  18. self.assertEqual(1, len(response.context['notifications']))
  19. self.assertEqual(False, response.context['notifications'][0].is_read)
  20. def test_notification_marked_as_read(self):
  21. n = Notification.objects.first()
  22. path = reverse('customer:notifications-detail', kwargs={'pk': n.id})
  23. response = self.app.get(path, user=self.user)
  24. # notification should be marked as read
  25. self.assertEqual(http_client.OK, response.status_code)
  26. n.refresh_from_db()
  27. self.assertTrue(n.is_read)