Skip to content

Commit e655b21

Browse files
committed
update 1:n and n:m filter tests to use RelationshipFilter syntax
1 parent 9aae6c7 commit e655b21

File tree

1 file changed

+104
-2
lines changed

1 file changed

+104
-2
lines changed

graphene_sqlalchemy/tests/test_filters.py

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,38 @@ def test_filter_relationship_one_to_many(session):
166166
add_test_data(session)
167167
Query = create_schema(session)
168168

169+
# test contains
169170
query = """
170171
query {
171172
reporter (filters: {
172173
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+
]
174201
}
175202
}) {
176203
firstName
@@ -187,6 +214,28 @@ def test_filter_relationship_one_to_many(session):
187214
result = to_std_dicts(result.data)
188215
assert result == expected
189216

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
190239

191240
# Test a n:m relationship
192241
def test_filter_relationship_many_to_many(session):
@@ -204,10 +253,42 @@ def test_filter_relationship_many_to_many(session):
204253

205254
Query = create_schema(session)
206255

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
207283
query = """
208284
query {
209285
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+
}
211292
}) {
212293
headline
213294
}
@@ -222,6 +303,27 @@ def test_filter_relationship_many_to_many(session):
222303
result = to_std_dicts(result.data)
223304
assert result == expected
224305

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+
225327

226328
# Test connecting filters with "and"
227329
def test_filter_logic_and(session):

0 commit comments

Comments
 (0)