-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Create LibraryContainerLocator for Library Containers [FC-0083]
#369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kdmccormick
merged 6 commits into
openedx:master
from
open-craft:chris/FAL-4108-create-container-keys
Mar 21, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4fda18c
refactor: Convert LibraryCollectionKey to LibraryElementKey
ChrisChV 2f0dae3
feat: Add LibraryContainerLocator
ChrisChV e1d5a18
refactor: Convert LibraryElementKey as abstract class
ChrisChV 2419bd7
chore: Bump version of the package
ChrisChV fc0cff1
refactor: Rename LibraryElementKey to LibraryItemKey
ChrisChV ec22e77
refactor: Rename library_element_key to library_item_key
ChrisChV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """ | ||
| Tests of LibraryContainerLocator | ||
| """ | ||
| import ddt | ||
| from opaque_keys import InvalidKeyError | ||
| from opaque_keys.edx.tests import LocatorBaseTest | ||
| from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2 | ||
|
|
||
|
|
||
| @ddt.ddt | ||
| class TestLibraryContainerLocator(LocatorBaseTest): | ||
| """ | ||
| Tests of :class:`.LibraryContainerLocator` | ||
| """ | ||
| @ddt.data( | ||
| "org/lib/id/foo", | ||
| "org/lib/id", | ||
| "org+lib+id", | ||
| "org+lib+", | ||
| "org+lib++id@library", | ||
| "org+ne@t", | ||
| "per%ent+sign", | ||
| ) | ||
| def test_coll_key_from_invalid_string(self, coll_id_str): | ||
| with self.assertRaises(InvalidKeyError): | ||
| LibraryContainerLocator.from_string(coll_id_str) | ||
|
|
||
| def test_key_constructor(self): | ||
| org = 'TestX' | ||
| lib = 'LibraryX' | ||
| container_type = 'unit' | ||
| container_id = 'test-container' | ||
| library_key = LibraryLocatorV2(org=org, slug=lib) | ||
| container_key = LibraryContainerLocator( | ||
| library_key=library_key, | ||
| container_type=container_type, | ||
| container_id=container_id, | ||
| ) | ||
| library_key = container_key.library_key | ||
| self.assertEqual(str(container_key), "lct:TestX:LibraryX:unit:test-container") | ||
| self.assertEqual(container_key.org, org) | ||
| self.assertEqual(container_key.container_type, container_type) | ||
| self.assertEqual(container_key.container_id, container_id) | ||
| self.assertEqual(library_key.org, org) | ||
| self.assertEqual(library_key.slug, lib) | ||
|
|
||
| def test_key_constructor_bad_ids(self): | ||
| library_key = LibraryLocatorV2(org="TestX", slug="lib1") | ||
|
|
||
| with self.assertRaises(TypeError): | ||
| LibraryContainerLocator(library_key=None, container_type='unit', container_id='usage') | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| LibraryContainerLocator(library_key=library_key, container_type='unit', container_id='usage-!@#{$%^&*}') | ||
|
|
||
| def test_key_constructor_bad_type(self): | ||
| library_key = LibraryLocatorV2(org="TestX", slug="lib1") | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| LibraryContainerLocator(library_key=library_key, container_type='unit-!@#{$%^&*}', container_id='usage') | ||
|
|
||
| def test_key_from_string(self): | ||
| org = 'TestX' | ||
| lib = 'LibraryX' | ||
| container_type = 'unit' | ||
| container_id = 'test-container' | ||
| str_key = f"lct:{org}:{lib}:{container_type}:{container_id}" | ||
| container_key = LibraryContainerLocator.from_string(str_key) | ||
| library_key = container_key.library_key | ||
| self.assertEqual(str(container_key), str_key) | ||
| self.assertEqual(container_key.org, org) | ||
| self.assertEqual(container_key.container_type, container_type) | ||
| self.assertEqual(container_key.container_id, container_id) | ||
| self.assertEqual(library_key.org, org) | ||
| self.assertEqual(library_key.slug, lib) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Do we need this to be short? If size doesn't matter, maybe change this to something readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@navinkarkera Yes, other larger possibilities were ruled out; you can see that conversation here: openedx/openedx-learning#282 (comment)