예제 #1
0
    def test_zip(self, course: Course, student_user: User):
        conftest.create_exercise(course, 1)
        conftest.create_exercise(course, 2)
        conftest.create_exercise(course, 3)
        conftest.create_exercise(course, 4, is_archived=True)
        conftest.create_usercourse(student_user, course)

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

        # Uploading a multiple zip solutions file
        upload_response = client.post(f'/upload/{course.id}',
                                      data={
                                          '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(
            f'/upload/{course.id}',
            data={
                'file': self.zipfiles_extractors_bytes_io[0],
            })
        assert second_upload_response.status_code == 400
예제 #2
0
    def test_solutions_of_user(
        staff_user: User,
        student_user: User,
        course: Course,
        solution: Solution,
        _assessments,
    ):
        conftest.create_usercourse(student_user, course)
        client = conftest.get_logged_user(staff_user.username)
        client.post(
            f'/assessment/{solution.id}',
            data=json.dumps({'assessment': 2}),
            content_type='application/json',
        )
        solution = Solution.get_by_id(solution.id)
        assert solution.assessment.name == 'Nice'

        client.post(
            f'/assessment/{solution.id}',
            data=json.dumps({'assessment': None}),
            content_type='application/json',
        )

        exercise2 = conftest.create_exercise(course, 2)
        solution2 = conftest.create_solution(exercise2, student_user)
        client.post(
            f'/assessment/{solution2.id}',
            data=json.dumps({'assessment': 3}),
            content_type='application/json',
        )
        solution2 = Solution.get_by_id(solution2.id)

        exercises = solution.of_user(student_user.id, from_all_courses=True)
        assert exercises[0].get('assessment') is None
        assert exercises[1].get('assessment') == 'Try again'
예제 #3
0
    def test_courses_exercises(
        course: Course,
        student_user: User,
        captured_templates,
    ):
        course2 = conftest.create_course(index=1)
        conftest.create_usercourse(student_user, course)
        conftest.create_exercise(course2, 1)
        conftest.create_exercise(course2, 2)
        assert len(
            list(Exercise.get_objects(student_user.id,
                                      from_all_courses=True), )) == 0

        client = conftest.get_logged_user(username=student_user.username)
        client.get(f'course/{course.id}')
        template, _ = captured_templates[-1]
        assert template.name == 'exercises.html'
        conftest.create_exercise(course, 1, index=1)
        assert len(list(Exercise.get_objects(student_user.id))) == 1

        unregistered_response = client.get(f'course/{course2.id}')
        assert unregistered_response.status_code == 403

        fail_response = client.get('course/123456')
        assert fail_response.status_code == 404

        conftest.create_usercourse(student_user, course2)
        client.get(f'course/{course2.id}')
        template, _ = captured_templates[-1]
        assert template.name == 'exercises.html'
        assert len(list(Exercise.get_objects(student_user.id))) == 2
예제 #4
0
    def test_usercourse_on_save(student_user: User, course: Course):
        course2 = conftest.create_course(index=1)
        usercourse = conftest.create_usercourse(student_user, course)
        assert student_user.last_course_viewed == course

        conftest.create_usercourse(student_user, course2)
        assert student_user.last_course_viewed == course

        usercourse.delete_instance()
        assert student_user.last_course_viewed == course2
예제 #5
0
    def test_upload_invalid_exercise(
        self,
        course: Course,
        student_user: User,
    ):
        conftest.create_usercourse(student_user, course)

        client = conftest.get_logged_user(username=student_user.username)
        fail_upload_response = client.post(f'/upload/{course.id}',
                                           data={
                                               'file': self.image_bytes_io,
                                           })
        assert fail_upload_response.status_code == 400
예제 #6
0
    def test_upload_correct_course(
        self,
        course: Course,
        student_user: User,
    ):
        conftest.create_exercise(course, 1)
        conftest.create_usercourse(student_user, course)

        client = conftest.get_logged_user(username=student_user.username)
        success_upload_response = client.post(f'/upload/{course.id}',
                                              data={
                                                  'file':
                                                  self.pyfile_different_course,
                                              })
        assert success_upload_response.status_code == 200
예제 #7
0
    def test_upload_another_course(
        self,
        course: Course,
        student_user: User,
    ):
        course2 = conftest.create_course(index=1)
        conftest.create_exercise(course2, 1)
        conftest.create_usercourse(student_user, course)

        client = conftest.get_logged_user(username=student_user.username)
        fail_upload_response = client.post(f'/upload/{course2.id}',
                                           data={
                                               'file':
                                               self.pyfile_different_course,
                                           })
        assert fail_upload_response.status_code == 400
예제 #8
0
    def test_send_page(
        student_user: User,
        course: Course,
        exercise: Exercise,
    ):
        course2 = conftest.create_course(2)
        exercise2 = conftest.create_exercise(course2, 1)
        conftest.create_usercourse(student_user, course)
        client = conftest.get_logged_user(student_user.username)
        success_send_response = client.get(f'send/{course.id}')
        assert success_send_response.status_code == 200

        success_send_response2 = client.get(f'send/{course.id}/{exercise.id}')
        assert success_send_response2.status_code == 200

        fail_send_response = client.get(f'send/{course2.id}')
        assert fail_send_response.status_code == 403

        fail_send_response = client.get(f'send/{course2.id}/{exercise2.id}')
        assert fail_send_response.status_code == 403
예제 #9
0
    def setup(cls):
        cls.course1 = conftest.create_course(1)
        cls.course2 = conftest.create_course(2)
        cls.course_no_submissions = conftest.create_course(3)
        cls.course_no_exercises = conftest.create_course(4)

        cls.ex1_1 = conftest.create_exercise(cls.course1, 1, 1)
        cls.ex1_2 = conftest.create_exercise(cls.course1, 2, 2)
        cls.ex2_1 = conftest.create_exercise(cls.course2, 1, 3)
        cls.ex3_1 = conftest.create_exercise(cls.course_no_submissions, 1, 4)

        cls.user1 = conftest.create_user(index=1)
        cls.user2 = conftest.create_user(index=2)

        conftest.create_usercourse(cls.user1, cls.course1)
        conftest.create_usercourse(cls.user1, cls.course2)
        conftest.create_usercourse(cls.user2, cls.course1)

        solution = conftest.create_solution

        cls.s1 = solution(cls.ex1_1, cls.user1)
        cls.s2 = solution(cls.ex1_1, cls.user1, code='Other submission')
        cls.s3 = solution(cls.ex1_1, cls.user2)
        cls.s4 = solution(cls.ex1_2, cls.user1)

        cls.s5 = solution(cls.ex2_1, cls.user1)
예제 #10
0
    def test_push_exercise(self, exercise: models.Exercise,
                           student_user: models.User):
        git_receive_pack = 'git-receive-pack'
        conftest.create_usercourse(student_user, exercise.course)

        response = self._send_git_request(
            username=student_user.username,
            method_name=self.GET_METHOD,
            url=self._get_formatted_git_url(exercise, self.INFO_URL),
            service=git_receive_pack,
        )

        assert response.status_code == 200
        assert response.data.startswith(b'001f#')

        response = self._send_git_request(
            username=student_user.username,
            method_name=self.POST_METHOD,
            url=self._get_formatted_git_url(exercise, git_receive_pack),
            data=POST_NEW_REPOSITORY_BUFFER,
        )
        assert response.status_code == 200
        assert response.data.startswith(
            b'0030\x01000eunpack ok\n0019ok refs/heads/master\n00000000')
예제 #11
0
    def test_usercourse_on_delete(student_user: User, course: Course):
        usercourse = conftest.create_usercourse(student_user, course)
        assert student_user.last_course_viewed == course

        usercourse.delete_instance()
        assert student_user.last_course_viewed is None
예제 #12
0
    def test_user_registered_to_course(student_user: User, course: Course):
        conftest.create_usercourse(student_user, course)
        assert course.has_user(student_user)

        course2 = conftest.create_course(index=1)
        assert not course2.has_user(student_user)