Skip to content

Commit 6cc36c0

Browse files
test: verify that components are from the same learning package
1 parent e7e6472 commit 6cc36c0

File tree

2 files changed

+27
-1
lines changed
  • openedx_learning/apps/authoring/containers
  • tests/openedx_learning/apps/authoring/units

2 files changed

+27
-1
lines changed

openedx_learning/apps/authoring/containers/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def create_next_container_version(
298298
299299
* Something was added to the Container.
300300
* We re-ordered the rows in the container.
301-
* Something was removed to the container.
301+
* Something was removed from the container.
302302
* The Container's metadata changed, e.g. the title.
303303
* We pin to different versions of the Container.
304304

tests/openedx_learning/apps/authoring/units/test_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
import pytest
55

6+
from django.core.exceptions import ValidationError
7+
68
from ..components.test_api import ComponentTestCase
79
from openedx_learning.api import authoring as authoring_api
810
from openedx_learning.api import authoring_models
@@ -105,6 +107,30 @@ def test_create_unit_with_invalid_children(self):
105107
# Check that a new version was not created:
106108
assert unit.versioning.draft == unit_version
107109

110+
def test_adding_external_components(self):
111+
"""
112+
Test that components from another learning package cannot be added to a
113+
unit.
114+
"""
115+
learning_package2 = authoring_api.create_learning_package(key="other-package", title="Other Package")
116+
unit, _unit_version = authoring_api.create_unit_and_version(
117+
learning_package_id=learning_package2.pk,
118+
key=f"unit:key",
119+
title="Unit",
120+
created=self.now,
121+
created_by=None,
122+
)
123+
assert self.component_1.learning_package != learning_package2
124+
# Try adding a a component from LP 1 (self.learning_package) to a unit from LP 2
125+
with pytest.raises(ValidationError, match="Container entities must be from the same learning package."):
126+
authoring_api.create_next_unit_version(
127+
unit=unit,
128+
title="Unit Containing an External Component",
129+
components=[self.component_1],
130+
created=self.now,
131+
created_by=None,
132+
)
133+
108134
def test_create_empty_unit_and_version(self):
109135
"""Test creating a unit with no components.
110136

0 commit comments

Comments
 (0)