diff --git a/common/lib/xmodule/xmodule/contentstore/content.py b/common/lib/xmodule/xmodule/contentstore/content.py index f61a6f88ac..37608b4182 100644 --- a/common/lib/xmodule/xmodule/contentstore/content.py +++ b/common/lib/xmodule/xmodule/contentstore/content.py @@ -63,7 +63,7 @@ class StaticContent(object): return self.location def get_url_path(self): - return self._key_to_string(self.location) + return self.location.to_deprecated_string() @property def data(self): @@ -104,7 +104,7 @@ class StaticContent(object): return None 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 def get_location_from_path(path): @@ -124,7 +124,7 @@ class StaticContent(object): # Generate url of urlparse.path component scheme, netloc, orig_path, params, query, fragment = urlparse(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 orig_query = parse_qsl(query) @@ -135,7 +135,7 @@ class StaticContent(object): course_id, 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)) else: new_query_list.append((query_name, query_value)) @@ -146,15 +146,6 @@ class StaticContent(object): def stream_data(self): 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): def __init__(self, loc, name, content_type, stream, last_modified_at=None, thumbnail_location=None, import_path=None, diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index ca9647b7a5..a2ab88f8d1 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -88,8 +88,8 @@ class TestMongoModuleStore(unittest.TestCase): cls.connection.drop_database(DB) cls.connection.close() - @staticmethod - def initdb(): + @classmethod + def initdb(cls): # connect to the db doc_store_config = { 'host': HOST, @@ -112,7 +112,7 @@ class TestMongoModuleStore(unittest.TestCase): draft_store, 999, DATA_DIR, - TestMongoModuleStore.courses, + cls.courses, static_content_store=content_store ) @@ -134,13 +134,6 @@ class TestMongoModuleStore(unittest.TestCase): # Destroy the test 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): '''Make sure the db loads''' ids = list(self.connection[DB][COLLECTION].find({}, {'_id': True})) @@ -288,57 +281,57 @@ class TestMongoModuleStore(unittest.TestCase): Test getting, setting, and defaulting the locked attr and arbitrary attrs. """ 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) # a bit overkill, could just do for content[0] for content in course_content: assert not content.get('locked', False) 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) - attrs = TestMongoModuleStore.content_store.get_attrs(asset_key) + assert not self.content_store.get_attr(asset_key, 'locked', False) + attrs = self.content_store.get_attrs(asset_key) assert_in('uploadDate', attrs) assert not attrs.get('locked', False) - TestMongoModuleStore.content_store.set_attr(asset_key, 'locked', True) - assert TestMongoModuleStore.content_store.get_attr(asset_key, 'locked', False) - attrs = TestMongoModuleStore.content_store.get_attrs(asset_key) + self.content_store.set_attr(asset_key, 'locked', True) + assert self.content_store.get_attr(asset_key, 'locked', False) + attrs = self.content_store.get_attrs(asset_key) assert_in('locked', attrs) assert attrs['locked'] is True - TestMongoModuleStore.content_store.set_attrs(asset_key, {'miscel': 99}) - assert_equals(TestMongoModuleStore.content_store.get_attr(asset_key, 'miscel'), 99) + self.content_store.set_attrs(asset_key, {'miscel': 99}) + assert_equals(self.content_store.get_attr(asset_key, 'miscel'), 99) asset_key = AssetLocation._from_deprecated_son( course_content[0].get('content_son', course_content[0]['_id']), location.run ) assert_raises( - AttributeError, TestMongoModuleStore.content_store.set_attr, asset_key, + AttributeError, self.content_store.set_attr, asset_key, 'md5', 'ff1532598830e3feac91c2449eaa60d6' ) assert_raises( - AttributeError, TestMongoModuleStore.content_store.set_attrs, asset_key, + AttributeError, self.content_store.set_attrs, asset_key, {'foo': 9, 'md5': 'ff1532598830e3feac91c2449eaa60d6'} ) assert_raises( - NotFoundError, TestMongoModuleStore.content_store.get_attr, + NotFoundError, self.content_store.get_attr, Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'), 'displayname' ) assert_raises( - NotFoundError, TestMongoModuleStore.content_store.set_attr, + NotFoundError, self.content_store.set_attr, Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'), 'displayname', 'hello' ) assert_raises( - NotFoundError, TestMongoModuleStore.content_store.get_attrs, + NotFoundError, self.content_store.get_attrs, Location('bogus', 'bogus', 'bogus', 'asset', 'bogus') ) assert_raises( - NotFoundError, TestMongoModuleStore.content_store.set_attrs, + NotFoundError, self.content_store.set_attrs, Location('bogus', 'bogus', 'bogus', 'asset', 'bogus'), {'displayname': 'hello'} ) assert_raises( - NotFoundError, TestMongoModuleStore.content_store.set_attrs, + NotFoundError, self.content_store.set_attrs, Location('bogus', 'bogus', 'bogus', 'asset', None), {'displayname': 'hello'} ) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 48964e1666..c14999b297 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -97,7 +97,7 @@ def import_static_content( try: static_content_store.save(content) 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 ))