@@ -103,56 +103,6 @@ def test_pre_save(self):
103
103
self .assertGreater (obj .data .auto_now , auto_now_two )
104
104
105
105
106
- class ArrayFieldTests (TestCase ):
107
- @classmethod
108
- def setUpTestData (cls ):
109
- cls .book = Book .objects .create (
110
- author = Author (
111
- name = "Shakespeare" ,
112
- age = 55 ,
113
- skills = ["writing" , "editing" ],
114
- address = Address (city = "NYC" , state = "NY" , tags = ["home" , "shipping" ]),
115
- ),
116
- )
117
-
118
- def test_contains (self ):
119
- self .assertCountEqual (Book .objects .filter (author__skills__contains = ["nonexistent" ]), [])
120
- self .assertCountEqual (
121
- Book .objects .filter (author__skills__contains = ["writing" ]), [self .book ]
122
- )
123
- # Nested
124
- self .assertCountEqual (
125
- Book .objects .filter (author__address__tags__contains = ["nonexistent" ]), []
126
- )
127
- self .assertCountEqual (
128
- Book .objects .filter (author__address__tags__contains = ["home" ]), [self .book ]
129
- )
130
-
131
- def test_contained_by (self ):
132
- self .assertCountEqual (
133
- Book .objects .filter (author__skills__contained_by = ["writing" , "publishing" ]), []
134
- )
135
- self .assertCountEqual (
136
- Book .objects .filter (author__skills__contained_by = ["writing" , "editing" , "publishing" ]),
137
- [self .book ],
138
- )
139
- # Nested
140
- self .assertCountEqual (
141
- Book .objects .filter (author__address__tags__contained_by = ["home" , "work" ]), []
142
- )
143
- self .assertCountEqual (
144
- Book .objects .filter (author__address__tags__contained_by = ["home" , "work" , "shipping" ]),
145
- [self .book ],
146
- )
147
-
148
- def test_len (self ):
149
- self .assertCountEqual (Book .objects .filter (author__skills__len = 1 ), [])
150
- self .assertCountEqual (Book .objects .filter (author__skills__len = 2 ), [self .book ])
151
- # Nested
152
- self .assertCountEqual (Book .objects .filter (author__address__tags__len = 1 ), [])
153
- self .assertCountEqual (Book .objects .filter (author__address__tags__len = 2 ), [self .book ])
154
-
155
-
156
106
class EmbeddedArrayTests (TestCase ):
157
107
def test_save_load (self ):
158
108
reviews = [
@@ -425,6 +375,56 @@ def test_nested(self):
425
375
self .assertCountEqual (Book .objects .filter (author__address__city = "NYC" ), [obj ])
426
376
427
377
378
+ class ArrayFieldTests (TestCase ):
379
+ @classmethod
380
+ def setUpTestData (cls ):
381
+ cls .book = Book .objects .create (
382
+ author = Author (
383
+ name = "Shakespeare" ,
384
+ age = 55 ,
385
+ skills = ["writing" , "editing" ],
386
+ address = Address (city = "NYC" , state = "NY" , tags = ["home" , "shipping" ]),
387
+ ),
388
+ )
389
+
390
+ def test_contains (self ):
391
+ self .assertCountEqual (Book .objects .filter (author__skills__contains = ["nonexistent" ]), [])
392
+ self .assertCountEqual (
393
+ Book .objects .filter (author__skills__contains = ["writing" ]), [self .book ]
394
+ )
395
+ # Nested
396
+ self .assertCountEqual (
397
+ Book .objects .filter (author__address__tags__contains = ["nonexistent" ]), []
398
+ )
399
+ self .assertCountEqual (
400
+ Book .objects .filter (author__address__tags__contains = ["home" ]), [self .book ]
401
+ )
402
+
403
+ def test_contained_by (self ):
404
+ self .assertCountEqual (
405
+ Book .objects .filter (author__skills__contained_by = ["writing" , "publishing" ]), []
406
+ )
407
+ self .assertCountEqual (
408
+ Book .objects .filter (author__skills__contained_by = ["writing" , "editing" , "publishing" ]),
409
+ [self .book ],
410
+ )
411
+ # Nested
412
+ self .assertCountEqual (
413
+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" ]), []
414
+ )
415
+ self .assertCountEqual (
416
+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" , "shipping" ]),
417
+ [self .book ],
418
+ )
419
+
420
+ def test_len (self ):
421
+ self .assertCountEqual (Book .objects .filter (author__skills__len = 1 ), [])
422
+ self .assertCountEqual (Book .objects .filter (author__skills__len = 2 ), [self .book ])
423
+ # Nested
424
+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 1 ), [])
425
+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 2 ), [self .book ])
426
+
427
+
428
428
class InvalidLookupTests (SimpleTestCase ):
429
429
def test_invalid_field (self ):
430
430
msg = "Author has no field named 'first_name'"
0 commit comments