|
7 | 7 |
|
8 | 8 | import openedx_content.api as content_api |
9 | 9 | from openedx_content.models_api import Component, ComponentVersion, Unit, UnitVersion |
10 | | -from tests.test_django_app.models import TestContainer |
| 10 | +from tests.test_django_app.models import TestContainer, TestEntity |
11 | 11 |
|
12 | 12 | from ..components.test_api import ComponentTestCase |
13 | 13 |
|
@@ -151,14 +151,33 @@ def test_create_unit_with_invalid_children(self): |
151 | 151 | unit = self.create_unit_with_components([]) |
152 | 152 | unit_version = unit.versioning.draft |
153 | 153 | unit2 = self.create_unit_with_components([], key="unit:key2", title="Unit 2") |
| 154 | + |
154 | 155 | # Try adding a Unit to a Unit |
155 | | - with pytest.raises(ValidationError, match='The entity "unit:key2" cannot be added to a "unit" container.'): |
| 156 | + with pytest.raises( |
| 157 | + ValidationError, match='The entity "unit:key2" cannot be added to a "unit" container.' |
| 158 | + ) as err: |
156 | 159 | content_api.create_next_unit_version( |
157 | 160 | unit, |
158 | 161 | components=[unit2], |
159 | 162 | created=self.now, |
160 | 163 | created_by=None, |
161 | 164 | ) |
| 165 | + assert "Only Components can be added as children of a Unit" in str(err.value.__cause__) |
| 166 | + |
| 167 | + # Try adding a generic entity to a Unit |
| 168 | + pe = content_api.create_publishable_entity(self.learning_package.id, "pe", created=self.now, created_by=None) |
| 169 | + pev = content_api.create_publishable_entity_version( |
| 170 | + pe.pk, version_num=1, title="t", created=self.now, created_by=None |
| 171 | + ) |
| 172 | + with pytest.raises(ValidationError, match='The entity "pe" cannot be added to a "unit" container.') as err: |
| 173 | + content_api.create_next_unit_version( |
| 174 | + unit, |
| 175 | + components=[pev], |
| 176 | + created=self.now, |
| 177 | + created_by=None, |
| 178 | + ) |
| 179 | + assert "Only Components can be added as children of a Unit" in str(err.value.__cause__) |
| 180 | + |
162 | 181 | # Check that a new version was not created: |
163 | 182 | unit.refresh_from_db() |
164 | 183 | assert content_api.get_unit(unit.pk).versioning.draft == unit_version |
|
0 commit comments