Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def test_strange_solution_with_no_files(
        exercise: Exercise,
        student_user: User,
        staff_user: User,
    ):
        solution = conftest.create_solution(
            exercise,
            student_user,
            files=[],
            hash_='koko',
        )

        staff_client = conftest.get_logged_user(staff_user.username)
        view_response = staff_client.get(f'{routes.SOLUTIONS}/{solution.id}')
        assert view_response.status_code == 200
        solution = Solution.get_by_id(solution.id)
        assert solution.state == Solution.STATES.DONE.name

        to_show_in_view = {
            'solution': solution,
            'file_id': None,
            'shared_url': '',
            'is_manager': False,
            'solution_files': (),
            'viewer_is_solver': True,
        }

        with pytest.raises(ResourceNotFound):
            assert get_view_parameters(**to_show_in_view)

        user_client = conftest.get_logged_user(student_user.username)
        assert len(list(notifications.get(student_user))) == 1
        view_response = user_client.get(f'{routes.SOLUTIONS}/{solution.id}')
        assert view_response.status_code == 404
Exemplo n.º 3
0
    def test_mark_as_checked(
        exercise: Exercise,
        student_user: User,
        staff_user: User,
        solution: Solution,
    ):
        # Basic functionality
        assert solution.state == Solution.STATES.CREATED.name
        marked = solutions.mark_as_checked(solution.id, staff_user.id)
        # HELL WITH PEEWEE!!!
        solution = Solution.get_by_id(solution.id)
        assert marked
        assert solution.state == Solution.STATES.DONE.name
        assert solution.checker == staff_user

        # Not duplicating things
        staff_user2 = conftest.create_staff_user(index=1)
        solution2 = conftest.create_solution(exercise, student_user)
        marked = solutions.mark_as_checked(solution2.id, staff_user2.id)
        solution2 = Solution.get_by_id(solution2.id)
        assert solution2.state == Solution.STATES.DONE.name
        assert solution2.checker == staff_user2

        # Creates notifications
        assert len(list(notifications.get(student_user))) == 2
Exemplo n.º 4
0
    def test_send(self, student_user: User):
        another_user = conftest.create_student_user(index=1)
        params = self.generate_params()
        n1 = notifications.send(student_user, **params)
        n2 = notifications.send(another_user, self.kind_checked, 'yoyo2')
        n3 = notifications.send(student_user, self.kind_flake8, 'yoyo3')

        assert n1.user == student_user
        assert n1.kind == params['kind'].value
        assert n1.message == params['message']
        assert n1.related_id == params['related_id']
        assert n1.action_url == params['action_url']
        assert n2.kind != n3.kind
        assert n2.message == 'yoyo2'
        assert n2.user == another_user
        assert len(list(notifications.get(student_user))) == 2
        assert len(list(notifications.get(another_user))) == 1
Exemplo n.º 5
0
    def test_solve_solution_with_identical_code(self, comment: models.Comment):
        f_solution, s_solution = self._duplicate_solution_from_comment(
            comment=comment,
            first_solution_code=SOME_CODE,
            second_solution_code=SOME_CODE,
        )
        assert len(tuple(s_solution.comments)) == 0
        tasks.solve_solution_with_identical_code(s_solution.id)
        assert len(tuple(s_solution.comments)) == 1

        user_notifications = notifications.get(user=s_solution.solver)
        assert len(user_notifications) == 1
        solution_id = user_notifications[0].related_id
        assert s_solution.id == solution_id

        user_notifications = notifications.get(user=f_solution.solver)
        assert len(user_notifications) == 0
Exemplo n.º 6
0
 def test_invalid_solution(self, solution: Solution):
     solution_file = solution.solution_files.get()
     solution_file.code = INVALID_CODE
     solution_file.save()
     tasks.run_linter_on_solution(solution.id)
     comments = tuple(Comment.by_solution(solution))
     assert comments
     assert len(comments) == 1
     comment = comments[0].comment
     assert comment.text == INVALID_CODE_MESSAGE
     assert comment.flake8_key == INVALID_CODE_KEY
     user_notifications = notifications.get(user=solution.solver)
     assert len(user_notifications) == 1
     assert user_notifications
     subject = user_notifications[0].message
     assert solution.exercise.subject in subject
     assert '1' in subject
