@@ -102,6 +102,56 @@ def test_pre_save(self):
102
102
self .assertGreater (obj .data .auto_now , auto_now_two )
103
103
104
104
105
+ class ArrayFieldTests (TestCase ):
106
+ @classmethod
107
+ def setUpTestData (cls ):
108
+ cls .book = Book .objects .create (
109
+ author = Author (
110
+ name = "Shakespeare" ,
111
+ age = 55 ,
112
+ skills = ["writing" , "editing" ],
113
+ address = Address (city = "NYC" , state = "NY" , tags = ["home" , "shipping" ]),
114
+ ),
115
+ )
116
+
117
+ def test_contains (self ):
118
+ self .assertCountEqual (Book .objects .filter (author__skills__contains = ["nonexistent" ]), [])
119
+ self .assertCountEqual (
120
+ Book .objects .filter (author__skills__contains = ["writing" ]), [self .book ]
121
+ )
122
+ # Nested
123
+ self .assertCountEqual (
124
+ Book .objects .filter (author__address__tags__contains = ["nonexistent" ]), []
125
+ )
126
+ self .assertCountEqual (
127
+ Book .objects .filter (author__address__tags__contains = ["home" ]), [self .book ]
128
+ )
129
+
130
+ def test_contained_by (self ):
131
+ self .assertCountEqual (
132
+ Book .objects .filter (author__skills__contained_by = ["writing" , "publishing" ]), []
133
+ )
134
+ self .assertCountEqual (
135
+ Book .objects .filter (author__skills__contained_by = ["writing" , "editing" , "publishing" ]),
136
+ [self .book ],
137
+ )
138
+ # Nested
139
+ self .assertCountEqual (
140
+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" ]), []
141
+ )
142
+ self .assertCountEqual (
143
+ Book .objects .filter (author__address__tags__contained_by = ["home" , "work" , "shipping" ]),
144
+ [self .book ],
145
+ )
146
+
147
+ def test_len (self ):
148
+ self .assertCountEqual (Book .objects .filter (author__skills__len = 1 ), [])
149
+ self .assertCountEqual (Book .objects .filter (author__skills__len = 2 ), [self .book ])
150
+ # Nested
151
+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 1 ), [])
152
+ self .assertCountEqual (Book .objects .filter (author__address__tags__len = 2 ), [self .book ])
153
+
154
+
105
155
class EmbeddedArrayTests (TestCase ):
106
156
def test_save_load (self ):
107
157
reviews = [
0 commit comments