Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jill/collection-compo…
Browse files Browse the repository at this point in the history
…nents
  • Loading branch information
pomegranited committed Aug 27, 2024
2 parents 56c0a99 + baebbb3 commit bdf1548
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 23 deletions.
2 changes: 1 addition & 1 deletion openedx_learning/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Open edX Learning ("Learning Core").
"""
__version__ = "0.11.1"
__version__ = "0.11.2"
14 changes: 13 additions & 1 deletion openedx_learning/apps/authoring/collections/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"add_to_collections",
"create_collection",
"get_collection",
"get_collections",
"get_learning_package_collections",
"get_object_collections",
"remove_from_collections",
Expand Down Expand Up @@ -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')
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -185,15 +185,15 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions tests/openedx_learning/apps/authoring/collections/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


Expand All @@ -42,6 +47,7 @@ class GetCollectionTestCase(CollectionTestCase):
"""
collection1: Collection
collection2: Collection
collection3: Collection
disabled_collection: Collection

@classmethod
Expand All @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit bdf1548

Please sign in to comment.