@@ -103,6 +103,56 @@ 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+
106156class EmbeddedArrayTests (TestCase ):
107157 def test_save_load (self ):
108158 reviews = [
0 commit comments