diff --git a/openedx_learning/apps/authoring/containers/api.py b/openedx_learning/apps/authoring/containers/api.py index 065c8a01..f4ee44b8 100644 --- a/openedx_learning/apps/authoring/containers/api.py +++ b/openedx_learning/apps/authoring/containers/api.py @@ -298,7 +298,7 @@ def create_next_container_version( * Something was added to the Container. * We re-ordered the rows in the container. - * Something was removed to the container. + * Something was removed from the container. * The Container's metadata changed, e.g. the title. * We pin to different versions of the Container. diff --git a/tests/openedx_learning/apps/authoring/units/test_api.py b/tests/openedx_learning/apps/authoring/units/test_api.py index 26170aca..67097af0 100644 --- a/tests/openedx_learning/apps/authoring/units/test_api.py +++ b/tests/openedx_learning/apps/authoring/units/test_api.py @@ -3,6 +3,8 @@ """ import pytest +from django.core.exceptions import ValidationError + from ..components.test_api import ComponentTestCase from openedx_learning.api import authoring as authoring_api from openedx_learning.api import authoring_models @@ -105,6 +107,30 @@ def test_create_unit_with_invalid_children(self): # Check that a new version was not created: assert unit.versioning.draft == unit_version + def test_adding_external_components(self): + """ + Test that components from another learning package cannot be added to a + unit. + """ + learning_package2 = authoring_api.create_learning_package(key="other-package", title="Other Package") + unit, _unit_version = authoring_api.create_unit_and_version( + learning_package_id=learning_package2.pk, + key=f"unit:key", + title="Unit", + created=self.now, + created_by=None, + ) + assert self.component_1.learning_package != learning_package2 + # Try adding a a component from LP 1 (self.learning_package) to a unit from LP 2 + with pytest.raises(ValidationError, match="Container entities must be from the same learning package."): + authoring_api.create_next_unit_version( + unit=unit, + title="Unit Containing an External Component", + components=[self.component_1], + created=self.now, + created_by=None, + ) + def test_create_empty_unit_and_version(self): """Test creating a unit with no components.