@@ -101,6 +101,56 @@ def test_pre_save(self):
101
101
self .assertGreater (obj .data .auto_now , auto_now_two )
102
102
103
103
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
+
104
154
class EmbeddedArrayTests (TestCase ):
105
155
def test_save_load (self ):
106
156
reviews = [
0 commit comments