Skip to content

Commit bc3e931

Browse files
refactor: Unit -> UnitType, etc.
1 parent cd2e1a6 commit bc3e931

10 files changed

Lines changed: 43 additions & 43 deletions

File tree

src/openedx_content/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
from .applets.components.api import *
1616
from .applets.media.api import *
1717
from .applets.publishing.api import *
18-
from .applets.sections.models import Section # Note this isn't a model. Should we move it?
19-
from .applets.subsections.models import Subsection # Note this isn't a model. Should we move it?
20-
from .applets.units.models import Unit # Note this isn't a model. Should we move it?
18+
from .applets.sections.models import SectionType # Note this isn't a model. Should we move it?
19+
from .applets.subsections.models import SubsectionType # Note this isn't a model. Should we move it?
20+
from .applets.units.models import UnitType # Note this isn't a model. Should we move it?

src/openedx_content/applets/backup_restore/zipper.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
from ..components import api as components_api
3434
from ..media import api as media_api
3535
from ..publishing import api as publishing_api
36-
from ..units.models import Unit
37-
from ..subsections.models import Subsection
38-
from ..sections.models import Section
36+
from ..units.models import UnitType
37+
from ..subsections.models import SubsectionType
38+
from ..sections.models import SectionType
3939
from .serializers import (
4040
CollectionSerializer,
4141
ComponentSerializer,
@@ -843,7 +843,7 @@ def _save_units(self, learning_package, containers):
843843
self._save_container(
844844
learning_package,
845845
containers,
846-
container_type=Unit,
846+
container_type=UnitType,
847847
container_map=self.units_map_by_key,
848848
children_map=self.components_map_by_key,
849849
)
@@ -853,7 +853,7 @@ def _save_subsections(self, learning_package, containers):
853853
self._save_container(
854854
learning_package,
855855
containers,
856-
container_type=Subsection,
856+
container_type=SubsectionType,
857857
container_map=self.subsections_map_by_key,
858858
children_map=self.units_map_by_key,
859859
)
@@ -863,7 +863,7 @@ def _save_sections(self, learning_package, containers):
863863
self._save_container(
864864
learning_package,
865865
containers,
866-
container_type=Section,
866+
container_type=SectionType,
867867
container_map=self.sections_map_by_key,
868868
children_map=self.subsections_map_by_key,
869869
)
@@ -907,9 +907,9 @@ def _process_draft_containers(
907907
created_by=self.user_id,
908908
)
909909

910-
_process_draft_containers(Unit, self.units_map_by_key, children_map=self.components_map_by_key)
911-
_process_draft_containers(Subsection, self.subsections_map_by_key, children_map=self.units_map_by_key)
912-
_process_draft_containers(Section, self.sections_map_by_key, children_map=self.subsections_map_by_key)
910+
_process_draft_containers(UnitType, self.units_map_by_key, children_map=self.components_map_by_key)
911+
_process_draft_containers(SubsectionType, self.subsections_map_by_key, children_map=self.units_map_by_key)
912+
_process_draft_containers(SectionType, self.sections_map_by_key, children_map=self.subsections_map_by_key)
913913

914914
# --------------------------
915915
# Utilities

src/openedx_content/applets/sections/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
from ..publishing.api import ContainerTypeImplementation, get_container_type
1010
from ..publishing.models import PublishableEntity
11-
from ..subsections.models import Subsection
11+
from ..subsections.models import SubsectionType
1212

1313
__all__ = [
14-
"Section",
14+
"SectionType",
1515
]
1616

1717

18-
class Section(ContainerTypeImplementation):
18+
class SectionType(ContainerTypeImplementation):
1919
"""
2020
A Section is type of Container that holds Subsections.
2121
@@ -31,10 +31,10 @@ def validate_entity(cls, entity: PublishableEntity) -> None:
3131
"""Check if the given entity is allowed as a child of a Section"""
3232
# Sections only allow Subsections as children, so the entity must be 1:1 with Container:
3333
container = entity.container # Could raise PublishableEntity.container.RelatedObjectDoesNotExist
34-
if get_container_type(container) is not Subsection:
34+
if get_container_type(container) is not SubsectionType:
3535
raise ValidationError("Only Subsection can be added as children of a Section")
3636

3737
# validate settings
3838

3939

40-
ContainerTypeImplementation.register(Section)
40+
ContainerTypeImplementation.register(SectionType)

src/openedx_content/applets/subsections/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
from ..publishing.api import ContainerTypeImplementation, get_container_type
1010
from ..publishing.models import PublishableEntity
11-
from ..units.models import Unit
11+
from ..units.models import UnitType
1212

1313
__all__ = [
14-
"Subsection",
14+
"SubsectionType",
1515
]
1616

1717

18-
class Subsection(ContainerTypeImplementation):
18+
class SubsectionType(ContainerTypeImplementation):
1919
"""
2020
A Subsection is type of Container that holds Units.
2121
@@ -31,10 +31,10 @@ def validate_entity(cls, entity: PublishableEntity) -> None:
3131
"""Check if the given entity is allowed as a child of a Subsection"""
3232
# Subsections only allow Units as children, so the entity must be 1:1 with Container:
3333
container = entity.container # Could raise PublishableEntity.container.RelatedObjectDoesNotExist
34-
if get_container_type(container) is not Unit:
34+
if get_container_type(container) is not UnitType:
3535
raise ValidationError("Only Units can be added as children of a Subsection")
3636

3737
# validate settings
3838

3939

40-
ContainerTypeImplementation.register(Subsection)
40+
ContainerTypeImplementation.register(SubsectionType)

src/openedx_content/applets/units/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from ..publishing.models import PublishableEntity
99

1010
__all__ = [
11-
"Unit",
11+
"UnitType",
1212
]
1313

1414

15-
class Unit(ContainerTypeImplementation):
15+
class UnitType(ContainerTypeImplementation):
1616
"""
1717
A Unit is type of Container that holds Components.
1818
@@ -32,4 +32,4 @@ def validate_entity(cls, entity: PublishableEntity) -> None:
3232
# validate settings
3333

3434

35-
ContainerTypeImplementation.register(Unit)
35+
ContainerTypeImplementation.register(UnitType)

tests/openedx_content/applets/backup_restore/test_backup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def setUpTestData(cls):
163163
key="unit-1",
164164
created=cls.now,
165165
created_by=cls.user.id,
166-
container_type=api.Unit,
166+
container_type=api.UnitType,
167167
)
168168

169169
def check_toml_file(self, zip_path: Path, zip_member_name: Path, content_to_check: list):

tests/openedx_content/applets/collections/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def setUpTestData(cls) -> None:
251251
key="unit-1",
252252
created=created_time,
253253
created_by=cls.user.id,
254-
container_type=api.Unit,
254+
container_type=api.UnitType,
255255
)
256256

257257
# Make and publish one Component

tests/openedx_content/applets/publishing/container_test_case.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ class ContainerTestCase(ComponentTestCase):
4040

4141
def setUp(self) -> None:
4242
super().setUp()
43-
self.create_unit = partial(self.create_container, container_type=content_api.Unit)
44-
self.create_unit_and_version = partial(self.create_container_and_version, container_type=content_api.Unit)
45-
self.create_subsection = partial(self.create_container, container_type=content_api.Subsection)
43+
self.create_unit = partial(self.create_container, container_type=content_api.UnitType)
44+
self.create_unit_and_version = partial(self.create_container_and_version, container_type=content_api.UnitType)
45+
self.create_subsection = partial(self.create_container, container_type=content_api.SubsectionType)
4646
self.create_subsection_and_version = partial(
47-
self.create_container_and_version, container_type=content_api.Subsection
47+
self.create_container_and_version, container_type=content_api.SubsectionType
4848
)
49-
self.create_section = partial(self.create_container, container_type=content_api.Section)
50-
self.create_section_and_version = partial(self.create_container_and_version, container_type=content_api.Section)
49+
self.create_section = partial(self.create_container, container_type=content_api.SectionType)
50+
self.create_section_and_version = partial(self.create_container_and_version, container_type=content_api.SectionType)
5151

5252
def create_component(
5353
self, *, title: str = "Test Component", key: str = "component:1"

tests/openedx_content/applets/subsections/test_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_create_subsection_with_invalid_children(self):
9595
title="Subsection",
9696
created=self.now,
9797
created_by=None,
98-
container_type=content_api.Subsection,
98+
container_type=content_api.SubsectionType,
9999
)
100100
assert subsection.versioning.draft == subsection_version
101101
subsection2, _s2v1 = content_api.create_container_and_version(
@@ -104,7 +104,7 @@ def test_create_subsection_with_invalid_children(self):
104104
title="Subsection 2",
105105
created=self.now,
106106
created_by=None,
107-
container_type=content_api.Subsection,
107+
container_type=content_api.SubsectionType,
108108
)
109109
# Try adding a Subsection to a Subsection
110110
with pytest.raises(
@@ -135,7 +135,7 @@ def test_adding_external_units(self):
135135
title="Subsection",
136136
created=self.now,
137137
created_by=None,
138-
container_type=content_api.Subsection,
138+
container_type=content_api.SubsectionType,
139139
)
140140
assert self.unit_1.publishable_entity.learning_package != learning_package2
141141
# Try adding a a unit from LP 1 (self.learning_package) to a subsection from LP 2
@@ -187,7 +187,7 @@ def test_create_empty_subsection_and_version(self):
187187
title="Subsection",
188188
created=self.now,
189189
created_by=None,
190-
container_type=content_api.Subsection,
190+
container_type=content_api.SubsectionType,
191191
)
192192
assert subsection, subsection_version
193193
assert subsection_version.version_num == 1
@@ -212,7 +212,7 @@ def test_create_next_subsection_version_with_two_unpinned_units(self):
212212
title="Subsection",
213213
created=self.now,
214214
created_by=None,
215-
container_type=content_api.Subsection,
215+
container_type=content_api.SubsectionType,
216216
)
217217
subsection_version_v2 = content_api.create_next_container_version(
218218
subsection.pk,
@@ -241,7 +241,7 @@ def test_create_next_subsection_version_forcing_version_num(self):
241241
title="Subsection",
242242
created=self.now,
243243
created_by=None,
244-
container_type=content_api.Subsection,
244+
container_type=content_api.SubsectionType,
245245
)
246246
subsection_version_v2 = content_api.create_next_container_version(
247247
subsection.pk,
@@ -263,7 +263,7 @@ def test_create_next_subsection_version_with_unpinned_and_pinned_units(self):
263263
title="Subsection",
264264
created=self.now,
265265
created_by=None,
266-
container_type=content_api.Subsection,
266+
container_type=content_api.SubsectionType,
267267
)
268268
subsection_version_v2 = content_api.create_next_container_version(
269269
subsection.pk,
@@ -346,7 +346,7 @@ def test_add_unit_after_publish(self):
346346
title="Subsection",
347347
created=self.now,
348348
created_by=None,
349-
container_type=content_api.Subsection,
349+
container_type=content_api.SubsectionType,
350350
)
351351
assert subsection.versioning.draft == subsection_version
352352
assert subsection.versioning.published is None
@@ -972,7 +972,7 @@ def test_add_remove_container_children(self):
972972
entities=[self.unit_1],
973973
created=self.now,
974974
created_by=None,
975-
container_type=content_api.Subsection,
975+
container_type=content_api.SubsectionType,
976976
)
977977
assert content_api.get_entities_in_container(subsection, published=False) == [
978978
Entry(self.unit_1.versioning.draft),

tests/openedx_content/applets/units/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_adding_external_components(self):
142142
title="Unit",
143143
created=self.now,
144144
created_by=None,
145-
container_type=content_api.Unit,
145+
container_type=content_api.UnitType,
146146
)
147147
assert self.component_1.learning_package != learning_package2
148148
# Try adding a a component from LP 1 (self.learning_package) to a unit from LP 2

0 commit comments

Comments
 (0)