예제 #1
0
 def _verify_csv_data(self, username, expected_data):
     """
     Verify grade report data.
     """
     with patch('instructor_task.tasks_helper._get_current_task'):
         upload_grades_csv(None, None, self.course.id, None, 'graded')
         report_store = ReportStore.from_config()
         report_csv_filename = report_store.links_for(self.course.id)[0][0]
         with open(report_store.path_to(self.course.id, report_csv_filename)) as csv_file:
             for row in unicodecsv.DictReader(csv_file):
                 if row.get('username') == username:
                     csv_row_data = [row[column] for column in self.columns_to_check]
                     self.assertEqual(csv_row_data, expected_data)
예제 #2
0
    def test_one_group_problem(self):
        """
        Verify that grade export works when only the Group A user
        partition receives a problem.  We expect to see a column for
        the homework where student_a's entry includes their grade, and
        student b's entry shows a 0.
        """
        problem_a_url = 'problem_a_url'
        self.define_option_problem(problem_a_url, parent=self.vertical_a)

        self.submit_student_answer(self.student_a.username, problem_a_url,
                                   [OPTION_1, OPTION_1])

        with patch('instructor_task.tasks_helper._get_current_task'):
            result = upload_grades_csv(None, None, self.course.id, None,
                                       'graded')
            self.verify_csv_task_success(result)
            self.verify_grades_in_csv([{
                self.student_a: {
                    'grade': '0.8',
                    'HW 01': '1.0',
                    'HW 02': '0.0',
                    'HW Avg': '0.8'
                }
            }, {
                self.student_b: {
                    'grade': '0.0',
                    'HW 01': '0.0',
                    'HW 02': '0.0',
                    'HW Avg': '0.0'
                }
            }],
                                      ignore_other_columns=True)
    def test_both_groups_problems(self):
        """
        Verify that grade export works when each user partition
        receives (different) problems.  Each user's grade on their
        particular problem should show up in the grade report.
        """
        problem_a_url = 'problem_a_url'
        problem_b_url = 'problem_b_url'
        self.define_option_problem(problem_a_url, parent=self.vertical_a)
        self.define_option_problem(problem_b_url, parent=self.vertical_b)
        # 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, problem_a_url, [OPTION_1, OPTION_1])
        self.submit_student_answer(self.student_b.username, problem_b_url, [OPTION_1, OPTION_2])

        with patch('instructor_task.tasks_helper._get_current_task'):
            result = upload_grades_csv(None, None, self.course.id, None, 'graded')
            self.verify_csv_task_success(result)
            self.verify_grades_in_csv(
                [
                    {self.student_a: {'grade': '1.0', 'HW': '1.0'}},
                    {self.student_b: {'grade': '0.5', 'HW': '0.5'}}
                ],
                ignore_other_columns=True
            )
예제 #4
0
    def test_both_groups_problems(self):
        """
        Verify that grade export works when each user partition
        receives (different) problems.  Each user's grade on their
        particular problem should show up in the grade report.
        """
        problem_a_url = 'problem_a_url'
        problem_b_url = 'problem_b_url'
        self.define_option_problem(problem_a_url, parent=self.vertical_a)
        self.define_option_problem(problem_b_url, parent=self.vertical_b)
        # 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, problem_a_url,
                                   [OPTION_1, OPTION_1])
        self.submit_student_answer(self.student_b.username, problem_b_url,
                                   [OPTION_1, OPTION_2])

        with patch('instructor_task.tasks_helper._get_current_task'):
            result = upload_grades_csv(None, None, self.course.id, None,
                                       'graded')
            self.verify_csv_task_success(result)
            self.verify_grades_in_csv([{
                self.student_a: {
                    'grade': '1.0',
                    'HW': '1.0'
                }
            }, {
                self.student_b: {
                    'grade': '0.5',
                    'HW': '0.5'
                }
            }],
                                      ignore_other_columns=True)
