@@ -41,6 +41,14 @@ class FakeAllQuerySetComponent(UnicornView):
4141 queryset_with_no_typehint = Flavor .objects .none ()
4242
4343
44+ def component_queryset_field_asserts (component , field_name ):
45+ field = getattr (component , field_name )
46+ assert isinstance (field , QuerySet )
47+ assert field .model == Flavor
48+ assert len (field ) == 1
49+ assert field [0 ].name == "test-qs"
50+
51+
4452def test_set_property_from_data_str ():
4553 component = FakeComponent (component_name = "test" , component_id = "12345678" )
4654 assert "property_view" == component .string
@@ -95,12 +103,9 @@ def test_set_property_from_data_empty_queryset():
95103 component = FakeComponent (component_name = "test" , component_id = "12345678" )
96104 assert len (component .queryset ) == 0
97105
98- set_property_from_data (component , "queryset" , [{"name" : "test-qs-test " }])
106+ set_property_from_data (component , "queryset" , [{"name" : "test-qs" }])
99107
100- assert isinstance (component .queryset , QuerySet )
101- assert component .queryset .model == Flavor
102- assert len (component .queryset ) == 1
103- assert component .queryset [0 ].name == "test-qs-test"
108+ component_queryset_field_asserts (component , "queryset" )
104109
105110
106111@pytest .mark .django_db
@@ -109,77 +114,43 @@ def test_set_property_from_data_queryset():
109114 assert len (component .queryset_with_data ) == 1
110115
111116 set_property_from_data (
112- component , "queryset_with_data" , [{"pk" : 1 , "name" : "test-qs-with-data " }]
117+ component , "queryset_with_data" , [{"pk" : 1 , "name" : "test-qs" }]
113118 )
114119
115- assert isinstance (component .queryset_with_data , QuerySet )
116- assert component .queryset_with_data .model == Flavor
117- assert len (component .queryset_with_data ) == 1
118- assert component .queryset_with_data [0 ].name == "test-qs-with-data"
120+ component_queryset_field_asserts (component , "queryset_with_data" )
119121
120122
121123def test_set_property_from_data_queryset_list_with_typehint ():
122124 component = FakeComponent (component_name = "test" , component_id = "12345678" )
123125 assert len (component .queryset_with_typehint ) == 0
124126
125- set_property_from_data (
126- component , "queryset_with_typehint" , [{"name" : "test-qs-test-1" }]
127- )
127+ set_property_from_data (component , "queryset_with_typehint" , [{"name" : "test-qs" }])
128128
129- assert isinstance (component .queryset_with_typehint , QuerySet )
130- assert component .queryset_with_typehint .model == Flavor
131- assert len (component .queryset_with_typehint ) == 1
132- assert component .queryset_with_typehint [0 ].name == "test-qs-test-1"
129+ component_queryset_field_asserts (component , "queryset_with_typehint" )
133130
134131
135132def test_set_property_from_data_queryset_none_with_typehint ():
136133 component = FakeQuerySetComponent (component_name = "test" , component_id = "12345678" )
137134 assert component .queryset_with_typehint is None
138135
139- set_property_from_data (
140- component , "queryset_with_typehint" , [{"name" : "test-qs-test-2" }]
141- )
136+ set_property_from_data (component , "queryset_with_typehint" , [{"name" : "test-qs" }])
142137
143- assert isinstance (component .queryset_with_typehint , QuerySet )
144- assert component .queryset_with_typehint .model == Flavor
145- assert len (component .queryset_with_typehint ) == 1
146- assert component .queryset_with_typehint [0 ].name == "test-qs-test-2"
138+ component_queryset_field_asserts (component , "queryset_with_typehint" )
147139
148140
149141def test_set_property_from_data_all_querysets ():
150142 component = FakeAllQuerySetComponent (component_name = "test" , component_id = "12345678" )
151143
144+ set_property_from_data (component , "queryset_with_empty_list" , [{"name" : "test-qs" }])
145+ set_property_from_data (component , "queryset_with_none" , [{"name" : "test-qs" }])
152146 set_property_from_data (
153- component , "queryset_with_empty_list" , [{"name" : "test-all-qs-test" }]
154- )
155- set_property_from_data (
156- component , "queryset_with_none" , [{"name" : "test-all-qs-test" }]
147+ component , "queryset_with_empty_queryset" , [{"name" : "test-qs" }]
157148 )
158149 set_property_from_data (
159- component , "queryset_with_empty_queryset" , [{"name" : "test-all-qs-test" }]
160- )
161- set_property_from_data (
162- component , "queryset_with_no_typehint" , [{"name" : "test-all-qs-test" }]
150+ component , "queryset_with_no_typehint" , [{"name" : "test-qs" }]
163151 )
164152
165- assert isinstance (component .queryset_with_empty_list , QuerySet )
166- assert isinstance (component .queryset_with_none , QuerySet )
167- assert isinstance (component .queryset_with_empty_queryset , QuerySet )
168- assert isinstance (component .queryset_with_no_typehint , QuerySet )
169-
170- assert component .queryset_with_empty_list .model == Flavor
171- assert component .queryset_with_none .model == Flavor
172- assert component .queryset_with_empty_queryset .model == Flavor
173- assert component .queryset_with_no_typehint .model == Flavor
174-
175- assert len (component .queryset_with_empty_list ) == 1
176- assert len (component .queryset_with_none ) == 1
177- assert len (component .queryset_with_empty_queryset ) == 1
178- assert len (component .queryset_with_no_typehint ) == 1
179-
180- assert (
181- component .queryset_with_empty_list [0 ].name
182- == component .queryset_with_none [0 ].name
183- == component .queryset_with_empty_queryset [0 ].name
184- == component .queryset_with_no_typehint [0 ].name
185- )
153+ component_queryset_field_asserts (component , "queryset_with_empty_list" )
154+ component_queryset_field_asserts (component , "queryset_with_none" )
155+ component_queryset_field_asserts (component , "queryset_with_empty_queryset" )
156+ component_queryset_field_asserts (component , "queryset_with_no_typehint" )
0 commit comments