Ejemplo n.º 1
0
 def set_or_create(self, course_run, **kwargs):
     """Ensures that a cached edX object exists, then properly sets values on the data property"""
     data = self.build_data_property(course_run, **kwargs)
     obj, created = self.get_or_create(course_run, data=data)
     if not created:
         obj.data = data
         obj.save()
     CachedEdxDataApi.update_cache_last_access(self.user, self.cache_type, timestamp=now_in_utc())
     return obj
Ejemplo n.º 2
0
 def set_or_create(self, course_run, **kwargs):
     """Ensures that a cached edX object exists, then properly sets values on the data property"""
     data = self.build_data_property(course_run, **kwargs)
     obj, created = self.get_or_create(course_run, data=data)
     if not created:
         obj.data = data
         obj.save()
     CachedEdxDataApi.update_cache_last_access(self.user,
                                               self.cache_type,
                                               timestamp=now_in_utc())
     return obj
Ejemplo n.º 3
0
    def test_update_cache_last_access(self):
        """Test for update_cache_last_access"""
        with self.assertRaises(ValueError):
            CachedEdxDataApi.update_cache_last_access(self.user, 'footype')
        assert UserCacheRefreshTime.objects.filter(user=self.user).exists() is False

        CachedEdxDataApi.update_cache_last_access(self.user, CachedEdxDataApi.ENROLLMENT)
        cache_time = UserCacheRefreshTime.objects.get(user=self.user)
        assert cache_time.enrollment <= now_in_utc()
        assert cache_time.certificate is None
        assert cache_time.current_grade is None

        old_timestamp = now_in_utc() - timedelta(days=1)
        CachedEdxDataApi.update_cache_last_access(self.user, CachedEdxDataApi.ENROLLMENT, old_timestamp)
        cache_time.refresh_from_db()
        assert cache_time.enrollment == old_timestamp
    def test_update_cache_last_access(self):
        """Test for update_cache_last_access"""
        with self.assertRaises(ValueError):
            CachedEdxDataApi.update_cache_last_access(self.user, 'footype')
        assert UserCacheRefreshTime.objects.filter(
            user=self.user).exists() is False

        CachedEdxDataApi.update_cache_last_access(self.user,
                                                  CachedEdxDataApi.ENROLLMENT)
        cache_time = UserCacheRefreshTime.objects.get(user=self.user)
        assert cache_time.enrollment <= now_in_utc()
        assert cache_time.certificate is None
        assert cache_time.current_grade is None

        old_timestamp = now_in_utc() - timedelta(days=1)
        CachedEdxDataApi.update_cache_last_access(self.user,
                                                  CachedEdxDataApi.ENROLLMENT,
                                                  old_timestamp)
        cache_time.refresh_from_db()
        assert cache_time.enrollment == old_timestamp