From c6c92230c5ef927d836c086275a5a3edecad4f3a Mon Sep 17 00:00:00 2001 From: George Schneeloch Date: Mon, 28 Sep 2015 17:25:29 +0000 Subject: [PATCH 1/2] Fixed min_count KeyError --- lms/djangoapps/ccx/tests/test_views.py | 54 ++++++++++++++++++++++++++ lms/djangoapps/ccx/views.py | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index 7ec56e5df6..fcce7146a8 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -265,6 +265,60 @@ class TestCoachDashboard(SharedModuleStoreTestCase, LoginEnrollmentTestCase): self.assertEqual(policy['GRADER'][3]['type'], 'Final Exam') self.assertEqual(policy['GRADER'][3]['min_count'], 0) + @patch('ccx.views.render_to_response', intercept_renderer) + def test_save_without_min_count(self): + """ + POST grading policy without min_count field. + """ + self.make_coach() + ccx = self.make_ccx() + + course_id = CCXLocator.from_course_locator(self.course.id, ccx.id) + save_policy_url = reverse( + 'ccx_set_grading_policy', kwargs={'course_id': course_id}) + + # This policy doesn't include a min_count field + policy = { + "GRADE_CUTOFFS": { + "Pass": 0.5 + }, + "GRADER": [ + { + "weight": 0.15, + "type": "Homework", + "drop_count": 2, + "short_label": "HW" + } + ] + } + + response = self.client.post( + save_policy_url, {"policy": json.dumps(policy)} + ) + self.assertEqual(response.status_code, 302) + + ccx = CustomCourseForEdX.objects.get() + + # Make sure grading policy adjusted + policy = get_override_for_ccx( + ccx, self.course, 'grading_policy', self.course.grading_policy + ) + self.assertEqual(len(policy['GRADER']), 1) + self.assertEqual(policy['GRADER'][0]['type'], 'Homework') + self.assertNotIn('min_count', policy['GRADER'][0]) + + save_ccx_url = reverse('save_ccx', kwargs={'course_id': course_id}) + coach_dashboard_url = reverse( + 'ccx_coach_dashboard', + kwargs={'course_id': course_id} + ) + response = self.client.get(coach_dashboard_url) + schedule = json.loads(response.mako_context['schedule']) # pylint: disable=no-member + response = self.client.post( + save_ccx_url, json.dumps(schedule), content_type='application/json' + ) + self.assertEqual(response.status_code, 200) + def test_enroll_member_student(self): """enroll a list of students who are members of the class """ diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index 520e5452d3..5cc41f7625 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -254,7 +254,7 @@ def save_ccx(request, course, ccx=None): grader = policy['GRADER'] for section in grader: count = graded.get(section.get('type'), 0) - if count < section['min_count']: + if count < section.get('min_count', 0): changed = True section['min_count'] = count if changed: From 3284b7e44999fee2d81605743869bd8a3e73fbae Mon Sep 17 00:00:00 2001 From: George Schneeloch Date: Wed, 30 Sep 2015 18:26:42 +0000 Subject: [PATCH 2/2] Added myself to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index ce0886263e..dce185380c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -243,3 +243,4 @@ Michael Frey Hasnain Naveed J. Cliff Dyer Jamie Folsom +George Schneeloch