storing work
This commit is contained in:
18
cms/djangoapps/contentstore/tests/test_core_caching.py
Normal file
18
cms/djangoapps/contentstore/tests/test_core_caching.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from django.test.testcases import TestCase
|
||||
from cache_toolbox.core import get_cached_content, set_cached_content
|
||||
import mock
|
||||
|
||||
class CachingTestCase(TestCase):
|
||||
# Tests for https://edx.lighthouseapp.com/projects/102637/tickets/112-updating-asset-does-not-refresh-the-cached-copy
|
||||
def test_put_and_get(self):
|
||||
mockAsset = mock.Mock()
|
||||
mockLocation = mock.Mock()
|
||||
mockLocation.category = u'thumbnail'
|
||||
mockLocation.name = u'monsters.jpg'
|
||||
mockLocation.course = u'800'
|
||||
mockLocation.tag = u'c4x'
|
||||
mockLocation.org = u'mitX'
|
||||
mockLocation.revision = None
|
||||
mockAsset.location = mockLocation
|
||||
set_cached_content(mockAsset)
|
||||
cachedAsset = get_cached_content(mockLocation)
|
||||
@@ -753,8 +753,7 @@ def upload_asset(request, org, course, coursename):
|
||||
# nomenclature since we're using a FileSystem paradigm here. We're just imposing
|
||||
# the Location string formatting expectations to keep things a bit more consistent
|
||||
|
||||
# unicode needed for cache equivalency
|
||||
filename = unicode(request.FILES['file'].name)
|
||||
filename = request.FILES['file'].name
|
||||
mime_type = request.FILES['file'].content_type
|
||||
filedata = request.FILES['file'].read()
|
||||
|
||||
|
||||
@@ -108,11 +108,23 @@ def instance_key(model, instance_or_pk):
|
||||
getattr(instance_or_pk, 'pk', instance_or_pk),
|
||||
)
|
||||
|
||||
import logging
|
||||
|
||||
def set_cached_content(content):
|
||||
cache.set(content.get_id(), content)
|
||||
logging.warn("set cached---------------------------------------")
|
||||
logging.warn(str(content.location))
|
||||
cache.set(str(content.location), content)
|
||||
|
||||
def get_cached_content(location):
|
||||
return cache.get(StaticContent.get_id_from_location(location))
|
||||
logging.warn("get cached------------------------")
|
||||
logging.warn(str(location))
|
||||
logging.warn(StaticContent.get_id_from_location(location))
|
||||
return cache.get(str(location))
|
||||
|
||||
def del_cached_content(location):
|
||||
cache.delete(StaticContent.get_id_from_location(location))
|
||||
if cache.get(str(location)) is None:
|
||||
logging.err('nothing in cache for: ' + str(location))
|
||||
logging.warn("deleted cache----------")
|
||||
logging.warn(str(location))
|
||||
logging.warn(StaticContent.get_id_from_location(location))
|
||||
cache.delete(str(location))
|
||||
|
||||
@@ -29,14 +29,12 @@ class StaticContent(object):
|
||||
|
||||
@staticmethod
|
||||
def generate_thumbnail_name(original_name):
|
||||
# unicode needed for cache equivalency
|
||||
return unicode(('{0}'+XASSET_THUMBNAIL_TAIL_NAME).format(os.path.splitext(original_name)[0]))
|
||||
return ('{0}'+XASSET_THUMBNAIL_TAIL_NAME).format(os.path.splitext(original_name)[0])
|
||||
|
||||
@staticmethod
|
||||
def compute_location(org, course, name, revision=None, is_thumbnail=False):
|
||||
name = name.replace('/', '_')
|
||||
# unicode needed for cache equivalency
|
||||
return Location([unicode(XASSET_LOCATION_TAG), org, course, u'asset' if not is_thumbnail else u'thumbnail', Location.clean(name), revision])
|
||||
return Location([XASSET_LOCATION_TAG, org, course, 'asset' if not is_thumbnail else 'thumbnail', Location.clean(name), revision])
|
||||
|
||||
def get_id(self):
|
||||
return StaticContent.get_id_from_location(self.location)
|
||||
|
||||
Reference in New Issue
Block a user