@@ -103,56 +103,6 @@ def test_pre_save(self):
103103 self .assertGreater (obj .data .auto_now , auto_now_two )
104104
105105
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-
156106class EmbeddedArrayTests (TestCase ):
157107 def test_save_load (self ):
158108 reviews = [
@@ -485,6 +435,56 @@ def test_nested(self):
485435 self .assertCountEqual (Book .objects .filter (author__address__city = "NYC" ), [obj ])
486436
487437
438+ class ArrayFieldTests (TestCase ):
439+ @classmethod
440+ def setUpTestData (cls ):
441+ cls .book = Book .objects .create (
442+ author = Author (
443+ name = "Shakespeare" ,
444+ age = 55 ,
445+ skills = ["writing" , "editing" ],
446+ address = Address (city = "NYC" , state = "NY" , tags = ["home" , "shipping" ]),
447+ ),
448+ )
449+
450+ def test_contains (self ):
451+ self .assertCountEqual (Book .objects .filter (author__skills__contains = ["nonexistent" ]), [])
452+ self .assertCountEqual (
453+ Book .objects .filter (author__skills__contains = ["writing" ]), [self .book ]
454+ )
455+ # Nested
456+ self .assertCountEqual (
457+ Book .objects .filter (author__address__tags__contains = ["nonexistent" ]), []
458+ )
459+ self .assertCountEqual (
460+ Book .objects .filter (author__address__tags__contains = ["home" ]), [self .book ]
461+ )
462+
463+ def test_contained_by (self ):
464+ self .assertCountEqual (
465+ Book .objects .filter (author__skills__contained_by = ["writing" , "publishing" ]), []
466+ )
467+ self .assertCountEqual (
468+ Book .objects .filter (author__skills__contained_by = ["writing" , "editing" , "publishing" ]),
469+ [self .book ],
470+ )
471+ # Nested
472+ self .assertCountEqual (
473+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" ]), []
474+ )
475+ self .assertCountEqual (
476+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" , "shipping" ]),
477+ [self .book ],
478+ )
479+
480+ def test_len (self ):
481+ self .assertCountEqual (Book .objects .filter (author__skills__len = 1 ), [])
482+ self .assertCountEqual (Book .objects .filter (author__skills__len = 2 ), [self .book ])
483+ # Nested
484+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 1 ), [])
485+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 2 ), [self .book ])
486+
487+
488488class InvalidLookupTests (SimpleTestCase ):
489489 def test_invalid_field (self ):
490490 msg = "Author has no field named 'first_name'"
0 commit comments