def test_single_problem(self, _get_current_task): vertical = ItemFactory.create( parent_location=self.problem_section.location, category='vertical', metadata={'graded': True}, display_name='Problem Vertical' ) self.define_option_problem(u'Pröblem1', parent=vertical) self.submit_student_answer(self.student_1.username, u'Pröblem1', ['Option 1']) result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset({'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) problem_name = u'Homework 1: Problem - Pröblem1' header_row = self.csv_header_row + [problem_name + ' (Earned)', problem_name + ' (Possible)'] self.verify_rows_in_csv([ dict(zip( header_row, [ unicode(self.student_1.id), self.student_1.email, self.student_1.username, '0.01', '1.0', '2.0'] )), dict(zip( header_row, [ unicode(self.student_2.id), self.student_2.email, self.student_2.username, '0.0', 'N/A', 'N/A' ] )) ])
def test_cohort_content(self): self.submit_student_answer(self.alpha_user.username, u'Pröblem0', ['Option 1', 'Option 1']) resp = self.submit_student_answer(self.alpha_user.username, u'Pröblem1', ['Option 1', 'Option 1']) self.assertEqual(resp.status_code, 404) resp = self.submit_student_answer(self.beta_user.username, u'Pröblem0', ['Option 1', 'Option 2']) self.assertEqual(resp.status_code, 404) self.submit_student_answer(self.beta_user.username, u'Pröblem1', ['Option 1', 'Option 2']) with patch('instructor_task.tasks_helper._get_current_task'): result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( { 'action_name': 'graded', 'attempted': 4, 'succeeded': 4, 'failed': 0 }, result) problem_names = [ u'Homework 1: Problem - Pröblem0', u'Homework 1: Problem - Pröblem1' ] header_row = [u'Student ID', u'Email', u'Username', u'Final Grade'] for problem in problem_names: header_row += [problem + ' (Earned)', problem + ' (Possible)'] self.verify_rows_in_csv([ dict( zip(header_row, [ unicode(self.staff_user.id), self.staff_user.email, self.staff_user.username, u'0.0', u'N/A', u'N/A', u'N/A', u'N/A' ])), dict( zip(header_row, [ unicode(self.alpha_user.id), self.alpha_user.email, self.alpha_user.username, u'1.0', u'2.0', u'2.0', u'N/A', u'N/A' ])), dict( zip(header_row, [ unicode(self.beta_user.id), self.beta_user.email, self.beta_user.username, u'0.5', u'N/A', u'N/A', u'1.0', u'2.0' ])), dict( zip(header_row, [ unicode(self.non_cohorted_user.id), self.non_cohorted_user.email, self.non_cohorted_user.username, u'0.0', u'N/A', u'N/A', u'N/A', u'N/A' ])), ])
def test_grading_failure(self, mock_iterate_grades_for, _mock_current_task): """ Test that any grading errors are properly reported in the progress dict and uploaded to the report store. """ # mock an error response from `iterate_grades_for` student = self.create_student(u'username', u'*****@*****.**') error_message = u'Cannöt grade student' mock_iterate_grades_for.return_value = [(student, {}, error_message)] result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( { 'attempted': 1, 'succeeded': 0, 'failed': 1 }, result) report_store = ReportStore.from_config() self.assertTrue( any('grade_report_err' in item[0] for item in report_store.links_for(self.course.id))) self.verify_rows_in_csv([{ u'Student ID': unicode(student.id), u'Email': student.email, u'Username': student.username, u'error_msg': error_message }])
def test_single_problem(self, _get_current_task): vertical = ItemFactory.create( parent_location=self.problem_section.location, category='vertical', metadata={'graded': True}, display_name='Problem Vertical') self.define_option_problem(u'Pröblem1', parent=vertical) self.submit_student_answer(self.student_1.username, u'Pröblem1', ['Option 1']) result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( { 'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0 }, result) problem_name = u'Homework 1: Problem - Pröblem1' header_row = self.csv_header_row + [ problem_name + ' (Earned)', problem_name + ' (Possible)' ] self.verify_rows_in_csv([ dict( zip(header_row, [ unicode(self.student_1.id), self.student_1.email, self.student_1.username, '0.01', '1.0', '2.0' ])), dict( zip(header_row, [ unicode(self.student_2.id), self.student_2.email, self.student_2.username, '0.0', 'N/A', 'N/A' ])) ])
def test_no_problems(self, _get_current_task): """ Verify that we see no grade information for a course with no graded problems. """ result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( { 'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0 }, result) self.verify_rows_in_csv([ dict( zip(self.csv_header_row, [ unicode(self.student_1.id), self.student_1.email, self.student_1.username, '0.0' ])), dict( zip(self.csv_header_row, [ unicode(self.student_2.id), self.student_2.email, self.student_2.username, '0.0' ])) ])
def test_grading_failure(self, error_message, mock_iterate_grades_for, _mock_current_task): """ Test that any grading errors are properly reported in the progress dict and uploaded to the report store. """ # mock an error response from `iterate_grades_for` student = self.create_student(u'username', u'*****@*****.**') mock_iterate_grades_for.return_value = [ (student, {}, error_message) ] result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( {'attempted': 1, 'succeeded': 0, 'failed': 1}, result) report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD') self.assertTrue(any('grade_report_err' in item[0] for item in report_store.links_for(self.course.id))) self.verify_rows_in_csv([ { u'Student ID': unicode(student.id), u'Email': student.email, u'Username': student.username, u'error_msg': error_message if error_message else "Unknown error" } ])
def test_cohort_content(self): self.submit_student_answer(self.alpha_user.username, u'Pröblem0', ['Option 1', 'Option 1']) resp = self.submit_student_answer(self.alpha_user.username, u'Pröblem1', ['Option 1', 'Option 1']) self.assertEqual(resp.status_code, 404) resp = self.submit_student_answer(self.beta_user.username, u'Pröblem0', ['Option 1', 'Option 2']) self.assertEqual(resp.status_code, 404) self.submit_student_answer(self.beta_user.username, u'Pröblem1', ['Option 1', 'Option 2']) with patch('instructor_task.tasks_helper._get_current_task'): result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( {'action_name': 'graded', 'attempted': 4, 'succeeded': 4, 'failed': 0}, result ) problem_names = [u'Homework 1: Problem - Pröblem0', u'Homework 1: Problem - Pröblem1'] header_row = [u'Student ID', u'Email', u'Username', u'Final Grade'] for problem in problem_names: header_row += [problem + ' (Earned)', problem + ' (Possible)'] self.verify_rows_in_csv([ dict(zip( header_row, [ unicode(self.staff_user.id), self.staff_user.email, self.staff_user.username, u'0.0', u'N/A', u'N/A', u'N/A', u'N/A' ] )), dict(zip( header_row, [ unicode(self.alpha_user.id), self.alpha_user.email, self.alpha_user.username, u'1.0', u'2.0', u'2.0', u'N/A', u'N/A' ] )), dict(zip( header_row, [ unicode(self.beta_user.id), self.beta_user.email, self.beta_user.username, u'0.5', u'N/A', u'N/A', u'1.0', u'2.0' ] )), dict(zip( header_row, [ unicode(self.non_cohorted_user.id), self.non_cohorted_user.email, self.non_cohorted_user.username, u'0.0', u'N/A', u'N/A', u'N/A', u'N/A' ] )), ])
def test_problem_grade_report(self): """ Test that we generate the correct the correct grade report when dealing with A/B tests. In order to verify that the behavior of the grade report is correct, we submit answers for problems that the student won't have access to. A/B tests won't restrict access to the problems, but it should not show up in that student's course tree when generating the grade report, hence the N/A's in the grade report. """ # student A will get 100%, student B will get 50% because # OPTION_1 is the correct option, and OPTION_2 is the # incorrect option self.submit_student_answer(self.student_a.username, self.problem_a_url, [self.OPTION_1, self.OPTION_1]) self.submit_student_answer(self.student_a.username, self.problem_b_url, [self.OPTION_1, self.OPTION_1]) self.submit_student_answer(self.student_b.username, self.problem_a_url, [self.OPTION_1, self.OPTION_2]) self.submit_student_answer(self.student_b.username, self.problem_b_url, [self.OPTION_1, self.OPTION_2]) with patch('instructor_task.tasks_helper._get_current_task'): result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( { 'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0 }, result) problem_names = [ u'Homework 1: Problem - pröblem_a_url', u'Homework 1: Problem - pröblem_b_url' ] header_row = [u'Student ID', u'Email', u'Username', u'Final Grade'] for problem in problem_names: header_row += [problem + ' (Earned)', problem + ' (Possible)'] self.verify_rows_in_csv([ dict( zip(header_row, [ unicode(self.student_a.id), self.student_a.email, self.student_a.username, u'1.0', u'2.0', u'2.0', u'N/A', u'N/A' ])), dict( zip(header_row, [ unicode(self.student_b.id), self.student_b.email, self.student_b.username, u'0.5', u'N/A', u'N/A', u'1.0', u'2.0' ])) ])
def test_problem_grade_report(self): """ Test that we generate the correct the correct grade report when dealing with A/B tests. In order to verify that the behavior of the grade report is correct, we submit answers for problems that the student won't have access to. A/B tests won't restrict access to the problems, but it should not show up in that student's course tree when generating the grade report, hence the N/A's in the grade report. """ # student A will get 100%, student B will get 50% because # OPTION_1 is the correct option, and OPTION_2 is the # incorrect option self.submit_student_answer(self.student_a.username, self.problem_a_url, [self.OPTION_1, self.OPTION_1]) self.submit_student_answer(self.student_a.username, self.problem_b_url, [self.OPTION_1, self.OPTION_1]) self.submit_student_answer(self.student_b.username, self.problem_a_url, [self.OPTION_1, self.OPTION_2]) self.submit_student_answer(self.student_b.username, self.problem_b_url, [self.OPTION_1, self.OPTION_2]) with patch('instructor_task.tasks_helper._get_current_task'): result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset( {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result ) problem_names = [u'Homework 1: Problem - pröblem_a_url', u'Homework 1: Problem - pröblem_b_url'] header_row = [u'Student ID', u'Email', u'Username', u'Final Grade'] for problem in problem_names: header_row += [problem + ' (Earned)', problem + ' (Possible)'] self.verify_rows_in_csv([ dict(zip( header_row, [ unicode(self.student_a.id), self.student_a.email, self.student_a.username, u'1.0', u'2.0', u'2.0', u'N/A', u'N/A' ] )), dict(zip( header_row, [ unicode(self.student_b.id), self.student_b.email, self.student_b.username, u'0.5', u'N/A', u'N/A', u'1.0', u'2.0' ] )) ])
def test_no_problems(self, _get_current_task): """ Verify that we see no grade information for a course with no graded problems. """ result = upload_problem_grade_report(None, None, self.course.id, None, 'graded') self.assertDictContainsSubset({'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv([ dict(zip( self.csv_header_row, [unicode(self.student_1.id), self.student_1.email, self.student_1.username, '0.0'] )), dict(zip( self.csv_header_row, [unicode(self.student_2.id), self.student_2.email, self.student_2.username, '0.0'] )) ])