Skip to content

Commit fa0424d

Browse files
test: check typing of mixins
1 parent 16a7b10 commit fa0424d

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

tests/openedx_learning/apps/authoring/components/test_models.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests related to the Component models
33
"""
44
from datetime import datetime, timezone
5+
from typing import TYPE_CHECKING, assert_type
56

67
from freezegun import freeze_time
78

@@ -10,7 +11,7 @@
1011
get_component,
1112
get_or_create_component_type,
1213
)
13-
from openedx_learning.apps.authoring.components.models import ComponentType
14+
from openedx_learning.apps.authoring.components.models import Component, ComponentType, ComponentVersion
1415
from openedx_learning.apps.authoring.publishing.api import (
1516
LearningPackage,
1617
create_learning_package,
@@ -19,6 +20,15 @@
1920
)
2021
from openedx_learning.lib.test_utils import TestCase
2122

23+
if TYPE_CHECKING:
24+
# Test that our mixins on Component.objects and PublishableEntityVersionMixin etc. haven't broken manager typing
25+
assert_type(Component.objects.create(), Component)
26+
assert_type(Component.objects.get(), Component)
27+
assert_type(Component.with_publishing_relations.create(), Component)
28+
assert_type(Component.with_publishing_relations.get(), Component)
29+
assert_type(ComponentVersion.objects.create(), ComponentVersion)
30+
assert_type(ComponentVersion.objects.get(), ComponentVersion)
31+
2232

2333
class TestModelVersioningQueries(TestCase):
2434
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Tests related to the Publishing model mixins
3+
"""
4+
from typing import TYPE_CHECKING, assert_type
5+
6+
from openedx_learning.apps.authoring.publishing.models import PublishableEntityMixin, PublishableEntityVersionMixin
7+
from openedx_learning.lib.managers import WithRelationsManager
8+
9+
if TYPE_CHECKING:
10+
# Test that our mixins provide the right typing for 'objects'
11+
class FooEntity(PublishableEntityMixin):
12+
pass
13+
14+
assert_type(FooEntity.objects.create(), FooEntity)
15+
assert_type(FooEntity.objects, WithRelationsManager[FooEntity])
16+
17+
class FooEntityVersion(PublishableEntityVersionMixin):
18+
pass
19+
20+
assert_type(FooEntityVersion.objects.create(), FooEntityVersion)
21+
assert_type(FooEntityVersion.objects, WithRelationsManager[FooEntityVersion])

0 commit comments

Comments
 (0)