diff --git a/openedx_learning/__init__.py b/openedx_learning/__init__.py index 354ad372..cf87e3bf 100644 --- a/openedx_learning/__init__.py +++ b/openedx_learning/__init__.py @@ -1,4 +1,4 @@ """ Open edX Learning ("Learning Core"). """ -__version__ = "0.11.1" +__version__ = "0.11.2" diff --git a/openedx_learning/apps/authoring/collections/api.py b/openedx_learning/apps/authoring/collections/api.py index 29764735..137a0d26 100644 --- a/openedx_learning/apps/authoring/collections/api.py +++ b/openedx_learning/apps/authoring/collections/api.py @@ -18,6 +18,7 @@ "add_to_collections", "create_collection", "get_collection", + "get_collections", "get_learning_package_collections", "get_object_collections", "remove_from_collections", @@ -157,4 +158,15 @@ def get_learning_package_collections(learning_package_id: int) -> QuerySet[Colle """ return Collection.objects \ .filter(learning_package_id=learning_package_id, enabled=True) \ - .select_related("learning_package") + .select_related("learning_package") \ + .order_by('pk') + + +def get_collections(enabled: bool | None = None) -> QuerySet[Collection]: + """ + Get all collections, optionally caller can filter by enabled flag + """ + qs = Collection.objects.all() + if enabled is not None: + qs = qs.filter(enabled=enabled) + return qs.select_related("learning_package").order_by('pk') diff --git a/requirements/base.txt b/requirements/base.txt index 82b1638f..3cd100e1 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -68,7 +68,7 @@ edx-drf-extensions==10.3.0 # via -r requirements/base.in edx-opaque-keys==2.10.0 # via edx-drf-extensions -idna==3.7 +idna==3.8 # via requests kombu==5.4.0 # via celery @@ -102,7 +102,7 @@ six==1.16.0 # via python-dateutil sqlparse==0.5.1 # via django -stevedore==5.2.0 +stevedore==5.3.0 # via # edx-django-utils # edx-opaque-keys diff --git a/requirements/dev.txt b/requirements/dev.txt index b6460f46..e0a61adb 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -167,7 +167,7 @@ edx-drf-extensions==10.3.0 # via -r requirements/quality.txt edx-i18n-tools==1.6.2 # via -r requirements/dev.in -edx-lint==5.3.7 +edx-lint==5.4.0 # via -r requirements/quality.txt edx-opaque-keys==2.10.0 # via @@ -185,7 +185,7 @@ grimp==3.4.1 # -r requirements/ci.txt # -r requirements/quality.txt # import-linter -idna==3.7 +idna==3.8 # via # -r requirements/quality.txt # requests @@ -193,7 +193,7 @@ import-linter==2.0 # via # -r requirements/ci.txt # -r requirements/quality.txt -importlib-metadata==8.2.0 +importlib-metadata==8.4.0 # via # -r requirements/quality.txt # keyring @@ -210,7 +210,7 @@ jaraco-classes==3.4.0 # via # -r requirements/quality.txt # keyring -jaraco-context==5.3.0 +jaraco-context==6.0.1 # via # -r requirements/quality.txt # keyring @@ -261,7 +261,7 @@ more-itertools==10.4.0 # -r requirements/quality.txt # jaraco-classes # jaraco-functools -mypy==1.11.1 +mypy==1.11.2 # via -r requirements/quality.txt mypy-extensions==1.0.0 # via @@ -448,7 +448,7 @@ sqlparse==0.5.1 # -r requirements/quality.txt # django # django-debug-toolbar -stevedore==5.2.0 +stevedore==5.3.0 # via # -r requirements/quality.txt # code-annotations diff --git a/requirements/doc.txt b/requirements/doc.txt index 6512a148..a714318b 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -151,7 +151,7 @@ grimp==3.4.1 # via # -r requirements/test.txt # import-linter -idna==3.7 +idna==3.8 # via # -r requirements/test.txt # requests @@ -178,7 +178,7 @@ markupsafe==2.1.5 # jinja2 mock==5.1.0 # via -r requirements/test.txt -mypy==1.11.1 +mypy==1.11.2 # via -r requirements/test.txt mypy-extensions==1.0.0 # via @@ -315,7 +315,7 @@ sqlparse==0.5.1 # -r requirements/test.txt # django # django-debug-toolbar -stevedore==5.2.0 +stevedore==5.3.0 # via # -r requirements/test.txt # code-annotations diff --git a/requirements/pip.txt b/requirements/pip.txt index 5f8b9c04..f0fca188 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -10,5 +10,5 @@ wheel==0.44.0 # The following packages are considered to be unsafe in a requirements file: pip==24.2 # via -r requirements/pip.in -setuptools==72.2.0 +setuptools==73.0.1 # via -r requirements/pip.in diff --git a/requirements/quality.txt b/requirements/quality.txt index c89c9d35..f16f0d38 100644 --- a/requirements/quality.txt +++ b/requirements/quality.txt @@ -138,7 +138,7 @@ edx-django-utils==5.15.0 # edx-drf-extensions edx-drf-extensions==10.3.0 # via -r requirements/test.txt -edx-lint==5.3.7 +edx-lint==5.4.0 # via -r requirements/quality.in edx-opaque-keys==2.10.0 # via @@ -150,13 +150,13 @@ grimp==3.4.1 # via # -r requirements/test.txt # import-linter -idna==3.7 +idna==3.8 # via # -r requirements/test.txt # requests import-linter==2.0 # via -r requirements/test.txt -importlib-metadata==8.2.0 +importlib-metadata==8.4.0 # via # keyring # twine @@ -170,7 +170,7 @@ isort==5.13.2 # pylint jaraco-classes==3.4.0 # via keyring -jaraco-context==5.3.0 +jaraco-context==6.0.1 # via keyring jaraco-functools==4.0.2 # via keyring @@ -204,7 +204,7 @@ more-itertools==10.4.0 # via # jaraco-classes # jaraco-functools -mypy==1.11.1 +mypy==1.11.2 # via -r requirements/test.txt mypy-extensions==1.0.0 # via @@ -338,7 +338,7 @@ sqlparse==0.5.1 # -r requirements/test.txt # django # django-debug-toolbar -stevedore==5.2.0 +stevedore==5.3.0 # via # -r requirements/test.txt # code-annotations diff --git a/requirements/test.txt b/requirements/test.txt index 0420e6d8..aa8e87b9 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -126,7 +126,7 @@ freezegun==1.5.1 # via -r requirements/test.in grimp==3.4.1 # via import-linter -idna==3.7 +idna==3.8 # via # -r requirements/base.txt # requests @@ -144,7 +144,7 @@ markupsafe==2.1.5 # via jinja2 mock==5.1.0 # via -r requirements/test.in -mypy==1.11.1 +mypy==1.11.2 # via -r requirements/test.in mypy-extensions==1.0.0 # via mypy @@ -225,7 +225,7 @@ sqlparse==0.5.1 # -r requirements/base.txt # django # django-debug-toolbar -stevedore==5.2.0 +stevedore==5.3.0 # via # -r requirements/base.txt # code-annotations diff --git a/tests/openedx_learning/apps/authoring/collections/test_api.py b/tests/openedx_learning/apps/authoring/collections/test_api.py index 526c2cba..f5564748 100644 --- a/tests/openedx_learning/apps/authoring/collections/test_api.py +++ b/tests/openedx_learning/apps/authoring/collections/test_api.py @@ -25,6 +25,7 @@ class CollectionTestCase(TestCase): Base-class for setting up commonly used test data. """ learning_package: LearningPackage + learning_package_2: LearningPackage now: datetime @classmethod @@ -33,6 +34,10 @@ def setUpTestData(cls) -> None: key="ComponentTestCase-test-key", title="Components Test Case Learning Package", ) + cls.learning_package_2 = publishing_api.create_learning_package( + key="ComponentTestCase-test-key-2", + title="Components Test Case another Learning Package", + ) cls.now = datetime(2024, 8, 5, tzinfo=timezone.utc) @@ -42,6 +47,7 @@ class GetCollectionTestCase(CollectionTestCase): """ collection1: Collection collection2: Collection + collection3: Collection disabled_collection: Collection @classmethod @@ -62,6 +68,12 @@ def setUpTestData(cls) -> None: title="Collection 2", description="Description of Collection 2", ) + cls.collection3 = collection_api.create_collection( + cls.learning_package_2.id, + created_by=None, + title="Collection 3", + description="Description of Collection 3", + ) cls.disabled_collection = collection_api.create_collection( cls.learning_package.id, created_by=None, @@ -102,6 +114,36 @@ def test_get_invalid_learning_package_collections(self): collections = collection_api.get_learning_package_collections(12345) assert not list(collections) + def test_get_all_collections(self): + """ + Test getting all collections. + """ + collections = collection_api.get_collections() + self.assertQuerySetEqual(collections, [ + self.collection1, + self.collection2, + self.collection3, + self.disabled_collection, + ], ordered=True) + + def test_get_all_enabled_collections(self): + """ + Test getting all ENABLED collections. + """ + collections = collection_api.get_collections(enabled=True) + self.assertQuerySetEqual(collections, [ + self.collection1, + self.collection2, + self.collection3, + ], ordered=True) + + def test_get_all_disabled_collections(self): + """ + Test getting all DISABLED collections. + """ + collections = collection_api.get_collections(enabled=False) + assert list(collections) == [self.disabled_collection] + class CollectionCreateTestCase(CollectionTestCase): """