Exemplo n.º 7
0
    def test_check_solution_with_invalid_exercise(
            self, solution: models.Solution,
    ):
        self._initialize_solution(solution, INVALID_EXERCISE_TESTS)
        self._run_unit_tests(solution.id)
        auto_comments = tuple(models.SolutionExerciseTestExecution.select())
        assert len(auto_comments) == 1
        comment = auto_comments[0]

        expected_name = models.ExerciseTestName.FATAL_TEST_NAME
        assert comment.exercise_test_name.test_name == expected_name
        expected_name = models.ExerciseTestName.FATAL_TEST_PRETTY_TEST_NAME
        assert comment.exercise_test_name.pretty_test_name == expected_name

        all_notifications = list(notifications.get(user=solution.solver))
        assert len(all_notifications) == 1
        assert all_notifications[0].kind == UNITTEST_NOTIFICATION
Exemplo n.º 8
0
    def test_check_if_other_solutions_can_be_solved(
        self,
        comment: models.Comment,
    ):
        first_solution, another_solution = (
            self._duplicate_solution_from_comment(
                comment=comment,
                first_solution_code=SOME_CODE,
                second_solution_code=SOME_CODE,
            ))

        assert len(tuple(another_solution.comments)) == 0
        tasks.check_if_other_solutions_can_be_solved(first_solution.id)
        assert len(tuple(another_solution.comments)) == 1

        user_notifications = notifications.get(user=another_solution.solver)
        assert len(user_notifications) == 1

        subject = user_notifications[0].message
        assert another_solution.exercise.subject in subject
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
def get_notifications():
    response = notifications.get(user=current_user)
    return jsonify(response)
Exemplo n.º 11
0
 def check_full_inbox(user: User):
     assert (len(list(
         notifications.get(user))) == Notification.MAX_PER_USER)
Exemplo n.º 12
0
    def test_user_commented_after_check(
        solution: Solution,
        student_user: User,
        staff_user: User,
    ):
        client = conftest.get_logged_user(student_user.username)

        # Marking the solution as checked
        solutions.mark_as_checked(solution.id, staff_user.id)
        solution = Solution.get_by_id(solution.id)

        # Sending comments after solution checked
        comment_response = client.post('/comments',
                                       data=json.dumps({
                                           'fileId':
                                           solution.files[0].id,
                                           'act':
                                           'create',
                                           'kind':
                                           'text',
                                           'comment':
                                           'new one',
                                           'line':
                                           1,
                                       }),
                                       content_type='application/json')
        new_comment_response = client.post('/comments',
                                           data=json.dumps({
                                               'fileId':
                                               solution.files[0].id,
                                               'act':
                                               'create',
                                               'kind':
                                               'text',
                                               'comment':
                                               'another one',
                                               'line':
                                               2,
                                           }),
                                           content_type='application/json')
        assert comment_response.status_code == 200
        assert new_comment_response.status_code == 200
        assert len(list(notifications.get(staff_user))) == 1

        conftest.logout_user(client)
        client2 = conftest.get_logged_user(staff_user.username)

        # Sending a comment after student user commented
        staff_comment_response = client2.post(
            '/comments',
            data=json.dumps({
                'fileId': solution.files[0].id,
                'act': 'create',
                'kind': 'text',
                'comment': 'FINE',
                'line': 1,
            }),
            content_type='application/json',
        )
        assert staff_comment_response.status_code == 200
        assert len(list(notifications.get(student_user))) == 2

        conftest.logout_user(client2)
        client = conftest.get_logged_user(student_user.username)

        # User student comments again
        another_comment_response = client.post(
            '/comments',
            data=json.dumps({
                'fileId': solution.files[0].id,
                'act': 'create',
                'kind': 'text',
                'comment': 'OK',
                'line': 3,
            }),
            content_type='application/json',
        )
        assert another_comment_response.status_code == 200
        assert len(list(notifications.get(staff_user))) == 2
Exemplo n.º 13
0
 def _verify_notifications(solution):
     all_notifications = notifications.get(user=solution.solver)
     assert len(all_notifications) == 1
     assert all_notifications[0].kind == UNITTEST_NOTIFICATION