diff --git a/opaque_keys/edx/keys.py b/opaque_keys/edx/keys.py index 4ae1c03..ec87cb2 100644 --- a/opaque_keys/edx/keys.py +++ b/opaque_keys/edx/keys.py @@ -89,10 +89,11 @@ def make_asset_key(self, asset_type: str, path: str) -> AssetKey: # pragma: no raise NotImplementedError() -class LibCollectionKey(LearningContextKey): +class LibraryCollectionKey(OpaqueKey): """ An :class:`opaque_keys.OpaqueKey` identifying a particular Library Collection object. """ + KEY_TYPE = 'collection_key' __slots__ = () @property @@ -112,9 +113,9 @@ def lib(self) -> str | None: # pragma: no cover raise NotImplementedError() @property - def context_key(self) -> LearningContextKey: # pragma: no cover + def library_key(self) -> LearningContextKey: # pragma: no cover """ - Get the learning context key (LearningContextKey) for this XBlock usage. + Get the key of the library that this collection belongs to. """ raise NotImplementedError() diff --git a/opaque_keys/edx/locator.py b/opaque_keys/edx/locator.py index 6d1be57..968d64c 100644 --- a/opaque_keys/edx/locator.py +++ b/opaque_keys/edx/locator.py @@ -16,7 +16,7 @@ from opaque_keys import OpaqueKey, InvalidKeyError from opaque_keys.edx.keys import AssetKey, CourseKey, DefinitionKey, \ - LearningContextKey, UsageKey, UsageKeyV2, LibCollectionKey + LearningContextKey, UsageKey, UsageKeyV2, LibraryCollectionKey log = logging.getLogger(__name__) @@ -1623,7 +1623,7 @@ def html_id(self) -> str: return str(self) -class LibCollectionLocator(CheckFieldMixin, LibCollectionKey): +class LibraryCollectionLocator(CheckFieldMixin, LibraryCollectionKey): """ When serialized, these keys look like: lib-collection:org:lib:collection-id @@ -1657,7 +1657,7 @@ def __init__(self, lib_key: LibraryLocatorV2, usage_id: str): ) @property - def context_key(self) -> LibraryLocatorV2: + def library_key(self) -> LibraryLocatorV2: return self.lib_key def _to_string(self) -> str: diff --git a/opaque_keys/edx/tests/test_collection_locators.py b/opaque_keys/edx/tests/test_collection_locators.py index 31b518a..5946886 100644 --- a/opaque_keys/edx/tests/test_collection_locators.py +++ b/opaque_keys/edx/tests/test_collection_locators.py @@ -1,16 +1,16 @@ """ -Tests of LibCollectionLocator +Tests of LibraryCollectionLocator """ import ddt from opaque_keys import InvalidKeyError from opaque_keys.edx.tests import LocatorBaseTest -from opaque_keys.edx.locator import LibCollectionLocator, LibraryLocatorV2 +from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryLocatorV2 @ddt.ddt -class TestLibCollectionLocator(LocatorBaseTest): +class TestLibraryCollectionLocator(LocatorBaseTest): """ - Tests of :class:`.LibCollectionLocator` + Tests of :class:`.LibraryCollectionLocator` """ @ddt.data( "org/lib/id/foo", @@ -23,15 +23,15 @@ class TestLibCollectionLocator(LocatorBaseTest): ) def test_coll_key_from_invalid_string(self, coll_id_str): with self.assertRaises(InvalidKeyError): - LibCollectionLocator.from_string(coll_id_str) + LibraryCollectionLocator.from_string(coll_id_str) def test_coll_key_constructor(self): org = 'TestX' lib = 'LibraryX' code = 'test-problem-bank' lib_key = LibraryLocatorV2(org=org, slug=lib) - coll_key = LibCollectionLocator(lib_key=lib_key, usage_id=code) - lib_key = coll_key.context_key + coll_key = LibraryCollectionLocator(lib_key=lib_key, usage_id=code) + lib_key = coll_key.library_key self.assertEqual(str(coll_key), "lib-collection:TestX:LibraryX:test-problem-bank") self.assertEqual(coll_key.org, org) self.assertEqual(coll_key.lib, lib) @@ -43,17 +43,17 @@ def test_coll_key_constructor_bad_ids(self): lib_key = LibraryLocatorV2(org="TestX", slug="lib1") with self.assertRaises(ValueError): - LibCollectionLocator(lib_key=lib_key, usage_id='usage-!@#{$%^&*}') + LibraryCollectionLocator(lib_key=lib_key, usage_id='usage-!@#{$%^&*}') with self.assertRaises(TypeError): - LibCollectionLocator(lib_key=None, usage_id='usage') + LibraryCollectionLocator(lib_key=None, usage_id='usage') def test_coll_key_from_string(self): org = 'TestX' lib = 'LibraryX' code = 'test-problem-bank' str_key = f"lib-collection:{org}:{lib}:{code}" - coll_key = LibCollectionLocator.from_string(str_key) - lib_key = coll_key.context_key + coll_key = LibraryCollectionLocator.from_string(str_key) + lib_key = coll_key.library_key self.assertEqual(str(coll_key), str_key) self.assertEqual(coll_key.org, org) self.assertEqual(coll_key.lib, lib) @@ -63,4 +63,4 @@ def test_coll_key_from_string(self): def test_coll_key_invalid_from_string(self): with self.assertRaises(InvalidKeyError): - LibCollectionLocator.from_string("this-is-a-great-test") + LibraryCollectionLocator.from_string("this-is-a-great-test") diff --git a/setup.py b/setup.py index 7b4ad8a..b1679bc 100644 --- a/setup.py +++ b/setup.py @@ -131,7 +131,6 @@ def get_version(*file_paths): 'course-v1 = opaque_keys.edx.locator:CourseLocator', 'library-v1 = opaque_keys.edx.locator:LibraryLocator', 'lib = opaque_keys.edx.locator:LibraryLocatorV2', - 'lib-collection = opaque_keys.edx.locator:LibCollectionLocator', # don't use slashes in any new code 'slashes = opaque_keys.edx.locator:CourseLocator', ], @@ -154,6 +153,9 @@ def get_version(*file_paths): ], 'block_type': [ 'block-type-v1 = opaque_keys.edx.block_types:BlockTypeKeyV1', - ] + ], + 'collection_key': [ + 'lib-collection = opaque_keys.edx.locator:LibraryCollectionLocator', + ], } )