def test_zip_bomb(self, student_user: User): conftest.create_exercise() client = conftest.get_logged_user(username=student_user.username) # Trying to upload a zipbomb file upload_response = client.post('/upload', data={ 'file': self.zipbomb_bytes_io, }) assert upload_response.status_code == 413
def test_zip(self, student_user: User): conftest.create_exercise() conftest.create_exercise() conftest.create_exercise() conftest.create_exercise(is_archived=True) client = conftest.get_logged_user(username=student_user.username) # Uploading a multiple zip solutions file upload_response = client.post( '/upload', data=dict(file=self.zipfiles_extractors_bytes_io[1], )) json_response_upload = json.loads( upload_response.get_data(as_text=True), ) assert len(json_response_upload['exercise_misses']) == 1 assert len(json_response_upload['exercise_matches']) == 2 assert upload_response.status_code == 200 # Uploading a zip file with a same solution exists in the previous zip second_upload_response = client.post( '/upload', data=dict(file=self.zipfiles_extractors_bytes_io[0], )) assert second_upload_response.status_code == 400
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