Skip to content

Commit

Permalink
refactor: Rename LibCollection* to LibraryCollection*. Change Library…
Browse files Browse the repository at this point in the history
…CollectionKey to OpaqueKey
  • Loading branch information
ChrisChV committed Aug 30, 2024
1 parent 81de217 commit e3ff649
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
7 changes: 4 additions & 3 deletions opaque_keys/edx/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions opaque_keys/edx/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions opaque_keys/edx/tests/test_collection_locators.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand All @@ -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',
],
}
)

0 comments on commit e3ff649

Please sign in to comment.