def test_persistent_grades_enabled_on_course(self, default_store, num_mongo_queries, num_sql_queries): with self.store.default_store(default_store): self.set_up_course(enable_persistent_grades=True) with check_mongo_calls(num_mongo_queries): with self.assertNumQueries(num_sql_queries): self._apply_recalculate_subsection_grade() self.assertIsNotNone(PersistentCourseGrade.read(self.user.id, self.course.id)) self.assertGreater(len(PersistentSubsectionGrade.bulk_read_grades(self.user.id, self.course.id)), 0)
def test_persistent_grades_enabled_on_course(self, default_store, num_mongo_queries, num_sql_queries): with self.store.default_store(default_store): self.set_up_course(enable_persistent_grades=True) with check_mongo_calls(num_mongo_queries): with self.assertNumQueries(num_sql_queries): self._apply_recalculate_subsection_grade() self.assertIsNotNone(PersistentCourseGrade.read(self.user.id, self.course.id)) self.assertGreater(len(PersistentSubsectionGrade.bulk_read_grades(self.user.id, self.course.id)), 0)
def test_persistent_grades_not_enabled_on_course(self, default_store, num_mongo_queries, num_sql_queries): with self.store.default_store(default_store): self.set_up_course(enable_persistent_grades=False) with check_mongo_calls(num_mongo_queries): with self.assertNumQueries(num_sql_queries): self._apply_recalculate_subsection_grade() with self.assertRaises(PersistentCourseGrade.DoesNotExist): PersistentCourseGrade.read(self.user.id, self.course.id) self.assertEqual(len(PersistentSubsectionGrade.bulk_read_grades(self.user.id, self.course.id)), 0)
def test_persistent_grades_not_enabled_on_course(self, default_store, num_mongo_queries, num_sql_queries): with self.store.default_store(default_store): self.set_up_course(enable_persistent_grades=False) with check_mongo_calls(num_mongo_queries): with self.assertNumQueries(num_sql_queries): self._apply_recalculate_subsection_grade() with self.assertRaises(PersistentCourseGrade.DoesNotExist): PersistentCourseGrade.read(self.user.id, self.course.id) self.assertEqual(len(PersistentSubsectionGrade.bulk_read_grades(self.user.id, self.course.id)), 0)
def get_subsection_grades(user_id, course_key_or_id): """ Return dictionary of grades for user_id. """ course_key = _get_key(course_key_or_id, CourseKey) grades = {} for grade in _PersistentSubsectionGrade.bulk_read_grades(user_id, course_key): grades[grade.usage_key] = grade return grades
def _get_bulk_cached_subsection_grades(self): """ Returns and caches (for future access) the results of a bulk retrieval of all subsection grades in the course. """ if self._cached_subsection_grades is None: self._cached_subsection_grades = { record.full_usage_key: record for record in PersistentSubsectionGrade.bulk_read_grades(self.student.id, self.course.id) } return self._cached_subsection_grades
def _get_saved_subsection_grade(self, subsection_usage_key): """ Returns the saved value of the subsection grade for the given subsection usage key, caching the value. Returns None if not found. """ if self._cached_subsection_grades is None: self._cached_subsection_grades = { record.full_usage_key: record for record in PersistentSubsectionGrade.bulk_read_grades(self.student.id, self.course.id) } return self._cached_subsection_grades.get(subsection_usage_key)
def _get_saved_subsection_grade(self, subsection_usage_key): """ Returns the saved value of the subsection grade for the given subsection usage key, caching the value. Returns None if not found. """ if self._cached_subsection_grades is None: self._cached_subsection_grades = { record.full_usage_key: record for record in PersistentSubsectionGrade.bulk_read_grades(self.student.id, self.course.id) } return self._cached_subsection_grades.get(subsection_usage_key)