Skip to content

Commit

Permalink
test: verify that components are from the same learning package
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Feb 18, 2025
1 parent e7e6472 commit 6cc36c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openedx_learning/apps/authoring/containers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions tests/openedx_learning/apps/authoring/units/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6cc36c0

Please sign in to comment.