Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containers/units: High level APIs and expanded test cases #278

Open
wants to merge 26 commits into
base: braden/containers-units-ref
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a24a964
feat: Implement higher-level APIs for getting components from units
bradenmacdonald Feb 13, 2025
fe9ccf9
test: Expand test cases
bradenmacdonald Feb 13, 2025
7eaa206
feat: Add a contains_unpublished_changes API
bradenmacdonald Feb 14, 2025
3ac1e11
perf: Optimize contains_unpublished_changes to check a unit using onl…
bradenmacdonald Feb 14, 2025
236f7cc
refactor: Simplify EntityList: merge draft_version+published_version …
bradenmacdonald Feb 14, 2025
5f08231
refactor: Simplify create_next_unit_version() API
bradenmacdonald Feb 14, 2025
3545527
test: add tests for pinned components
bradenmacdonald Feb 15, 2025
275d5d0
feat: remove defined_list/initial_list/frozen_list from the API for now
bradenmacdonald Feb 15, 2025
5750147
docs: mark all containers APIs as unstable
bradenmacdonald Feb 15, 2025
fd83bd6
fix: minor corrections to units/containers API
bradenmacdonald Feb 15, 2025
a061722
feat: API to get a historic published version of a unit
bradenmacdonald Feb 16, 2025
74247f3
test: verify that units can only contain Components, not other types
bradenmacdonald Feb 16, 2025
e7e6472
test: "creating two units with the same components"
bradenmacdonald Feb 16, 2025
6cc36c0
test: verify that components are from the same learning package
bradenmacdonald Feb 18, 2025
c268dff
test: implement test_publishing_shared_component based on Slack convo
bradenmacdonald Feb 18, 2025
a6f21d3
test: clean up unit tests by implying pinned+false by default
bradenmacdonald Feb 18, 2025
735f4e4
chore: fix minor quality issues
bradenmacdonald Feb 19, 2025
8f27192
refactor: re-enable the too-many-positional-arguments pylint check
bradenmacdonald Feb 19, 2025
4f50022
fix: reduce query count of contains_unpublished_changes
bradenmacdonald Feb 20, 2025
f9d7f48
fix: mypy typing
bradenmacdonald Feb 20, 2025
703c0cf
fix: verify that all container entities are in the right learning pac…
bradenmacdonald Feb 20, 2025
f31c1de
chore: fix quality issues
bradenmacdonald Feb 20, 2025
e07a741
test: tests related to [soft] deletion/removal of components
bradenmacdonald Feb 20, 2025
e09a20e
refactor: consolidate defined_list/initial_list/frozen_list into enti…
bradenmacdonald Feb 21, 2025
1fc456e
test: add tests that publishes cascade down but not up
bradenmacdonald Feb 21, 2025
722026d
test: update docs about further tests we should write
bradenmacdonald Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openedx_learning/api/authoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# pylint: disable=wildcard-import
from ..apps.authoring.collections.api import *
from ..apps.authoring.components.api import *
from ..apps.authoring.containers.api import *
from ..apps.authoring.contents.api import *
from ..apps.authoring.publishing.api import *
from ..apps.authoring.containers.api import *
from ..apps.authoring.units.api import *

# This was renamed after the authoring API refactoring pushed this and other
Expand Down
2 changes: 2 additions & 0 deletions openedx_learning/api/authoring_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# pylint: disable=wildcard-import
from ..apps.authoring.collections.models import *
from ..apps.authoring.components.models import *
from ..apps.authoring.containers.models import *
from ..apps.authoring.contents.models import *
from ..apps.authoring.publishing.model_mixins import *
from ..apps.authoring.publishing.models import *
from ..apps.authoring.units.models import *
4 changes: 2 additions & 2 deletions openedx_learning/apps/authoring/components/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def create_next_component_version(
return component_version


def create_component_and_version(
def create_component_and_version( # pylint: disable=too-many-positional-arguments
learning_package_id: int,
/,
component_type: ComponentType,
Expand Down Expand Up @@ -326,7 +326,7 @@ def component_exists_by_key(
return False


def get_components(
def get_components( # pylint: disable=too-many-positional-arguments
learning_package_id: int,
/,
draft: bool | None = None,
Expand Down
16 changes: 6 additions & 10 deletions openedx_learning/apps/authoring/components/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"""
from __future__ import annotations

from typing import ClassVar

from django.db import models

from ....lib.fields import case_sensitive_char_field, immutable_uuid_field, key_field
Expand Down Expand Up @@ -76,7 +78,7 @@ def __str__(self):
return f"{self.namespace}:{self.name}"


class Component(PublishableEntityMixin): # type: ignore[django-manager-missing]
class Component(PublishableEntityMixin):
"""
This represents any Component that has ever existed in a LearningPackage.

Expand Down Expand Up @@ -120,14 +122,12 @@ class Component(PublishableEntityMixin): # type: ignore[django-manager-missing]
Make a foreign key to the Component model when you need a stable reference
that will exist for as long as the LearningPackage itself exists.
"""
# Tell mypy what type our objects manager has.
# It's actually PublishableEntityMixinManager, but that has the exact same
# interface as the base manager class.
objects: models.Manager[Component] = WithRelationsManager(
# Set up our custom manager. It has the same API as the default one, but selects related objects by default.
objects: ClassVar[WithRelationsManager[Component]] = WithRelationsManager( # type: ignore[assignment]
'component_type'
)

with_publishing_relations: models.Manager[Component] = WithRelationsManager(
with_publishing_relations = WithRelationsManager(
'component_type',
'publishable_entity',
'publishable_entity__draft__version',
Expand Down Expand Up @@ -201,10 +201,6 @@ class ComponentVersion(PublishableEntityVersionMixin):
This holds the content using a M:M relationship with Content via
ComponentVersionContent.
"""
# Tell mypy what type our objects manager has.
# It's actually PublishableEntityVersionMixinManager, but that has the exact
# same interface as the base manager class.
objects: models.Manager[ComponentVersion]

# This is technically redundant, since we can get this through
# publishable_entity_version.publishable.component, but this is more
Expand Down
Loading