Esempio n. 1
0
    def test_get_cached_edx_data(self):
        """
        Test for get_cached_edx_data
        """
        with self.assertRaises(ValueError):
            CachedEdxDataApi.get_cached_edx_data(self.user, 'footype')

        self.assert_cache_in_db()
        for run in self.all_runs:
            CachedEnrollmentFactory.create(user=self.user, course_run=run)
            CachedCertificateFactory.create(user=self.user, course_run=run)
            CachedCurrentGradeFactory.create(user=self.user, course_run=run)
        self.assert_cache_in_db(self.all_course_run_ids, self.all_course_run_ids, self.all_course_run_ids)
Esempio n. 2
0
 def assert_cache_in_db(self, enrollment_keys=None, certificate_keys=None, grades_keys=None):
     """
     Helper function to assert the course keys in the database cache
     """
     enrollment_keys = enrollment_keys or []
     certificate_keys = certificate_keys or []
     grades_keys = grades_keys or []
     enrollments = CachedEdxDataApi.get_cached_edx_data(self.user, CachedEdxDataApi.ENROLLMENT)
     certificates = CachedEdxDataApi.get_cached_edx_data(self.user, CachedEdxDataApi.CERTIFICATE)
     grades = CachedEdxDataApi.get_cached_edx_data(self.user, CachedEdxDataApi.CURRENT_GRADE)
     assert sorted(list(enrollments.enrollments.keys())) == sorted(enrollment_keys)
     assert sorted(list(certificates.certificates.keys())) == sorted(certificate_keys)
     assert sorted(list(grades.current_grades.keys())) == sorted(grades_keys)
    def test_get_cached_edx_data(self):
        """
        Test for get_cached_edx_data
        """
        with self.assertRaises(ValueError):
            CachedEdxDataApi.get_cached_edx_data(self.user, 'footype')

        self.assert_cache_in_db()
        for run in self.all_runs:
            CachedEnrollmentFactory.create(user=self.user, course_run=run)
            CachedCertificateFactory.create(user=self.user, course_run=run)
            CachedCurrentGradeFactory.create(user=self.user, course_run=run)
        self.assert_cache_in_db(self.all_course_run_ids,
                                self.all_course_run_ids,
                                self.all_course_run_ids)
 def assert_cache_in_db(self,
                        enrollment_keys=None,
                        certificate_keys=None,
                        grades_keys=None):
     """
     Helper function to assert the course keys in the database cache
     """
     enrollment_keys = enrollment_keys or []
     certificate_keys = certificate_keys or []
     grades_keys = grades_keys or []
     enrollments = CachedEdxDataApi.get_cached_edx_data(
         self.user, CachedEdxDataApi.ENROLLMENT)
     certificates = CachedEdxDataApi.get_cached_edx_data(
         self.user, CachedEdxDataApi.CERTIFICATE)
     grades = CachedEdxDataApi.get_cached_edx_data(
         self.user, CachedEdxDataApi.CURRENT_GRADE)
     assert sorted(list(
         enrollments.enrollments.keys())) == sorted(enrollment_keys)
     assert sorted(list(
         certificates.certificates.keys())) == sorted(certificate_keys)
     assert sorted(list(
         grades.current_grades.keys())) == sorted(grades_keys)