Commit 9818664b by cahrens

storing work

parent 04614078
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): ...@@ -753,8 +753,7 @@ def upload_asset(request, org, course, coursename):
# nomenclature since we're using a FileSystem paradigm here. We're just imposing # 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 # the Location string formatting expectations to keep things a bit more consistent
# unicode needed for cache equivalency filename = request.FILES['file'].name
filename = unicode(request.FILES['file'].name)
mime_type = request.FILES['file'].content_type mime_type = request.FILES['file'].content_type
filedata = request.FILES['file'].read() filedata = request.FILES['file'].read()
......
...@@ -108,11 +108,23 @@ def instance_key(model, instance_or_pk): ...@@ -108,11 +108,23 @@ def instance_key(model, instance_or_pk):
getattr(instance_or_pk, 'pk', instance_or_pk), getattr(instance_or_pk, 'pk', instance_or_pk),
) )
import logging
def set_cached_content(content): 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): 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): 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): ...@@ -29,14 +29,12 @@ class StaticContent(object):
@staticmethod @staticmethod
def generate_thumbnail_name(original_name): def generate_thumbnail_name(original_name):
# unicode needed for cache equivalency return ('{0}'+XASSET_THUMBNAIL_TAIL_NAME).format(os.path.splitext(original_name)[0])
return unicode(('{0}'+XASSET_THUMBNAIL_TAIL_NAME).format(os.path.splitext(original_name)[0]))
@staticmethod @staticmethod
def compute_location(org, course, name, revision=None, is_thumbnail=False): def compute_location(org, course, name, revision=None, is_thumbnail=False):
name = name.replace('/', '_') name = name.replace('/', '_')
# unicode needed for cache equivalency return Location([XASSET_LOCATION_TAG, org, course, 'asset' if not is_thumbnail else 'thumbnail', Location.clean(name), revision])
return Location([unicode(XASSET_LOCATION_TAG), org, course, u'asset' if not is_thumbnail else u'thumbnail', Location.clean(name), revision])
def get_id(self): def get_id(self):
return StaticContent.get_id_from_location(self.location) return StaticContent.get_id_from_location(self.location)
......
...@@ -120,7 +120,7 @@ default_options = { ...@@ -120,7 +120,7 @@ default_options = {
} }
task :predjango do task :predjango do
sh("find . -type f -name *.pyc -delete") sh("find . -type f -name '*.pyc' -delete")
sh('pip install -q --upgrade --no-deps -r local-requirements.txt') sh('pip install -q --upgrade --no-deps -r local-requirements.txt')
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment