File tree 2 files changed +32
-1
lines changed
tests/openedx_learning/apps/authoring
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 2
2
Tests related to the Component models
3
3
"""
4
4
from datetime import datetime , timezone
5
+ from typing import TYPE_CHECKING , assert_type
5
6
6
7
from freezegun import freeze_time
7
8
10
11
get_component ,
11
12
get_or_create_component_type ,
12
13
)
13
- from openedx_learning .apps .authoring .components .models import ComponentType
14
+ from openedx_learning .apps .authoring .components .models import Component , ComponentType , ComponentVersion
14
15
from openedx_learning .apps .authoring .publishing .api import (
15
16
LearningPackage ,
16
17
create_learning_package ,
19
20
)
20
21
from openedx_learning .lib .test_utils import TestCase
21
22
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
+
22
32
23
33
class TestModelVersioningQueries (TestCase ):
24
34
"""
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