@@ -186,6 +186,49 @@ def test_nested(self):
186186 self .assertCountEqual (Book .objects .filter (author__address__city = "NYC" ), [obj ])
187187
188188
189+ class  ArrayFieldTests (TestCase ):
190+  @classmethod  
191+  def  setUpTestData (cls ):
192+  cls .book  =  Book .objects .create (
193+  author = Author (
194+  name = "Shakespeare" ,
195+  age = 55 ,
196+  skills = ["writing" , "editing" ],
197+  address = Address (city = "NYC" , state = "NY" , tags = ["home" , "shipping" ]),
198+  ),
199+  )
200+ 
201+  def  test_contains (self ):
202+  self .assertCountEqual (Book .objects .filter (author__skills__contains = ["nonexistent" ]), [])
203+  self .assertCountEqual (
204+  Book .objects .filter (author__skills__contains = ["writing" ]), [self .book ]
205+  )
206+  # Nested 
207+  self .assertCountEqual (
208+  Book .objects .filter (author__address__tags__contains = ["nonexistent" ]), []
209+  )
210+  self .assertCountEqual (
211+  Book .objects .filter (author__address__tags__contains = ["home" ]), [self .book ]
212+  )
213+ 
214+  def  test_contained_by (self ):
215+  self .assertCountEqual (
216+  Book .objects .filter (author__skills__contained_by = ["writing" , "publishing" ]), []
217+  )
218+  self .assertCountEqual (
219+  Book .objects .filter (author__skills__contained_by = ["writing" , "editing" , "publishing" ]),
220+  [self .book ],
221+  )
222+  # Nested 
223+  self .assertCountEqual (
224+  Book .objects .filter (author__address__tags__contained_by = ["home" , "work" ]), []
225+  )
226+  self .assertCountEqual (
227+  Book .objects .filter (author__address__tags__contained_by = ["home" , "work" , "shipping" ]),
228+  [self .book ],
229+  )
230+ 
231+ 
189232class  InvalidLookupTests (SimpleTestCase ):
190233 def  test_invalid_field (self ):
191234 msg  =  "Author has no field named 'first_name'" 
0 commit comments