Skip to content

test: verify correct typing of mixins #280

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion tests/openedx_learning/apps/authoring/components/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Tests related to the Component models
"""
from datetime import datetime, timezone
from typing import TYPE_CHECKING, assert_type

from freezegun import freeze_time

Expand All @@ -10,7 +11,7 @@
get_component,
get_or_create_component_type,
)
from openedx_learning.apps.authoring.components.models import ComponentType
from openedx_learning.apps.authoring.components.models import Component, ComponentType, ComponentVersion
from openedx_learning.apps.authoring.publishing.api import (
LearningPackage,
create_learning_package,
Expand All @@ -19,6 +20,15 @@
)
from openedx_learning.lib.test_utils import TestCase

if TYPE_CHECKING:
# Test that our mixins on Component.objects and PublishableEntityVersionMixin etc. haven't broken manager typing
assert_type(Component.objects.create(), Component)
assert_type(Component.objects.get(), Component)
assert_type(Component.with_publishing_relations.create(), Component)
assert_type(Component.with_publishing_relations.get(), Component)
assert_type(ComponentVersion.objects.create(), ComponentVersion)
assert_type(ComponentVersion.objects.get(), ComponentVersion)


class TestModelVersioningQueries(TestCase):
"""
Expand Down
21 changes: 21 additions & 0 deletions tests/openedx_learning/apps/authoring/publishing/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Tests related to the Publishing model mixins
"""
from typing import TYPE_CHECKING, assert_type

from openedx_learning.apps.authoring.publishing.models import PublishableEntityMixin, PublishableEntityVersionMixin
from openedx_learning.lib.managers import WithRelationsManager

if TYPE_CHECKING:
# Test that our mixins provide the right typing for 'objects'
class FooEntity(PublishableEntityMixin):
pass

assert_type(FooEntity.objects.create(), FooEntity)
assert_type(FooEntity.objects, WithRelationsManager[FooEntity])

class FooEntityVersion(PublishableEntityVersionMixin):
pass

assert_type(FooEntityVersion.objects.create(), FooEntityVersion)
assert_type(FooEntityVersion.objects, WithRelationsManager[FooEntityVersion])