예제 #1
0
    def do_patch_object_test(self,
                             ag_model_obj,
                             client,
                             user,
                             url,
                             request_data,
                             format='json'):
        expected_data = ag_model_obj.to_dict()
        expected_data.pop('last_modified', None)
        for key, value in request_data.items():
            if isinstance(value, dict):
                expected_data[key].update(value)
            else:
                expected_data[key] = value

        client.force_authenticate(user)
        response = client.patch(url, request_data, format=format)
        self.assertEqual(status.HTTP_200_OK, response.status_code)

        ag_model_obj = ag_model_obj._meta.model.objects.get(pk=ag_model_obj.pk)
        self.assert_dict_contents_equal(
            expected_data,
            utils.exclude_dict(ag_model_obj.to_dict(), 'last_modified'))
        self.assert_dict_contents_equal(
            expected_data, utils.exclude_dict(response.data, 'last_modified'))

        return response
예제 #2
0
def _copy_ag_tests(project, new_project):
    for suite in project.ag_test_suites.all():
        instructor_files_needed = [
            file_ for file_ in new_project.instructor_files.all()
            if utils.find_if(suite.instructor_files_needed.all(),
                             lambda instr_file: instr_file.name == file_.name)
        ]
        student_files_needed = list(
            new_project.expected_student_files.filter(pattern__in=[
                student_file.pattern
                for student_file in suite.student_files_needed.all()
            ]))

        new_suite = AGTestSuite.objects.validate_and_create(
            project=new_project,
            instructor_files_needed=instructor_files_needed,
            student_files_needed=student_files_needed,
            **utils.exclude_dict(suite.to_dict(), ('pk', 'project') +
                                 AGTestSuite.get_serialize_related_fields()))

        for case in suite.ag_test_cases.all():
            new_case = AGTestCase.objects.validate_and_create(
                ag_test_suite=new_suite,
                **utils.exclude_dict(
                    case.to_dict(), ('pk', 'ag_test_suite') +
                    AGTestCase.get_serialize_related_fields()))

            for cmd in case.ag_test_commands.all():
                stdin_instructor_file = None
                if cmd.stdin_instructor_file is not None:
                    stdin_instructor_file = utils.find_if(
                        new_project.instructor_files.all(), lambda instr_file:
                        instr_file.name == cmd.stdin_instructor_file.name)

                expected_stdout_instructor_file = None
                if cmd.expected_stdout_instructor_file is not None:
                    expected_stdout_instructor_file = utils.find_if(
                        new_project.instructor_files.all(),
                        lambda instr_file: instr_file.name == cmd.
                        expected_stdout_instructor_file.name)

                expected_stderr_instructor_file = None
                if cmd.expected_stderr_instructor_file is not None:
                    expected_stderr_instructor_file = utils.find_if(
                        new_project.instructor_files.all(),
                        lambda instr_file: instr_file.name == cmd.
                        expected_stderr_instructor_file.name)

                AGTestCommand.objects.validate_and_create(
                    ag_test_case=new_case,
                    stdin_instructor_file=stdin_instructor_file,
                    expected_stdout_instructor_file=
                    expected_stdout_instructor_file,
                    expected_stderr_instructor_file=
                    expected_stderr_instructor_file,
                    **utils.exclude_dict(
                        cmd.to_dict(), ('pk', 'ag_test_case') +
                        AGTestCommand.get_serialize_related_fields()))
 def test_staff_get_project(self):
     self.assertFalse(self.project.visible_to_students)
     staff = obj_build.make_staff_user(self.course)
     # closing_time is only shown to admins.
     self.do_get_object_test(
         self.client, staff, self.url,
         exclude_dict(self.project.to_dict(), ['closing_time']))
 def test_guest_get_project(self):
     self.project.validate_and_update(visible_to_students=True,
                                      guests_can_submit=True)
     guest = obj_build.make_user()
     self.do_get_object_test(
         self.client, guest, self.url,
         exclude_dict(self.project.to_dict(),
                      ['closing_time', 'instructor_files']))
 def test_student_get_visible_project(self):
     self.project.validate_and_update(visible_to_students=True)
     student = obj_build.make_student_user(self.course)
     # closing_time is only shown to admins.
     self.do_get_object_test(
         self.client, student, self.url,
         exclude_dict(self.project.to_dict(),
                      ['closing_time', 'instructor_files']))
 def test_handgrader_get_project(self):
     self.assertFalse(self.project.visible_to_students)
     handgrader = obj_build.make_handgrader_user(self.course)
     # closing_time is only shown to admins.
     self.do_get_object_test(
         self.client, handgrader, self.url,
         exclude_dict(self.project.to_dict(),
                      ['closing_time', 'instructor_files']))
예제 #7
0
    def do_put_object_test(self,
                           ag_model_obj,
                           client,
                           user,
                           url,
                           request_data,
                           format='json'):
        expected_data = ag_model_obj.to_dict()
        expected_data.pop('last_modified', None)
        expected_data.update(request_data)

        client.force_authenticate(user)
        response = client.put(url, request_data, format=format)
        self.assertEqual(status.HTTP_200_OK, response.status_code)

        ag_model_obj = ag_model_obj._meta.model.objects.get(pk=ag_model_obj.pk)
        self.assert_dict_contents_equal(
            expected_data,
            utils.exclude_dict(ag_model_obj.to_dict(), 'last_modified'))
        self.assert_dict_contents_equal(
            expected_data, utils.exclude_dict(response.data, 'last_modified'))

        return response
예제 #8
0
def _copy_student_suites(project, new_project):
    for student_suite in project.student_test_suites.all():
        instructor_files_needed = [
            file_ for file_ in new_project.instructor_files.all()
            if utils.find_if(student_suite.instructor_files_needed.all(),
                             lambda instr_file: instr_file.name == file_.name)
        ]
        student_files_needed = list(
            new_project.expected_student_files.filter(pattern__in=[
                expected_file.pattern
                for expected_file in student_suite.student_files_needed.all()
            ]))
        StudentTestSuite.objects.validate_and_create(
            project=new_project,
            instructor_files_needed=instructor_files_needed,
            student_files_needed=student_files_needed,
            **utils.exclude_dict(
                student_suite.to_dict(), ('pk', 'project') +
                StudentTestSuite.get_serialize_related_fields()))