def test_latest_notification(self): """The redirect goes to the latest notification announcement URL.""" user = self.make_user() NotificationFactory(user=user) notification = NotificationFactory(user=user) with self.login(user): response = self.get("notifications:whats_new") assert response["Location"] == notification.announcement.url
def test_marks_all_notifications_viewed(self): """Any unread notifications from the user are marked as viewed.""" user = self.make_user() NotificationFactory() # Ensure a different user isn't affected. NotificationFactory(user=user) unread = Notification.NotificationStatus.UNREAD with self.login(user): self.get("notifications:whats_new") assert Notification.objects.filter(user=user, status=unread).count() == 0 assert Notification.objects.filter(status=unread).count() == 1
def test_str(self): notification = NotificationFactory() assert ( str(notification) == f"Notification for {notification.user} for {notification.announcement}" )
def test_factory(self): notification = NotificationFactory() assert notification.status == Notification.NotificationStatus.UNREAD assert notification.created_at is not None assert notification.user is not None assert notification.announcement is not None
def test_get(self): user = self.make_user() notification = NotificationFactory(user=user) with self.login(user): response = self.get("notifications:whats_new") assert response.status_code == 302 assert response["Location"] == notification.announcement.url
def test_show_whats_new_no_unread_notifications(self): """The show_whats_new is False when there are no unread notifications.""" user = self.make_user() NotificationFactory(user=user, status=Notification.NotificationStatus.VIEWED) with self.login(user): self.get_check_200("core:app") assert not self.get_context("show_whats_new")
def test_show_whats_new_in_context(self): """The show_whats_new boolean is in the context.""" user = self.make_user() NotificationFactory(user=user) with self.login(user): self.get_check_200("core:app") assert self.get_context("show_whats_new")
def test_show_whats_new_in_context(self): """The show_whats_new boolean is in the context.""" user = self.make_user() SchoolYearFactory(school=user.school) StudentFactory(school=user.school) NotificationFactory(user=user) with self.login(user): self.get_check_200("core:dashboard") assert self.get_context("show_whats_new")
def test_show_whats_new_does_not_want_announcements(self): """The show_whats_new is False for users that don't want announcements.""" user = self.make_user() user.profile.wants_announcements = False user.profile.save() NotificationFactory(user=user) with self.login(user): self.get_check_200("core:app") assert not self.get_context("show_whats_new")