@@ -203,7 +203,11 @@ def test_update_optional_nested_tuple_of_models(store: Store):
203
203
@pytest .mark .parametrize ("store" , redis_store_fixture )
204
204
def test_update_list_of_tuples_of_nested_models (store : Store ):
205
205
list_of_tuples = [("some book" , books [0 ]), ("book2" , books [2 ])]
206
- data = [Library (name = "Babel Library" , address = "In a book" , list_of_tuples = list_of_tuples )]
206
+ data = [
207
+ Library (
208
+ name = "Babel Library" , address = "In a book" , list_of_tuples = list_of_tuples
209
+ )
210
+ ]
207
211
Library .insert (data )
208
212
# the tuple of nested models is automatically inserted
209
213
got = sorted (Book .select (), key = lambda x : x .title )
@@ -219,9 +223,13 @@ def test_update_list_of_tuples_of_nested_models(store: Store):
219
223
@pytest .mark .parametrize ("store" , redis_store_fixture )
220
224
def test_update_dict_of_models (store : Store ):
221
225
dict_of_models = {"some book" : books [0 ], "book2" : books [2 ]}
222
- data = [Library (name = "Babel Library" , address = "In a book" , dict_of_models = dict_of_models )]
226
+ data = [
227
+ Library (
228
+ name = "Babel Library" , address = "In a book" , dict_of_models = dict_of_models
229
+ )
230
+ ]
223
231
Library .insert (data )
224
- # the tuple of nested models is automatically inserted
232
+ # the dict of nested models is automatically inserted
225
233
got = sorted (Book .select (), key = lambda x : x .title )
226
234
expected_books = [book for _ , book in dict_of_models .items ()]
227
235
expected = sorted (expected_books , key = lambda x : x .title )
@@ -232,6 +240,34 @@ def test_update_dict_of_models(store: Store):
232
240
assert got == expected
233
241
234
242
243
+ @pytest .mark .parametrize ("store" , redis_store_fixture )
244
+ def test_update_filled_optional_nested_model (store : Store ):
245
+ data = [
246
+ Library (name = "Babel Library" , address = "In a book" , optional_nested = books [0 ])
247
+ ]
248
+ Library .insert (data )
249
+
250
+ got = sorted (Book .select (), key = lambda x : x .title )
251
+ assert [books [0 ]] == got
252
+
253
+ got = sorted (Library .select (), key = lambda x : x .name )
254
+ expected = sorted (data , key = lambda x : x .name )
255
+ assert got == expected
256
+
257
+
258
+ @pytest .mark .parametrize ("store" , redis_store_fixture )
259
+ def test_update_unfilled_optional_nested_model (store : Store ):
260
+ data = [Library (name = "Babel Library" , address = "In a book" )]
261
+ Library .insert (data )
262
+
263
+ got = Book .select ()
264
+ assert got is None
265
+
266
+ got = sorted (Library .select (), key = lambda x : x .name )
267
+ expected = sorted (data , key = lambda x : x .name )
268
+ assert got == expected
269
+
270
+
235
271
@pytest .mark .parametrize ("store" , redis_store_fixture )
236
272
def test_select_default (store : Store ):
237
273
"""Selecting without arguments returns all the book models"""
0 commit comments