def test_share_solution_function( exercise: Exercise, student_user: User, ): student_user2 = conftest.create_student_user(index=1) solution = conftest.create_solution(exercise, student_user2) client2 = conftest.get_logged_user(student_user2.username) # Sharing his own solution shared_response = client2.post('/share', data=json.dumps(dict( solutionId=solution.id, act='get', )), content_type='application/json') assert shared_response.status_code == 200 # Entering another student solution shared_url = SharedSolution.get_or_none( SharedSolution.solution == solution, ) conftest.logout_user(client2) client = conftest.get_logged_user(student_user.username) shared_response = client.get(f'{routes.SHARED}/{shared_url}') assert shared_response.status_code == 200 # Downloading another student solution by solution.id solution_id_download_response = client.get( f'{routes.DOWNLOADS}/{solution.id}', ) assert solution_id_download_response.status_code == 403 # Downloading another student solution download_response = client.get( f'{routes.DOWNLOADS}/{shared_url}', ) assert download_response.status_code == 200 # Deleting another user's solution delete_not_user_solution_response = client.post( '/share', data=json.dumps(dict( solutionId=solution.id, act='delete', )), content_type='application/json', ) assert delete_not_user_solution_response.status_code == 403 # Deleting his own solution conftest.logout_user(client) client2 = conftest.get_logged_user(student_user2.username) delete_share_response = client2.post('/share', data=json.dumps(dict( solutionId=solution.id, act='delete', )), content_type='application/json') assert delete_share_response.status_code == 200 # Entering not shared solution after deletion conftest.logout_user(client2) client = conftest.get_logged_user(student_user.username) not_shared_solution_response = client.get( f'{routes.SHARED}/{shared_url}', ) assert not_shared_solution_response.status_code == 404
def _duplicate_solution_from_comment( comment: models.Comment, first_solution_code: str, second_solution_code: str, ) -> typing.Tuple[models.Solution, models.Solution]: first_solution: models.Solution = comment.solution first_solution.set_state(models.Solution.STATES.DONE) first_solution = first_solution.refresh() first_solution.json_data_str = first_solution_code first_solution.save() student_user: models.User = conftest.create_student_user(index=1) second_solution = models.Solution.create_solution( exercise=first_solution.exercise, solver=student_user, json_data_str=second_solution_code, ) return first_solution, second_solution
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
def test_next_exercise_with_cleanest_code( self, comment: Comment, staff_user: User, ): student_user: User = conftest.create_student_user(index=1) first_solution = comment.solution comment_text = comment.comment second_solution = conftest.create_solution(comment.solution.exercise, student_user) # comment exists on first solution - second one should be the first next_unchecked = Solution.next_unchecked() assert next_unchecked is not None assert next_unchecked.id == second_solution.id # delete the comment should give us back the first solution Comment.delete_by_id(comment.id) next_unchecked = Solution.next_unchecked() assert next_unchecked is not None assert next_unchecked.id == first_solution.id # if second_solution has comments we should get first solution Comment.create_comment( commenter=staff_user, line_number=1, comment_text=comment_text, file=second_solution.solution_files.get(), is_auto=False, ) next_unchecked = Solution.next_unchecked() assert next_unchecked is not None assert next_unchecked.id == first_solution.id # both have comments - the first one should be the first solution Comment.create_comment( commenter=staff_user, line_number=1, comment_text=comment_text, file=first_solution.solution_files.get(), is_auto=False, ) next_unchecked = Solution.next_unchecked() assert next_unchecked is not None assert next_unchecked.id == first_solution.id
def test_share_solution_by_another_user( exercise: Exercise, student_user: User, ): student_user2 = conftest.create_student_user(index=1) solution = conftest.create_solution(exercise, student_user2) client = conftest.get_logged_user(student_user.username) not_exist_share_response = client.post('/share', data=json.dumps(dict( solutionId=solution.id + 1, act='get', )), content_type='application/json') assert not_exist_share_response.status_code == 404 not_user_solution_share_response = client.post( '/share', data=json.dumps(dict( solutionId=solution.id, act='get', )), content_type='application/json', ) assert not_user_solution_share_response.status_code == 403
def test_start_checking( exercise: Exercise, student_user: User, staff_user: User, ): student_user2 = conftest.create_student_user(index=1) exercise2 = conftest.create_exercise(1) solution1 = conftest.create_solution(exercise, student_user) solution2 = conftest.create_solution(exercise2, student_user) solution3 = conftest.create_solution(exercise, student_user2) is_checking = solutions.start_checking(solution=None) assert not is_checking with no_celery: for solution in (solution1, solution2, solution3): assert solution.state == Solution.STATES.CREATED.name is_checking = solutions.start_checking(solution=solution) assert is_checking the_solution = Solution.get_by_id(solution.id) assert the_solution.state == Solution.STATES.IN_CHECKING.name
def test_get_next_unchecked( student_user: User, exercise: Exercise, staff_user: User, ): student_user2 = conftest.create_student_user(index=1) exercise2 = conftest.create_exercise(3) solution1 = conftest.create_solution(exercise, student_user) solution2 = conftest.create_solution(exercise2, student_user) solution3 = conftest.create_solution(exercise, student_user2) assert len(list(Solution.select())) == 3 unchecked = solutions.get_next_unchecked(exercise.id) assert unchecked is not None assert unchecked.exercise.id == solution1.exercise.id assert unchecked == solution1 solutions.mark_as_checked(solution1.id, staff_user) unchecked = solutions.get_next_unchecked(exercise.id) assert unchecked is not None assert unchecked.exercise.id == solution3.exercise.id assert unchecked == solution3 solutions.mark_as_checked(solution3.id, staff_user) unchecked = solutions.get_next_unchecked(exercise.id) assert unchecked is None unchecked = solutions.get_next_unchecked() assert unchecked is not None assert unchecked == solution2 solutions.mark_as_checked(solution2.id, staff_user) unchecked = solutions.get_next_unchecked() assert unchecked is None unchecked = solutions.get_next_unchecked(solution2.id) assert unchecked is None
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)