예제 #5
0
 def _verify_cell_data_for_user(self, username, course_id, column_header, expected_cell_content):
     """
     Verify cell data in the grades CSV for a particular user.
     """
     with patch('instructor_task.tasks_helper._get_current_task'):
         result = upload_grades_csv(None, None, course_id, None, 'graded')
         self.assertDictContainsSubset({'attempted': 2, 'succeeded': 2, 'failed': 0}, result)
         report_store = ReportStore.from_config()
         report_csv_filename = report_store.links_for(course_id)[0][0]
         with open(report_store.path_to(course_id, report_csv_filename)) as csv_file:
             for row in unicodecsv.DictReader(csv_file):
                 if row.get('username') == username:
                     self.assertEqual(row[column_header], expected_cell_content)
예제 #6
0
 def _verify_cell_data_for_user(self, username, course_id, column_header, expected_cell_content):
     """
     Verify cell data in the grades CSV for a particular user.
     """
     with patch('instructor_task.tasks_helper._get_current_task'):
         result = upload_grades_csv(None, None, course_id, None, 'graded')
         self.assertDictContainsSubset({'attempted': 2, 'succeeded': 2, 'failed': 0}, result)
         report_store = ReportStore.from_config()
         report_csv_filename = report_store.links_for(course_id)[0][0]
         with open(report_store.path_to(course_id, report_csv_filename)) as csv_file:
             for row in unicodecsv.DictReader(csv_file):
                 if row.get('username') == username:
                     self.assertEqual(row[column_header], expected_cell_content)
예제 #7
0
    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`
        mock_iterate_grades_for.return_value = [
            (self.create_student('username', '*****@*****.**'), {}, 'Cannot grade student')
        ]
        result = upload_grades_csv(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)))
예제 #8
0
    def test_unicode_emails(self, emails):
        """
        Test that students with unicode characters in emails is handled.
        """
        for i, email in enumerate(emails):
            self.create_student('student{0}'.format(i), email)

        self.current_task = Mock()
        self.current_task.update_state = Mock()
        with patch('instructor_task.tasks_helper._get_current_task') as mock_current_task:
            mock_current_task.return_value = self.current_task
            result = upload_grades_csv(None, None, self.course.id, None, 'graded')
        num_students = len(emails)
        self.assertDictContainsSubset({'attempted': num_students, 'succeeded': num_students, 'failed': 0}, result)
예제 #9
0
 def test_unicode_in_csv_header(self, mock_iterate_grades_for, _mock_current_task):
     """
     Tests that CSV grade report works if unicode in headers.
     """
     # mock a response from `iterate_grades_for`
     mock_iterate_grades_for.return_value = [
         (
             self.create_student('username', '*****@*****.**'),
             {'section_breakdown': [{'label': u'\u8282\u540e\u9898 01'}], 'percent': 0},
             'Cannot grade student'
         )
     ]
     result = upload_grades_csv(None, None, self.course.id, None, 'graded')
     self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result)
예제 #10
0
    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`
        mock_iterate_grades_for.return_value = [
            (self.create_student('username', '*****@*****.**'), {}, 'Cannot grade student')
        ]
        result = upload_grades_csv(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)))
예제 #11
0
 def test_unicode_in_csv_header(self, mock_iterate_grades_for, _mock_current_task):
     """
     Tests that CSV grade report works if unicode in headers.
     """
     # mock a response from `iterate_grades_for`
     mock_iterate_grades_for.return_value = [
         (
             self.create_student('username', '*****@*****.**'),
             {'section_breakdown': [{'label': u'\u8282\u540e\u9898 01'}], 'percent': 0, 'grade': None},
             'Cannot grade student'
         )
     ]
     result = upload_grades_csv(None, None, self.course.id, None, 'graded')
     self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result)
예제 #12
0
    def test_unicode_emails(self, emails):
        """
        Test that students with unicode characters in emails is handled.
        """
        for i, email in enumerate(emails):
            self.create_student('student{0}'.format(i), email)

        self.current_task = Mock()
        self.current_task.update_state = Mock()
        with patch('instructor_task.tasks_helper._get_current_task') as mock_current_task:
            mock_current_task.return_value = self.current_task
            result = upload_grades_csv(None, None, self.course.id, None, 'graded')
        num_students = len(emails)
        self.assertDictContainsSubset({'attempted': num_students, 'succeeded': num_students, 'failed': 0}, result)
