@@ -101,56 +101,6 @@ def test_pre_save(self):
101101 self .assertGreater (obj .data .auto_now , auto_now_two )
102102
103103
104- class ArrayFieldTests (TestCase ):
105- @classmethod
106- def setUpTestData (cls ):
107- cls .book = Book .objects .create (
108- author = Author (
109- name = "Shakespeare" ,
110- age = 55 ,
111- skills = ["writing" , "editing" ],
112- address = Address (city = "NYC" , state = "NY" , tags = ["home" , "shipping" ]),
113- ),
114- )
115-
116- def test_contains (self ):
117- self .assertCountEqual (Book .objects .filter (author__skills__contains = ["nonexistent" ]), [])
118- self .assertCountEqual (
119- Book .objects .filter (author__skills__contains = ["writing" ]), [self .book ]
120- )
121- # Nested
122- self .assertCountEqual (
123- Book .objects .filter (author__address__tags__contains = ["nonexistent" ]), []
124- )
125- self .assertCountEqual (
126- Book .objects .filter (author__address__tags__contains = ["home" ]), [self .book ]
127- )
128-
129- def test_contained_by (self ):
130- self .assertCountEqual (
131- Book .objects .filter (author__skills__contained_by = ["writing" , "publishing" ]), []
132- )
133- self .assertCountEqual (
134- Book .objects .filter (author__skills__contained_by = ["writing" , "editing" , "publishing" ]),
135- [self .book ],
136- )
137- # Nested
138- self .assertCountEqual (
139- Book .objects .filter (author__address__tags__contained_by = ["home" , "work" ]), []
140- )
141- self .assertCountEqual (
142- Book .objects .filter (author__address__tags__contained_by = ["home" , "work" , "shipping" ]),
143- [self .book ],
144- )
145-
146- def test_len (self ):
147- self .assertCountEqual (Book .objects .filter (author__skills__len = 1 ), [])
148- self .assertCountEqual (Book .objects .filter (author__skills__len = 2 ), [self .book ])
149- # Nested
150- self .assertCountEqual (Book .objects .filter (author__address__tags__len = 1 ), [])
151- self .assertCountEqual (Book .objects .filter (author__address__tags__len = 2 ), [self .book ])
152-
153-
154104class EmbeddedArrayTests (TestCase ):
155105 def test_save_load (self ):
156106 reviews = [
@@ -461,6 +411,56 @@ def test_nested(self):
461411 self .assertCountEqual (Book .objects .filter (author__address__city = "NYC" ), [obj ])
462412
463413
414+ class ArrayFieldTests (TestCase ):
415+ @classmethod
416+ def setUpTestData (cls ):
417+ cls .book = Book .objects .create (
418+ author = Author (
419+ name = "Shakespeare" ,
420+ age = 55 ,
421+ skills = ["writing" , "editing" ],
422+ address = Address (city = "NYC" , state = "NY" , tags = ["home" , "shipping" ]),
423+ ),
424+ )
425+
426+ def test_contains (self ):
427+ self .assertCountEqual (Book .objects .filter (author__skills__contains = ["nonexistent" ]), [])
428+ self .assertCountEqual (
429+ Book .objects .filter (author__skills__contains = ["writing" ]), [self .book ]
430+ )
431+ # Nested
432+ self .assertCountEqual (
433+ Book .objects .filter (author__address__tags__contains = ["nonexistent" ]), []
434+ )
435+ self .assertCountEqual (
436+ Book .objects .filter (author__address__tags__contains = ["home" ]), [self .book ]
437+ )
438+
439+ def test_contained_by (self ):
440+ self .assertCountEqual (
441+ Book .objects .filter (author__skills__contained_by = ["writing" , "publishing" ]), []
442+ )
443+ self .assertCountEqual (
444+ Book .objects .filter (author__skills__contained_by = ["writing" , "editing" , "publishing" ]),
445+ [self .book ],
446+ )
447+ # Nested
448+ self .assertCountEqual (
449+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" ]), []
450+ )
451+ self .assertCountEqual (
452+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" , "shipping" ]),
453+ [self .book ],
454+ )
455+
456+ def test_len (self ):
457+ self .assertCountEqual (Book .objects .filter (author__skills__len = 1 ), [])
458+ self .assertCountEqual (Book .objects .filter (author__skills__len = 2 ), [self .book ])
459+ # Nested
460+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 1 ), [])
461+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 2 ), [self .book ])
462+
463+
464464class InvalidLookupTests (SimpleTestCase ):
465465 def test_invalid_field (self ):
466466 msg = "Author has no field named 'first_name'"
0 commit comments