Commit 173be7d2 by Don Mitchell

Allow to_deprecated_string to do its magic

parent cc6dfbbc
...@@ -63,7 +63,7 @@ class StaticContent(object): ...@@ -63,7 +63,7 @@ class StaticContent(object):
return self.location return self.location
def get_url_path(self): def get_url_path(self):
return self._key_to_string(self.location) return self.location.to_deprecated_string()
@property @property
def data(self): def data(self):
...@@ -104,7 +104,7 @@ class StaticContent(object): ...@@ -104,7 +104,7 @@ class StaticContent(object):
return None return None
assert(isinstance(course_key, CourseKey)) assert(isinstance(course_key, CourseKey))
return StaticContent._key_to_string(course_key.make_asset_key('asset', '')) return course_key.make_asset_key('asset', '').to_deprecated_string()
@staticmethod @staticmethod
def get_location_from_path(path): def get_location_from_path(path):
...@@ -124,7 +124,7 @@ class StaticContent(object): ...@@ -124,7 +124,7 @@ class StaticContent(object):
# Generate url of urlparse.path component # Generate url of urlparse.path component
scheme, netloc, orig_path, params, query, fragment = urlparse(path) scheme, netloc, orig_path, params, query, fragment = urlparse(path)
loc = StaticContent.compute_location(course_id, orig_path) loc = StaticContent.compute_location(course_id, orig_path)
loc_url = StaticContent._key_to_string(loc) loc_url = loc.to_deprecated_string()
# parse the query params for "^/static/" and replace with the location url # parse the query params for "^/static/" and replace with the location url
orig_query = parse_qsl(query) orig_query = parse_qsl(query)
...@@ -135,7 +135,7 @@ class StaticContent(object): ...@@ -135,7 +135,7 @@ class StaticContent(object):
course_id, course_id,
query_value[len('/static/'):], query_value[len('/static/'):],
) )
new_query_url = StaticContent._key_to_string(new_query) new_query_url = new_query.to_deprecated_string()
new_query_list.append((query_name, new_query_url)) new_query_list.append((query_name, new_query_url))
else: else:
new_query_list.append((query_name, query_value)) new_query_list.append((query_name, query_value))
...@@ -146,15 +146,6 @@ class StaticContent(object): ...@@ -146,15 +146,6 @@ class StaticContent(object):
def stream_data(self): def stream_data(self):
yield self._data yield self._data
@staticmethod
def _key_to_string(key):
"""Converts the given key to a string, honoring the deprecated flag."""
# TODO OpaqueKey - remove deprecated check once opaque keys lands
if getattr(key, 'deprecated', False):
return key.to_deprecated_string()
else:
return unicode(key)
class StaticContentStream(StaticContent): class StaticContentStream(StaticContent):
def __init__(self, loc, name, content_type, stream, last_modified_at=None, thumbnail_location=None, import_path=None, def __init__(self, loc, name, content_type, stream, last_modified_at=None, thumbnail_location=None, import_path=None,
......
...@@ -88,8 +88,8 @@ class TestMongoModuleStore(unittest.TestCase): ...@@ -88,8 +88,8 @@ class TestMongoModuleStore(unittest.TestCase):
cls.connection.drop_database(DB) cls.connection.drop_database(DB)
cls.connection.close() cls.connection.close()
@staticmethod @classmethod
def initdb(): def initdb(cls):
# connect to the db # connect to the db
doc_store_config = { doc_store_config = {
'host': HOST, 'host': HOST,
...@@ -112,7 +112,7 @@ class TestMongoModuleStore(unittest.TestCase): ...@@ -112,7 +112,7 @@ class TestMongoModuleStore(unittest.TestCase):
draft_store, draft_store,
999, 999,
DATA_DIR, DATA_DIR,
TestMongoModuleStore.courses, cls.courses,
static_content_store=content_store static_content_store=content_store
) )
...@@ -134,13 +134,6 @@ class TestMongoModuleStore(unittest.TestCase): ...@@ -134,13 +134,6 @@ class TestMongoModuleStore(unittest.TestCase):
# Destroy the test db. # Destroy the test db.
connection.drop_database(DB) connection.drop_database(DB)
def setUp(self):
# make a copy for convenience
self.connection = TestMongoModuleStore.connection
def tearDown(self):
pass
def test_init(self): def test_init(self):
'''Make sure the db loads''' '''Make sure the db loads'''
ids = list(self.connection[DB][COLLECTION].find({}, {'_id': True})) ids = list(self.connection[DB][COLLECTION].find({}, {'_id': True}))
...@@ -288,57 +281,57 @@ class TestMongoModuleStore(unittest.TestCase): ...@@ -288,57 +281,57 @@ class TestMongoModuleStore(unittest.TestCase):
Test getting, setting, and defaulting the locked attr and arbitrary attrs. Test getting, setting, and defaulting the locked attr and arbitrary attrs.
""" """
location = Location('edX', 'toy', '2012_Fall', 'course', '2012_Fall') location = Location('edX', 'toy', '2012_Fall', 'course', '2012_Fall')
course_content, __ = TestMongoModuleStore.content_store.get_all_content_for_course(location.course_key) course_content, __ = self.content_store.get_all_content_for_course(location.course_key)
assert_true(len(course_content) > 0) assert_true(len(course_content) > 0)
# a bit overkill, could just do for content[0] # a bit overkill, could just do for content[0]
for content in course_content: for content in course_content:
assert not content.get('locked', False) assert not content.get('locked', False)
asset_key = AssetLocation._from_deprecated_son(content.get('content_son', content['_id']), location.run) asset_key = AssetLocation._from_deprecated_son(content.get('content_son', content['_id']), location.run)
assert not TestMongoModuleStore.content_store.get_attr(asset_key, 'locked', False) assert not self.content_store.get_attr(asset_key, 'locked', False)
attrs = TestMongoModuleStore.content_store.get_attrs(asset_key) attrs = self.content_store.get_attrs(asset_key)
assert_in('uploadDate', attrs) assert_in('uploadDate', attrs)
assert not attrs.get('locked', False) assert not attrs.get('locked', False)
TestMongoModuleStore.content_store.set_attr(asset_key, 'locked', True) self.content_store.set_attr(asset_key, 'locked', True)
assert TestMongoModuleStore.content_store.get_attr(asset_key, 'locked', False) assert self.content_store.get_attr(asset_key, 'locked', False)
attrs = TestMongoModuleStore.content_store.get_attrs(asset_key) attrs = self.content_store.get_attrs(asset_key)
assert_in('locked', attrs) assert_in('locked', attrs)
assert attrs['locked'] is True assert attrs['locked'] is True
TestMongoModuleStore.content_store.set_attrs(asset_key, {'miscel': 99}) self.content_store.set_attrs(asset_key, {'miscel': 99})
assert_equals(TestMongoModuleStore.content_store.get_attr(asset_key, 'miscel'), 99) assert_equals(self.content_store.get_attr(asset_key, 'miscel'), 99)
asset_key = AssetLocation._from_deprecated_son( asset_key = AssetLocation._from_deprecated_son(
course_content[0].get('content_son', course_content[0]['_id']), course_content[0].get('content_son', course_content[0]['_id']),
location.run location.run
) )
assert_raises( assert_raises(
AttributeError, TestMongoModuleStore.content_store.set_attr, asset_key, AttributeError, self.content_store.set_attr, asset_key,
'md5', 'ff1532598830e3feac91c2449eaa60d6' 'md5', 'ff1532598830e3feac91c2449eaa60d6'
) )
assert_raises( assert_raises(
AttributeError, TestMongoModuleStore.content_store.set_attrs, asset_key, AttributeError, self.content_store.set_attrs, asset_key,
{'foo': 9, 'md5': 'ff1532598830e3feac91c2449eaa60d6'} {'foo': 9, 'md5': 'ff1532598830e3feac91c2449eaa60d6'}
) )
assert_raises( assert_raises(
NotFoundError, TestMongoModuleStore.content_store.get_attr, NotFoundError, self.content_store.get_attr,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'), Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
'displayname' 'displayname'
) )
assert_raises( assert_raises(
NotFoundError, TestMongoModuleStore.content_store.set_attr, NotFoundError, self.content_store.set_attr,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'), Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
'displayname', 'hello' 'displayname', 'hello'
) )
assert_raises( assert_raises(
NotFoundError, TestMongoModuleStore.content_store.get_attrs, NotFoundError, self.content_store.get_attrs,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus') Location('bogus', 'bogus', 'bogus', 'asset', 'bogus')
) )
assert_raises( assert_raises(
NotFoundError, TestMongoModuleStore.content_store.set_attrs, NotFoundError, self.content_store.set_attrs,
Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'), Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'),
{'displayname': 'hello'} {'displayname': 'hello'}
) )
assert_raises( assert_raises(
NotFoundError, TestMongoModuleStore.content_store.set_attrs, NotFoundError, self.content_store.set_attrs,
Location('bogus', 'bogus', 'bogus', 'asset', None), Location('bogus', 'bogus', 'bogus', 'asset', None),
{'displayname': 'hello'} {'displayname': 'hello'}
) )
......
...@@ -97,7 +97,7 @@ def import_static_content( ...@@ -97,7 +97,7 @@ def import_static_content(
try: try:
static_content_store.save(content) static_content_store.save(content)
except Exception as err: except Exception as err:
log.exception('Error importing {0}, error={1}'.format( log.exception(u'Error importing {0}, error={1}'.format(
fullname_with_subpath, err fullname_with_subpath, err
)) ))
......
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