@@ -166,11 +166,38 @@ def test_filter_relationship_one_to_many(session):
166
166
add_test_data (session )
167
167
Query = create_schema (session )
168
168
169
+ # test contains
169
170
query = """
170
171
query {
171
172
reporter (filters: {
172
173
pets: {
173
- name: {in: ["Garfield", "Snoopy"]}
174
+ contains: {
175
+ name: {in: ["Garfield", "Lassie"]}
176
+ }
177
+ }
178
+ }) {
179
+ lastName
180
+ }
181
+ }
182
+ """
183
+ expected = {
184
+ "reporter" : [{"lastName" : "Doe" }, {"lastName" : "Roe" }],
185
+ }
186
+ schema = graphene .Schema (query = Query )
187
+ result = schema .execute (query )
188
+ assert not result .errors
189
+ result = to_std_dicts (result .data )
190
+ assert result == expected
191
+
192
+ # test containsAllOf
193
+ query = """
194
+ query {
195
+ reporter (filters: {
196
+ pets: {
197
+ containsAllOf: [
198
+ name: {eq: "Garfield"},
199
+ name: {eq: "Snoopy"},
200
+ ]
174
201
}
175
202
}) {
176
203
firstName
@@ -187,6 +214,28 @@ def test_filter_relationship_one_to_many(session):
187
214
result = to_std_dicts (result .data )
188
215
assert result == expected
189
216
217
+ # test containsExactly
218
+ query = """
219
+ query {
220
+ reporter (filters: {
221
+ pets: {
222
+ containsExactly: [
223
+ name: {eq: "Garfield"}
224
+ ]
225
+ }
226
+ }) {
227
+ firstName
228
+ }
229
+ }
230
+ """
231
+ expected = {
232
+ "reporter" : [],
233
+ }
234
+ schema = graphene .Schema (query = Query )
235
+ result = schema .execute (query )
236
+ assert not result .errors
237
+ result = to_std_dicts (result .data )
238
+ assert result == expected
190
239
191
240
# Test a n:m relationship
192
241
def test_filter_relationship_many_to_many (session ):
@@ -204,10 +253,42 @@ def test_filter_relationship_many_to_many(session):
204
253
205
254
Query = create_schema (session )
206
255
256
+ # test contains
257
+ query = """
258
+ query {
259
+ articles (filters: {
260
+ tags: {
261
+ contains: {
262
+ name: { in: ["sensational", "eye-grabbing"] }
263
+ }
264
+ }
265
+ }) {
266
+ headline
267
+ }
268
+ }
269
+ """
270
+ expected = {
271
+ "articles" : [
272
+ {"headline" : "Woah! Another!" },
273
+ {"headline" : "Article! Look!" },
274
+ ],
275
+ }
276
+ schema = graphene .Schema (query = Query )
277
+ result = schema .execute (query )
278
+ assert not result .errors
279
+ result = to_std_dicts (result .data )
280
+ assert result == expected
281
+
282
+ # test containsAllOf
207
283
query = """
208
284
query {
209
285
articles (filters: {
210
- tags: { name: { in: ["sensational", "eye-grabbing"] } }
286
+ tags: {
287
+ containsAllOf: [
288
+ { tag: { name: { eq: "eye-grabbing" } } },
289
+ { tag: { name: { eq: "sensational" } } },
290
+ ]
291
+ }
211
292
}) {
212
293
headline
213
294
}
@@ -222,6 +303,27 @@ def test_filter_relationship_many_to_many(session):
222
303
result = to_std_dicts (result .data )
223
304
assert result == expected
224
305
306
+ # test containsExactly
307
+ query = """
308
+ query {
309
+ articles (filters: {
310
+ containsExactly: [
311
+ { tag: { name: { eq: "sensational" } } }
312
+ ]
313
+ }) {
314
+ headline
315
+ }
316
+ }
317
+ """
318
+ expected = {
319
+ "articles" : [{"headline" : "Article! Look!" }],
320
+ }
321
+ schema = graphene .Schema (query = Query )
322
+ result = schema .execute (query )
323
+ assert not result .errors
324
+ result = to_std_dicts (result .data )
325
+ assert result == expected
326
+
225
327
226
328
# Test connecting filters with "and"
227
329
def test_filter_logic_and (session ):
0 commit comments