Skip to content

Commit a6abf2e

Browse files
committed
Adapt tests with person type
1 parent dc7ad88 commit a6abf2e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

app/tests/custom_fields/test_custom_field_base_manager.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from django.contrib.contenttypes.models import ContentType
66

77
from app.models import Person
8+
from app.models import PersonType
89
from app.tests import APITestCase
910
from app.tests.custom_fields.factories import CustomFieldFactory
1011
from app.tests.custom_fields.factories import CustomValueFactory
1112
from app.tests.factories import PersonFactory
13+
from app.tests.factories import PersonTypeFactory
1214
from django_features.custom_fields.models import CustomField
1315

1416

@@ -18,7 +20,9 @@ class CustomFieldBaseModelManagerTest(APITestCase):
1820

1921
def setUp(self) -> None:
2022
self.person_ct = ContentType.objects.get_for_model(Person)
21-
self.person: Person = PersonFactory() # type: ignore
23+
self.person_type_1: PersonType = PersonTypeFactory() # type: ignore
24+
self.person_type_2: PersonType = PersonTypeFactory() # type: ignore
25+
self.person: Person = PersonFactory(person_type=self.person_type_1) # type: ignore
2226

2327
def test_custom_field_base_manager_annotate_custom_field_keys(self) -> None:
2428
CustomFieldFactory(identifier="birthday", content_type=self.person_ct)
@@ -27,6 +31,20 @@ def test_custom_field_base_manager_annotate_custom_field_keys(self) -> None:
2731
["birthday", "hobby"], Person.objects.first().custom_field_keys
2832
)
2933

34+
def test_custom_field_base_manager_annotate_only_type_specific_fields(self) -> None:
35+
CustomFieldFactory(
36+
identifier="birthday",
37+
content_type=self.person_ct,
38+
type_object=self.person_type_1,
39+
)
40+
CustomFieldFactory(
41+
identifier="hobby",
42+
content_type=self.person_ct,
43+
type_object=self.person_type_2,
44+
)
45+
self.person.refresh_with_custom_fields()
46+
self.assertEqual(["birthday"], Person.objects.first().custom_field_keys)
47+
3048
def test_custom_field_base_manager_annotate_char_value(self) -> None:
3149
field = CustomFieldFactory(
3250
identifier="char_value",

app/tests/custom_fields/test_custom_field_base_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from django.contrib.contenttypes.models import ContentType
66

77
from app.models import Person
8+
from app.models import PersonType
89
from app.tests import APITestCase
910
from app.tests.custom_fields.factories import CustomFieldFactory
1011
from app.tests.custom_fields.factories import CustomValueFactory
1112
from app.tests.factories import PersonFactory
13+
from app.tests.factories import PersonTypeFactory
1214
from django_features.custom_fields.models import CustomField
1315
from django_features.custom_fields.models import CustomValue
1416

@@ -19,7 +21,11 @@ class CustomFieldBaseModelTest(APITestCase):
1921

2022
def setUp(self) -> None:
2123
self.person_ct = ContentType.objects.get_for_model(Person)
22-
self.person: Person = PersonFactory() # type: ignore
24+
self.person_type: PersonType = PersonTypeFactory() # type: ignore
25+
self.person: Person = PersonFactory(person_type=self.person_type) # type: ignore
26+
27+
def test_custom_field_base_model_custom_field_type_model(self) -> None:
28+
self.assertEqual(PersonType, Person.objects.get_type_model())
2329

2430
def test_custom_field_base_model_set_char_value(self) -> None:
2531
CustomFieldFactory(

0 commit comments

Comments
 (0)