File tree Expand file tree Collapse file tree
tests/openedx_learning/apps/authoring Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22Tests related to the Component models
33"""
44from datetime import datetime , timezone
5+ from typing import TYPE_CHECKING , assert_type
56
67from freezegun import freeze_time
78
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
1415from openedx_learning .apps .authoring .publishing .api import (
1516 LearningPackage ,
1617 create_learning_package ,
1920)
2021from 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
2333class TestModelVersioningQueries (TestCase ):
2434 """
Original file line number Diff line number Diff line change 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 ])
You can’t perform that action at this time.
0 commit comments