Merge pull request #19412 from edx/schen/frozen_grades

Add grades_frozen flag to grading info api for Gradebook
This commit is contained in:
Simon Chen
2018-12-11 10:02:22 -05:00
committed by GitHub
3 changed files with 29 additions and 61 deletions

View File

@@ -261,6 +261,7 @@ class CourseGradingView(BaseCourseView):
results = {
'assignment_types': self._get_assignment_types(course),
'subsections': self._get_subsections(course, graded_only),
'grades_frozen': are_grades_frozen(course_key),
}
return Response(results)

View File

@@ -61,8 +61,6 @@ class CourseGradingViewTest(SharedModuleStoreTestCase, APITestCase):
"""
Sets up the structure of the test course.
"""
course.self_paced = True
cls.section = ItemFactory.create(
parent_location=course.location,
category="chapter",
@@ -128,16 +126,8 @@ class CourseGradingViewTest(SharedModuleStoreTestCase, APITestCase):
}
)
def test_student_fails(self):
self.client.login(username=self.student.username, password=self.password)
resp = self.client.get(self.get_url(self.course_key))
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
def test_staff_succeeds(self):
self.client.login(username=self.staff.username, password=self.password)
resp = self.client.get(self.get_url(self.course_key))
self.assertEqual(resp.status_code, status.HTTP_200_OK)
expected_data = {
def _get_expected_data(self):
return {
'assignment_types': {
'Final Exam': {
'drop_count': 0,
@@ -197,64 +187,40 @@ class CourseGradingViewTest(SharedModuleStoreTestCase, APITestCase):
'module_id': text_type(self.midterm.location),
'short_label': 'Midterm 01',
},
]
],
'grades_frozen': False,
}
def test_student_fails(self):
self.client.login(username=self.student.username, password=self.password)
resp = self.client.get(self.get_url(self.course_key))
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
def test_staff_succeeds(self):
self.client.login(username=self.staff.username, password=self.password)
resp = self.client.get(self.get_url(self.course_key))
self.assertEqual(resp.status_code, status.HTTP_200_OK)
expected_data = self._get_expected_data()
self.assertEqual(expected_data, resp.data)
def test_staff_succeeds_graded_only(self):
self.client.login(username=self.staff.username, password=self.password)
resp = self.client.get(self.get_url(self.course_key), {'graded_only': True})
self.assertEqual(resp.status_code, status.HTTP_200_OK)
expected_data = {
'assignment_types': {
'Final Exam': {
'drop_count': 0,
'min_count': 1,
'short_label': 'Final',
'type': 'Final Exam',
'weight': 0.4
},
'Homework': {
'drop_count': 2,
'min_count': 12,
'short_label': 'HW',
'type': 'Homework',
'weight': 0.15
},
'Lab': {
'drop_count': 2,
'min_count': 12,
'short_label': 'Lab',
'type': 'Lab',
'weight': 0.15
},
'Midterm Exam': {
'drop_count': 0,
'min_count': 1,
'short_label': 'Midterm',
'type': 'Midterm Exam',
'weight': 0.3
}
},
'subsections': [
{
'assignment_type': 'Homework',
'display_name': self.homework.display_name,
'graded': True,
'module_id': text_type(self.homework.location),
'short_label': 'HW 01',
},
{
'assignment_type': 'Midterm Exam',
'display_name': self.midterm.display_name,
'graded': True,
'module_id': text_type(self.midterm.location),
'short_label': 'Midterm 01',
},
]
}
expected_data = self._get_expected_data()
expected_data['subsections'] = [sub for sub in expected_data['subsections'] if sub['graded']]
self.assertEqual(expected_data, resp.data)
def test_course_grade_frozen(self):
with patch('lms.djangoapps.grades.api.v1.gradebook_views.are_grades_frozen') as mock_frozen_grades:
mock_frozen_grades.return_value = True
self.client.login(username=self.staff.username, password=self.password)
resp = self.client.get(self.get_url(self.course_key))
self.assertEqual(resp.status_code, status.HTTP_200_OK)
expected_data = self._get_expected_data()
expected_data['grades_frozen'] = True
self.assertEqual(expected_data, resp.data)
class GradebookViewTestBase(GradeViewTestMixin, APITestCase):
"""

View File

@@ -366,3 +366,4 @@ def are_grades_frozen(course_key):
freeze_grade_date = course.end + timedelta(30)
now = timezone.now()
return now > freeze_grade_date
return False