예제 #13
0
    def create_rows(self):
        """
        Creates CSV rows for the provided emails.
        """
        result_store = Mock(rows=[])
        current_task = Mock(update_state=Mock())

        def csv_rows_interceptor(rows, *_args, **_kwargs):
            """
            Mock the upload_csv_to_report_store to return the csv rows.
            """
            result_store.rows = rows

        self.create_student('student1', self.EMAIL_WITH_ID)
        self.create_student('student2', self.EMAIL_WITHOUT_ID)

        with patch('instructor_task.tasks_helper.upload_csv_to_report_store',
                   side_effect=csv_rows_interceptor):
            with patch('instructor_task.tasks_helper._get_current_task'
                       ) as mock_current_task:
                mock_current_task.return_value = current_task
                upload_grades_csv(None, None, self.course.id, None, 'graded')

        return result_store.rows
    def _verify_cohort_data(self, course_id, expected_cohort_groups):
        """
        Verify cohort data.
        """
        cohort_groups_in_csv = []
        with patch('instructor_task.tasks_helper._get_current_task'):
            result = upload_grades_csv(None, None, course_id, None, 'graded')
            self.assertDictContainsSubset({'attempted': 2, 'succeeded': 2, 'failed': 0}, result)
            report_store = ReportStore.from_config()
            report_csv_filename = report_store.links_for(course_id)[0][0]
            with open(report_store.path_to(course_id, report_csv_filename)) as csv_file:
                for row in unicodecsv.DictReader(csv_file):
                    cohort_groups_in_csv.append(row['Cohort Group Name'])

        self.assertEqual(cohort_groups_in_csv, expected_cohort_groups)
    def _verify_cohort_data(self, course_id, expected_cohort_groups):
        """
        Verify cohort data.
        """
        cohort_groups_in_csv = []
        with patch('instructor_task.tasks_helper._get_current_task'):
            result = upload_grades_csv(None, None, course_id, None, 'graded')
            self.assertDictContainsSubset({'attempted': 2, 'succeeded': 2, 'failed': 0}, result)
            report_store = ReportStore.from_config()
            report_csv_filename = report_store.links_for(course_id)[0][0]
            with open(report_store.path_to(course_id, report_csv_filename)) as csv_file:
                for row in unicodecsv.DictReader(csv_file):
                    cohort_groups_in_csv.append(row['Cohort Name'])

        self.assertEqual(cohort_groups_in_csv, expected_cohort_groups)
예제 #16
0
    def test_one_group_problem(self):
        """
        Verify that grade export works when only the Group A user
        partition receives a problem.  We expect to see a column for
        the homework where student_a's entry includes their grade, and
        student b's entry shows a 0.
        """
        problem_a_url = "problem_a_url"
        self.define_option_problem(problem_a_url, parent=self.vertical_a)

        self.submit_student_answer(self.student_a.username, problem_a_url, [OPTION_1, OPTION_1])

        with patch("instructor_task.tasks_helper._get_current_task"):
            result = upload_grades_csv(None, None, self.course.id, None, "graded")
            self.verify_csv_task_success(result)
            self.verify_grades_in_csv(
                [{self.student_a: {"grade": "1.0", "HW": "1.0"}}, {self.student_b: {"grade": "0.0", "HW": "0.0"}}]
            )
    def test_one_group_problem(self):
        """
        Verify that grade export works when only the Group A user
        partition receives a problem.  We expect to see a column for
        the homework where student_a's entry includes their grade, and
        student b's entry shows a 0.
        """
        problem_a_url = 'problem_a_url'
        self.define_option_problem(problem_a_url, parent=self.vertical_a)

        self.submit_student_answer(self.student_a.username, problem_a_url,
                                   [OPTION_1, OPTION_1])

        with patch('instructor_task.tasks_helper._get_current_task'):
            result = upload_grades_csv(None, None, self.course.id, None,
                                       'graded')
            self.verify_csv_task_success(result)
            self.verify_grades_in_csv(
                [
                    {self.student_a: {'grade': '0.8', 'HW 01': '1.0', 'HW 02': '0.0', 'HW Avg': '0.8'}},
                    {self.student_b: {'grade': '0.0', 'HW 01': '0.0', 'HW 02': '0.0', 'HW Avg': '0.0'}}
                ],
                ignore_other_columns=True
            )