Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openedx_learning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Open edX Learning ("Learning Core").
"""

__version__ = "0.25.0"
__version__ = "0.26.0"
8 changes: 7 additions & 1 deletion openedx_learning/apps/authoring/publishing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ def get_container_by_key(learning_package_id: int, /, key: str) -> Container:
def get_containers(
learning_package_id: int,
container_cls: type[ContainerModel] = Container, # type: ignore[assignment]
include_deleted: bool | None = False,
) -> QuerySet[ContainerModel]:
"""
[ 🛑 UNSTABLE ]
Expand All @@ -1211,12 +1212,17 @@ def get_containers(
Args:
learning_package_id: The primary key of the learning package
container_cls: The subclass of Container to use, if applicable
include_deleted: If True, include deleted containers in the result.
Comment thread
rpenido marked this conversation as resolved.
Outdated

Returns:
A queryset containing the container associated with the given learning package.
"""
assert issubclass(container_cls, Container)
return container_cls.objects.filter(publishable_entity__learning_package=learning_package_id)
container_qset = container_cls.objects.filter(publishable_entity__learning_package=learning_package_id)
if not include_deleted:
container_qset = container_qset.filter(publishable_entity__draft__version__isnull=False)

return container_qset.order_by('pk')


def get_collection_containers(
Expand Down
28 changes: 28 additions & 0 deletions tests/openedx_learning/apps/authoring/sections/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ def test_get_containers(self):
with self.assertNumQueries(0):
assert result[0].versioning.has_unpublished_changes

def test_get_containers_deleted(self):
"""
Test that get_containers() does not return soft-deleted sections.
"""
section = self.create_section_with_subsections([])
authoring_api.soft_delete_draft(section.pk)

with self.assertNumQueries(1):
result = list(authoring_api.get_containers(self.learning_package.id, include_deleted=True))

assert result == [
self.unit_1.container,
self.unit_2.container,
self.subsection_1.container,
self.subsection_2.container,
section.container,
]

with self.assertNumQueries(1):
result = list(authoring_api.get_containers(self.learning_package.id))

assert result == [
self.unit_1.container,
self.unit_2.container,
self.subsection_1.container,
self.subsection_2.container,
]

def test_get_container(self):
"""
Test get_container()
Expand Down
14 changes: 14 additions & 0 deletions tests/openedx_learning/apps/authoring/subsections/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ def test_get_containers(self):
with self.assertNumQueries(0):
assert result[0].versioning.has_unpublished_changes

def test_get_containers_deleted(self):
"""
Test that get_containers() does not return soft-deleted sections.
"""
subsection = self.create_subsection_with_units([])
authoring_api.soft_delete_draft(subsection.pk)
with self.assertNumQueries(1):
result = list(authoring_api.get_containers(self.learning_package.id, include_deleted=True))
assert result == [self.unit_1.container, self.unit_2.container, subsection.container]

with self.assertNumQueries(1):
result = list(authoring_api.get_containers(self.learning_package.id))
assert result == [self.unit_1.container, self.unit_2.container]

def test_get_container(self):
"""
Test get_container()
Expand Down
14 changes: 14 additions & 0 deletions tests/openedx_learning/apps/authoring/units/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ def test_get_containers(self):
with self.assertNumQueries(0):
assert result[0].versioning.has_unpublished_changes

def test_get_containers_deleted(self):
"""
Test that get_containers() does not return soft-deleted units.
"""
unit = self.create_unit_with_components([])
authoring_api.soft_delete_draft(unit.pk)
with self.assertNumQueries(1):
result = list(authoring_api.get_containers(self.learning_package.id, include_deleted=True))
assert result == [unit.container]

with self.assertNumQueries(1):
result = list(authoring_api.get_containers(self.learning_package.id))
assert not result

def test_get_container(self):
"""
Test get_container()
Expand Down