def test_read( self, student_user: User, solution: Solution, ): assert len(list(notifications.get(student_user))) == 0 message_id = conftest.create_notification(student_user, solution) assert len(list(notifications.get(student_user))) == 1 unread = self.get_unread(student_user) assert len(list(unread)) == 1 notifications.read(id_=message_id) self.check_viewed_inbox(student_user) # Test by notification ID self.create_too_many_notifications(student_user, solution) assert (len(list( notifications.get(student_user))) == Notification.MAX_PER_USER) for notification in notifications.get(student_user): success = notifications.read(id_=notification.id) assert success self.check_full_inbox(student_user) # Still there self.check_viewed_inbox(student_user) # But already viewed # Test by user self.create_too_many_notifications(student_user, solution) assert (len(list( notifications.get(student_user))) == Notification.MAX_PER_USER) notifications.read(user=student_user) self.check_full_inbox(student_user) # Still there self.check_viewed_inbox(student_user) # But already viewed
def test_read_related( self, student_user: User, solution: Solution, exercise: Exercise, ): solution2 = conftest.create_solution(student_user, exercise) student_user2 = conftest.create_user(index=1) messages = [ conftest.create_notification(student_user, solution), conftest.create_notification(student_user, solution), conftest.create_notification(student_user, solution), conftest.create_notification(student_user, solution2), conftest.create_notification(student_user2, solution), ] assert all(not n.viewed for n in messages) notifications.read_related(solution.id, student_user) # peewee... messages = [Notification.get_by_id(n.id) for n in messages] assert all(n.viewed for n in messages[:3]) assert all(not n.viewed for n in messages[3:])
def test_get( self, student_user: User, notification: Notification, solution: Solution, ): assert len(list(notifications.get(student_user))) == 1 n = next(iter(notifications.get(student_user)), None) assert n is not None assert n.user == student_user assert n.related_id == solution.id assert n.message == 'Test message 0' student_user2 = conftest.create_student_user(index=1) assert len(list(notifications.get(student_user2))) == 0 conftest.create_notification(student_user2, solution, index=2) assert len(list(notifications.get(student_user))) == 1 assert len(list(notifications.get(student_user2))) == 1 self.create_too_many_notifications(student_user, solution) assert (len(list( notifications.get(student_user))) == Notification.MAX_PER_USER)
def create_too_many_notifications(user: User, solut: Solution): for i in range(Notification.MAX_PER_USER + 5): conftest.create_notification(user, solut, index=i)