def test_get_ultimate_submissions_only_finished_grading_status_considered( self): data = self.prepare_data(self.project, num_groups=2) non_considered_statuses = filter( lambda val: val != ag_models.Submission.GradingStatus. finished_grading, ag_models.Submission.GradingStatus.values) for item in data: for grading_status in non_considered_statuses: obj_build.make_submission(group=item.group, status=grading_status) self.project.validate_and_update(ultimate_submission_policy=ag_models. UltimateSubmissionPolicy.most_recent) self.assertCountEqual([item.most_recent_submission for item in data], [ fdbk.submission for fdbk in get_ultimate_submissions( self.project, filter_groups=None, ag_test_preloader=AGTestPreLoader(self.project)) ]) self.project.validate_and_update( ultimate_submission_policy=ag_models.UltimateSubmissionPolicy.best) self.assertCountEqual([item.best_submission for item in data], [ fdbk.submission for fdbk in get_ultimate_submissions( self.project, filter_groups=None, ag_test_preloader=AGTestPreLoader(self.project)) ])
def test_create_criterion_results_on_create(self): [admin] = obj_build.make_admin_users(self.course, 1) self.client.force_authenticate(admin) # Create HandgradingResult submission = obj_build.make_submission( group=obj_build.make_group(project=self.handgrading_rubric.project)) handgrading_result = hg_models.HandgradingResult.objects.validate_and_create( submission=submission, group=submission.group, handgrading_rubric=self.handgrading_rubric) # Create dummy submissions and groups with no submissions. These should not be affected dummy_submission = obj_build.make_submission( group=obj_build.make_group(project=self.handgrading_rubric.project)) dummy_submission = obj_build.make_submission( group=obj_build.make_group(project=self.handgrading_rubric.project)) group_with_no_submission = obj_build.make_group(project=self.handgrading_rubric.project) group_with_no_submission = obj_build.make_group(project=self.handgrading_rubric.project) self.assertEqual(0, handgrading_result.criterion_results.count()) self.assertEqual(1, hg_models.HandgradingResult.objects.count()) # Create dummy project with its own groups and HandgradingResults. # These should not be affected dummy_project = obj_build.make_project(course=self.handgrading_rubric.project.course) dummy_handgrading_rubric = hg_models.HandgradingRubric.objects.validate_and_create( points_style=hg_models.PointsStyle.start_at_max_and_subtract, max_points=0, show_grades_and_rubric_to_students=False, handgraders_can_leave_comments=True, handgraders_can_adjust_points=True, project=dummy_project) dummy_submission = obj_build.make_submission( group=obj_build.make_group(project=self.handgrading_rubric.project)) dummy_handgrading_result = hg_models.HandgradingResult.objects.validate_and_create( submission=dummy_submission, group=dummy_submission.group, handgrading_rubric=dummy_handgrading_rubric) self.assertEqual(0, hg_models.CriterionResult.objects.count()) self.assertEqual(2, hg_models.HandgradingResult.objects.count()) # Create Criterion, which should create a CriterionResult for above HandgradingResult response = self.client.post(self.url, self.data) self.assertEqual(status.HTTP_201_CREATED, response.status_code) handgrading_result.refresh_from_db() self.assertEqual(1, handgrading_result.criterion_results.count()) self.assertEqual(1, hg_models.CriterionResult.objects.count()) criterion_results = handgrading_result.to_dict()["criterion_results"] self.assertFalse(criterion_results[0]["selected"]) self.assertEqual(criterion_results[0]["criterion"], response.data)
def test_get_num_queued_submissions(self): client = APIClient() course = obj_build.make_course() admin = obj_build.make_admin_user(course) proj_kwargs = {'visible_to_students': True, 'guests_can_submit': True} no_submits = obj_build.make_project(course, **proj_kwargs) with_submits1 = obj_build.make_project(course, **proj_kwargs) with_submits2 = obj_build.make_project(course, **proj_kwargs) group_with_submits1 = obj_build.make_group(project=with_submits1) group_with_submits2 = obj_build.make_group(project=with_submits2) g1_statuses = [ ag_models.Submission.GradingStatus.queued, ag_models.Submission.GradingStatus.finished_grading, ag_models.Submission.GradingStatus.removed_from_queue, ag_models.Submission.GradingStatus.received, ag_models.Submission.GradingStatus.being_graded, ag_models.Submission.GradingStatus.error ] for grading_status in g1_statuses: obj_build.make_submission(status=grading_status, group=group_with_submits1) for i in range(3): obj_build.make_submission( status=ag_models.Submission.GradingStatus.queued, group=group_with_submits2) client.force_authenticate(admin) response = client.get( reverse('project-num-queued-submissions', kwargs={'pk': no_submits.pk})) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(0, response.data) response = client.get( reverse('project-num-queued-submissions', kwargs={'pk': with_submits1.pk})) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(1, response.data) response = client.get( reverse('project-num-queued-submissions', kwargs={'pk': with_submits2.pk})) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(3, response.data)
def setUp(self): super().setUp() self.group = obj_build.make_group() self.student = self.group.members.first() self.project = self.group.project ag_models.ExpectedStudentFile.objects.validate_and_create( pattern='*', max_num_matches=10, project=self.project) self.submitted_files = [SimpleUploadedFile('file{}'.format(i), 'waaaluigi{}'.format(i).encode()) for i in range(3)] self.submission = obj_build.make_submission( group=self.group, submitted_files=self.submitted_files, status=Submission.GradingStatus.finished_grading) self.handgrading_rubric = hg_models.HandgradingRubric.objects.validate_and_create( project=self.project ) # type: hg_models.HandgradingRubric [self.admin] = obj_build.make_admin_users(self.project.course, 1) [self.staff] = obj_build.make_staff_users(self.project.course, 1) [self.handgrader] = obj_build.make_users(1) self.project.course.handgraders.add(self.handgrader) self.client = APIClient() self.course = self.handgrading_rubric.project.course self.url = reverse('handgrading_result', kwargs={'group_pk': self.submission.group.pk})
def test_default_initialization(self): submission = obj_build.make_submission( submitted_filenames=["test.cpp"]) comment_inputs = { "location": { "first_line": 0, "last_line": 1, "filename": "test.cpp" }, "text": "HI", "handgrading_result": handgrading_models.HandgradingResult.objects.validate_and_create( submission=submission, group=submission.group, handgrading_rubric=self.default_handgrading_rubric) } comment_obj = handgrading_models.Comment.objects.validate_and_create( **comment_inputs) self.assertEqual(comment_obj.location.first_line, comment_inputs["location"]["first_line"]) self.assertEqual(comment_obj.location.last_line, comment_inputs["location"]["last_line"]) self.assertEqual(comment_obj.location.filename, comment_inputs["location"]["filename"]) self.assertEqual(comment_obj.text, comment_inputs["text"]) self.assertEqual(comment_obj.handgrading_result, comment_inputs["handgrading_result"])
def test_remove_from_queue_when_being_marked_as_being_graded_race_condition_prevented(self): group = obj_build.make_group(members_role=obj_build.UserRole.admin) submission = obj_build.make_submission(group=group) path = ('autograder.core.models' '.Submission.GradingStatus.removed_from_queue') @sleeper_subtest( path, new_callable=mock.PropertyMock, return_value=(ag_models.Submission.GradingStatus.removed_from_queue)) def do_request_and_wait(): tasks.grade_submission(submission.pk) subtest = do_request_and_wait() print('sending remove from queue request') client = APIClient() client.force_authenticate( submission.group.members.first()) response = client.post(reverse('submission-remove-from-queue', kwargs={'pk': submission.pk})) subtest.join() submission.refresh_from_db() self.assertNotEqual( ag_models.Submission.GradingStatus.removed_from_queue, submission.status) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) self.assertEqual(ag_models.Submission.GradingStatus.finished_grading, submission.status)
def setUp(self): super().setUp() self.default_handgrading_rubric = ( handgrading_models.HandgradingRubric.objects.validate_and_create( points_style=handgrading_models.PointsStyle. start_at_max_and_subtract, max_points=0, show_grades_and_rubric_to_students=False, handgraders_can_leave_comments=True, handgraders_can_adjust_points=True, project=obj_build.build_project())) self.criterion_obj = handgrading_models.Criterion.objects.validate_and_create( points=0, handgrading_rubric=self.default_handgrading_rubric) submission = obj_build.make_submission() self.result_obj = handgrading_models.HandgradingResult.objects.validate_and_create( submission=submission, group=submission.group, handgrading_rubric=self.default_handgrading_rubric) self.criterion_inputs = { "selected": True, "criterion": self.criterion_obj, "handgrading_result": self.result_obj }
def setUp(self): super().setUp() handgrading_rubric = handgrading_models.HandgradingRubric.objects.validate_and_create( points_style=handgrading_models.PointsStyle. start_at_max_and_subtract, max_points=0, show_grades_and_rubric_to_students=False, handgraders_can_leave_comments=True, handgraders_can_adjust_points=True, project=obj_build.build_project()) self.criterion = handgrading_models.Criterion.objects.validate_and_create( points=0, handgrading_rubric=handgrading_rubric) submission = obj_build.make_submission( submitted_filenames=["test.cpp"]) self.handgrading_result = handgrading_models.HandgradingResult.objects.validate_and_create( submission=submission, group=submission.group, handgrading_rubric=handgrading_rubric) self.course = handgrading_rubric.project.course self.client = APIClient() self.url = reverse( 'criterion_results', kwargs={'handgrading_result_pk': self.handgrading_result.pk}) self.data = { "selected": True, "criterion": self.criterion.pk, }
def test_prefetching_doesnt_skew_num_submissions_and_num_submissions_towards_limit( self): group = obj_build.make_group(project=self.visible_public_project) yesterday_submission = obj_build.make_submission( group=group, timestamp=timezone.now() - datetime.timedelta(days=1)) not_towards_limit_submission = obj_build.make_submission( group=group, count_towards_daily_limit=False) towards_limit_submission = obj_build.make_submission(group=group) group.refresh_from_db() self.assertEqual(3, group.num_submissions) self.assertEqual(1, group.num_submits_towards_limit) self.client.force_authenticate(self.admin) response = self.client.get(self.group_url(group)) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(3, response.data['num_submissions']) self.assertEqual(1, response.data['num_submits_towards_limit'])
def test_comment_doesnt_require_location(self): submission = obj_build.make_submission() handgrading_result = handgrading_models.HandgradingResult.objects.validate_and_create( submission=submission, group=submission.group, handgrading_rubric=self.default_handgrading_rubric) handgrading_models.Comment.objects.validate_and_create( text="hello", handgrading_result=handgrading_result)
def test_download_all_scores_non_finished_grading_not_included(self): obj_build.make_submission( group=self.student_group2, status=ag_models.Submission.GradingStatus.removed_from_queue) obj_build.make_submission( group=self.student_group2, status=ag_models.Submission.GradingStatus.error) url = reverse('project-all-submission-scores', kwargs={'pk': self.project.pk}) self.assertEqual( 2, ag_models.Submission.objects.filter( group__project=self.project).exclude( status=ag_models.Submission.GradingStatus.finished_grading ).count()) self.do_download_scores_test(url, self.project, [ self.group1_submission1_best, self.group1_submission2, self.group2_only_submission ])
def setUp(self): super().setUp() self.client = APIClient() # This submission that belongs to another project shouldn't # prevent us from downloading files for our project. obj_build.make_submission( status=ag_models.Submission.GradingStatus.being_graded) self.files = [ SimpleUploadedFile('file1.txt', b'adsfadslkfajsdkfj'), SimpleUploadedFile('file2.txt', b'asdqeirueinfaksdnfaadf'), SimpleUploadedFile('file3.txt', b'cmxcnajsddhadf') ] self.files_by_name = dict( zip([file_.name for file_ in self.files], self.files)) max_group_size = 3 self.project = obj_build.make_project(visible_to_students=True, max_group_size=max_group_size) ag_models.ExpectedStudentFile.objects.validate_and_create( project=self.project, pattern='*', max_num_matches=3) self.student_group1 = obj_build.make_group(project=self.project) self.group1_submission1 = obj_build.make_finished_submission( submitted_files=self.files[:1], group=self.student_group1) self.group1_submission2 = obj_build.make_finished_submission( submitted_files=self.files[:2], group=self.student_group1) self.student_group2 = obj_build.make_group(num_members=max_group_size, project=self.project) self.group2_submission1 = obj_build.make_finished_submission( submitted_files=self.files[-1:], group=self.student_group2) self.staff_group = obj_build.make_group( project=self.project, members_role=obj_build.UserRole.staff) self.staff_submission1 = obj_build.make_finished_submission( submitted_files=self.files, group=self.staff_group) self.no_submissions_group = obj_build.make_group(project=self.project) [self.admin] = obj_build.make_admin_users(self.project.course, 1)
def test_position_in_queue_for_non_queued_submission(self): submission = obj_build.make_submission() non_queued_statuses = list(ag_models.Submission.GradingStatus.values) non_queued_statuses.remove(ag_models.Submission.GradingStatus.queued) for status in non_queued_statuses: submission.status = status submission.save() self.assertEqual(0, submission.position_in_queue)
def setUp(self): super().setUp() self.submission = obj_build.make_submission() self.project = self.submission.group.project self.setup_stdout = 'setuppy stdouty' self.setup_stderr = 'setuppy stderrrry' self.ag_test_suite = obj_build.make_ag_test_suite( self.project, setup_suite_cmd='bash -c "printf \'{}\'; printf \'{}\' >&2"'. format(self.setup_stdout, self.setup_stderr)) self.ag_test_case = obj_build.make_ag_test_case(self.ag_test_suite)
def test_unfinished_and_error_submissions_ignored(self): self.client.force_authenticate(self.admin) student_group3 = obj_build.make_group(num_members=1, project=self.project) received = obj_build.make_submission(group=self.student_group1) received.status = ag_models.Submission.GradingStatus.received received.save() queued = obj_build.make_submission(group=self.student_group2) queued.status = ag_models.Submission.GradingStatus.queued queued.save() being_graded = obj_build.make_submission(group=student_group3) being_graded.status = ag_models.Submission.GradingStatus.being_graded being_graded.save() waiting_for_deferred = obj_build.make_submission( group=self.student_group2) waiting_for_deferred.status = ag_models.Submission.GradingStatus.waiting_for_deferred waiting_for_deferred.save() error = obj_build.make_submission(group=self.student_group2) error.status = ag_models.Submission.GradingStatus.error error.save() self.assertEqual(ag_models.UltimateSubmissionPolicy.most_recent, self.project.ultimate_submission_policy) self.do_download_submissions_test( reverse('project-all-submission-files', kwargs={'pk': self.project.pk}), [ self.group1_submission1, self.group1_submission2, self.group2_submission1 ]) self.do_download_submissions_test( reverse('project-ultimate-submission-files', kwargs={'pk': self.project.pk}), [self.group1_submission2, self.group2_submission1])
def test_error_some_submissions_not_in_project(self): other_submission = obj_build.make_submission( group=obj_build.make_group()) with self.assertRaises(exceptions.ValidationError) as cm: ag_models.RerunSubmissionsTask.objects.validate_and_create( creator=self.creator, project=self.project, rerun_all_submissions=False, submission_pks=[other_submission.pk]) self.assertIn('submission_pks', cm.exception.message_dict)
def setUp(self): self.submission = obj_build.make_submission() self.project = self.submission.group.project self.ag_suite = obj_build.make_ag_test_suite(self.project) # Make sure that ag tests and ag test results don't have # overlapping pks. for i in range(20): self.ag_suite.delete() self.ag_suite.pk = None self.ag_suite.save()
def setUp(self): super().setUp() self.project = obj_build.make_project() [self.creator] = obj_build.make_admin_users(self.project.course, 1) self.ag_test_suite = obj_build.make_ag_test_suite(self.project) self.ag_test_case = obj_build.make_ag_test_case(self.ag_test_suite) self.student_test_suite = obj_build.make_student_test_suite( self.project) self.submission = obj_build.make_submission(group=obj_build.make_group( project=self.project))
def test_get_ultimate_submission_no_finished_submissions(self): for policy in ag_models.UltimateSubmissionPolicy: self.project.validate_and_update(ultimate_submission_policy=policy) group = obj_build.make_group(project=self.project) submission = obj_build.make_submission(group=group) self.assertEqual(1, group.submissions.count()) self.assertNotEqual( ag_models.Submission.GradingStatus.finished_grading, submission.status) ultimate_submission = get_ultimate_submission(group) self.assertIsNone(ultimate_submission)
def test_position_in_queue_multiple_projects(self): """ Makes sure that position in queue is calculated per-project """ project1 = obj_build.build_project() group1_proj1 = obj_build.build_group( group_kwargs={'project': project1}) group2_proj1 = obj_build.build_group( group_kwargs={'project': project1}) project2 = obj_build.build_project() group1_proj2 = obj_build.build_group( group_kwargs={'project': project2}) group2_proj2 = obj_build.build_group( group_kwargs={'project': project2}) group1_p1 = obj_build.make_submission(group=group1_proj1) group1_p1.status = (ag_models.Submission.GradingStatus.queued) group1_p1.save() group1_p1_queue_pos = 1 group2_p1 = obj_build.make_submission(group=group2_proj1) group2_p1.status = (ag_models.Submission.GradingStatus.queued) group2_p1.save() group2_p1_queue_pos = 2 group1_p2 = obj_build.make_submission(group=group1_proj2) group1_p2.status = (ag_models.Submission.GradingStatus.queued) group1_p2.save() group1_p2_queue_pos = 1 group2_p2 = obj_build.make_submission(group=group2_proj2) group2_p2.status = (ag_models.Submission.GradingStatus.queued) group2_p2.save() group2_p2_queue_pos = 2 self.assertEqual(group1_p1_queue_pos, group1_p1.position_in_queue) self.assertEqual(group2_p1_queue_pos, group2_p1.position_in_queue) self.assertEqual(group1_p2_queue_pos, group1_p2.position_in_queue) self.assertEqual(group2_p2_queue_pos, group2_p2.position_in_queue)
def setUp(self): super().setUp() submission = obj_build.make_submission() self.project = submission.group.project suite1 = ag_models.AGTestSuite.objects.validate_and_create( name='kajsdhf', project=self.project) self.ag_test_case1 = ag_models.AGTestCase.objects.validate_and_create( name='aksdbva', ag_test_suite=suite1) self.ag_test_case2 = ag_models.AGTestCase.objects.validate_and_create( name='noniresta', ag_test_suite=suite1) suite_result = ag_models.AGTestSuiteResult.objects.validate_and_create( submission=submission, ag_test_suite=suite1) self.ag_test_case1_correct_result = ag_models.AGTestCaseResult.objects.validate_and_create( ag_test_case=self.ag_test_case1, ag_test_suite_result=suite_result) self.ag_test_case2_incorrect_result = ( ag_models.AGTestCaseResult.objects.validate_and_create( ag_test_case=self.ag_test_case2, ag_test_suite_result=suite_result) ) self.ag_test_case1_cmd = obj_build.make_full_ag_test_command( self.ag_test_case1, first_failed_test_normal_fdbk_config=( ag_models.NewAGTestCommandFeedbackConfig.max_fdbk_config()) ) self.total_points_possible = (self.ag_test_case1_cmd.points_for_correct_return_code + self.ag_test_case1_cmd.points_for_correct_stdout + self.ag_test_case1_cmd.points_for_correct_stderr) self.ag_test_case2_cmd = obj_build.make_full_ag_test_command( self.ag_test_case2, first_failed_test_normal_fdbk_config=( ag_models.NewAGTestCommandFeedbackConfig.max_fdbk_config()) ) self.case1_cmd_res = obj_build.make_correct_ag_test_command_result( self.ag_test_case1_cmd, ag_test_case_result=self.ag_test_case1_correct_result) self.case2_cmd_res = obj_build.make_incorrect_ag_test_command_result( self.ag_test_case2_cmd, ag_test_case_result=self.ag_test_case2_incorrect_result) case1_max_fdbk = get_case_fdbk( self.ag_test_case1_correct_result, ag_models.FeedbackCategory.max) self.assertEqual(self.total_points_possible, case1_max_fdbk.total_points) self.assertEqual(self.total_points_possible, case1_max_fdbk.total_points_possible) case2_max_fdbk = get_case_fdbk( self.ag_test_case2_incorrect_result, ag_models.FeedbackCategory.max) self.assertEqual(0, case2_max_fdbk.total_points) self.assertEqual(self.total_points_possible, case2_max_fdbk.total_points_possible)
def test_normal_merge(self): files = [] for i in range(2): file_name = 'whatever_you_want' + str(i) ag_models.ExpectedStudentFile.objects.create( pattern=file_name, project=self.visible_public_project) files.append( SimpleUploadedFile(file_name, ('heeey' + str(i)).encode('utf-8'))) for i in range(2): obj_build.make_submission(group=self.group1, submitted_files=files) for i in range(3): obj_build.make_submission(group=self.group2, submitted_files=files) expected_submission_count = (self.group1.submissions.count() + self.group2.submissions.count()) expected_member_names = self.group1.member_names + self.group2.member_names self.assertEqual(2, ag_models.Group.objects.count()) self.client.force_authenticate(self.admin) response = self.client.post( self.get_merge_url(self.group1, self.group2)) self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertEqual(1, ag_models.Group.objects.count()) merged_group = ag_models.Group.objects.first() self.assertEqual(merged_group.to_dict(), response.data) self.assertCountEqual(expected_member_names, merged_group.member_names) self.assertEqual(expected_submission_count, merged_group.submissions.count()) for submission in merged_group.submissions.all(): for file_ in files: file_.seek(0) self.assertEqual( submission.get_file(file_.name).read(), file_.read())
def test_get_ultimate_submission_no_finished_submissions_404(self): for policy in ag_models.UltimateSubmissionPolicy: self.project.validate_and_update(ultimate_submission_policy=policy) group = self.admin_group(self.project) submission = obj_build.make_submission(group=group) self.assertEqual(1, group.submissions.count()) self.assertNotEqual( ag_models.Submission.GradingStatus.finished_grading, submission.status) self.client.force_authenticate(group.members.first()) response = self.client.get(self.ultimate_submission_url(group)) self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) submission.delete()
def setUp(self): super().setUp() self.rubric = handgrading_models.HandgradingRubric.objects.validate_and_create( project=obj_build.build_project()) ag_models.ExpectedStudentFile.objects.validate_and_create( project=self.rubric.project, pattern='*', max_num_matches=10) self.submitted_files = [ SimpleUploadedFile('file{}'.format(i), b'waaaluigi') for i in range(4) ] self.submission = obj_build.make_submission( group=obj_build.make_group(project=self.rubric.project), submitted_files=self.submitted_files)
def test_get_ultimate_only_finished_grading_status_considered(self): group = obj_build.make_group(project=self.project) ultimate_submission = obj_build.make_finished_submission(group=group) non_considered_statuses = filter( lambda val: val != ag_models.Submission.GradingStatus. finished_grading, ag_models.Submission.GradingStatus.values) for grading_status in non_considered_statuses: obj_build.make_submission(group=group, status=grading_status) self.assertEqual( 1, ag_models.Submission.objects.filter( status=ag_models.Submission.GradingStatus.finished_grading). count()) for ultimate_submission_policy in ag_models.UltimateSubmissionPolicy: self.project.validate_and_update( ultimate_submission_policy=ultimate_submission_policy) self.assertSequenceEqual([ultimate_submission], [ fdbk.submission for fdbk in get_ultimate_submissions( self.project, filter_groups=None, ag_test_preloader=AGTestPreLoader(self.project)) ])
def setUp(self): super().setUp() self.maxDiff = None submission = obj_build.make_submission() project = submission.group.project self.ag_test_suite = ag_models.AGTestSuite.objects.validate_and_create( name='kajsdhf', project=project, setup_suite_cmd_name='asdlkjfa;skldjf;aksdf' ) # type: ag_models.AGTestSuite self.ag_test_case1 = ag_models.AGTestCase.objects.validate_and_create( name='aksdbva', ag_test_suite=self.ag_test_suite) # type: ag_models.AGTestCase self.ag_test_case2 = ag_models.AGTestCase.objects.validate_and_create( name='ndkaadjhfa', ag_test_suite=self.ag_test_suite, ) # type: ag_models.AGTestCase self.ag_test_cmd1 = obj_build.make_full_ag_test_command( self.ag_test_case1, set_arbitrary_points=False, points_for_correct_return_code=4) self.ag_test_cmd2 = obj_build.make_full_ag_test_command( self.ag_test_case2, set_arbitrary_points=False, points_for_correct_return_code=5) self.total_points = 9 self.ag_test_suite_result = ag_models.AGTestSuiteResult.objects.validate_and_create( submission=submission, ag_test_suite=self.ag_test_suite ) # type: ag_models.AGTestSuiteResult self.ag_test_case_result1 = ag_models.AGTestCaseResult.objects.validate_and_create( ag_test_case=self.ag_test_case1, ag_test_suite_result=self.ag_test_suite_result ) # type: ag_models.AGTestCaseResult self.ag_test_case_result2 = ag_models.AGTestCaseResult.objects.validate_and_create( ag_test_case=self.ag_test_case2, ag_test_suite_result=self.ag_test_suite_result ) # type: ag_models.AGTestCaseResult self.cmd_result1 = obj_build.make_correct_ag_test_command_result( self.ag_test_cmd1, self.ag_test_case_result1) self.cmd_result2 = obj_build.make_correct_ag_test_command_result( self.ag_test_cmd2, self.ag_test_case_result2)
def setUp(self): self.submission = obj_build.make_submission() self.project = self.submission.group.project self.ag_suite = obj_build.make_ag_test_suite(self.project) self.ag_suite = ag_models.AGTestSuite.objects.validate_and_create( name='kajsdhf', project=self.project) self.case = obj_build.make_ag_test_case(self.ag_suite) # Make sure that ag tests and ag test results don't have # overlapping pks. for i in range(20): self.case.delete() self.case.pk = None self.case.save() self.suite_result = ag_models.AGTestSuiteResult.objects.validate_and_create( ag_test_suite=self.ag_suite, submission=self.submission )
def test_get_ultimate_submission_no_finished_submissions(self): group_with_finished_submissions_data = self.prepare_data( self.project)[0] group_with_no_finished_submissions = obj_build.make_group( project=self.project) unfinished_submission = obj_build.make_submission( group=group_with_no_finished_submissions) self.project.validate_and_update(ultimate_submission_policy=ag_models. UltimateSubmissionPolicy.most_recent) self.assertEqual( 1, group_with_no_finished_submissions.submissions.count()) self.assertNotEqual( ag_models.Submission.GradingStatus.finished_grading, unfinished_submission.status) ultimate_submissions = [ fdbk.submission for fdbk in get_ultimate_submissions( self.project, filter_groups=None, ag_test_preloader=AGTestPreLoader(self.project)) ] self.assertSequenceEqual( [group_with_finished_submissions_data.most_recent_submission], ultimate_submissions) self.project.validate_and_update( ultimate_submission_policy=ag_models.UltimateSubmissionPolicy.best) self.assertEqual( 1, group_with_no_finished_submissions.submissions.count()) self.assertNotEqual( ag_models.Submission.GradingStatus.finished_grading, unfinished_submission.status) ultimate_submissions = [ fdbk.submission for fdbk in get_ultimate_submissions( self.project, filter_groups=None, ag_test_preloader=AGTestPreLoader(self.project)) ] self.assertSequenceEqual( [group_with_finished_submissions_data.best_submission], ultimate_submissions)
def setUp(self): super().setUp() handgrading_rubric = ( handgrading_models.HandgradingRubric.objects.validate_and_create( points_style=handgrading_models.PointsStyle. start_at_max_and_subtract, max_points=0, show_grades_and_rubric_to_students=False, handgraders_can_leave_comments=True, handgraders_can_adjust_points=True, project=obj_build.build_project())) location_data = { "first_line": 0, "last_line": 1, "filename": "test.cpp" } annotation = handgrading_models.Annotation.objects.validate_and_create( handgrading_rubric=handgrading_rubric) submission = obj_build.make_submission( submitted_filenames=["test.cpp"]) self.handgrading_result = ( handgrading_models.HandgradingResult.objects.validate_and_create( submission=submission, group=submission.group, handgrading_rubric=handgrading_rubric)) applied_annotation_data = { "location": location_data, "annotation": annotation, "handgrading_result": self.handgrading_result } self.applied_annotation = handgrading_models.AppliedAnnotation.objects.validate_and_create( **applied_annotation_data) self.course = handgrading_rubric.project.course self.client = APIClient() self.url = reverse( 'applied_annotations', kwargs={'handgrading_result_pk': self.handgrading_result.pk})
def setUp(self): super().setUp() project_filename = 'filey.txt' self.retcode_points = 42 self.cmd = obj_build.make_full_ag_test_command( set_arbitrary_expected_vals=False, set_arbitrary_points=False, cmd='touch {}'.format(project_filename), expected_return_code=ag_models.ExpectedReturnCode.zero, points_for_correct_return_code=self.retcode_points) self.ag_suite = self.cmd.ag_test_case.ag_test_suite self.project = self.ag_suite.project self.project_file = ag_models.InstructorFile.objects.validate_and_create( project=self.project, file_obj=SimpleUploadedFile(project_filename, b'asdkfasdjkf')) self.group = obj_build.make_group(project=self.project) self.ag_suite.instructor_files_needed.add(self.project_file) self.submission = obj_build.make_submission(group=self.group)