code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
182
url
stringlengths
46
251
license
stringclasses
4 values
async def test_edgeql_select_polymorphic_08(self): await self.assert_query_result( r''' SELECT Object { [IS Status | Priority].name, } ORDER BY .name; ''', [ {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': 'Closed'}, {'name': 'High'}, {'name': 'Low'}, {'name': 'Open'} ], ) await self.assert_query_result( r''' # the above should be equivalent to this: SELECT Object { name := Object[IS Status].name ?? Object[IS Priority].name, } ORDER BY .name; ''', [ {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': 'Closed'}, {'name': 'High'}, {'name': 'Low'}, {'name': 'Open'} ], )
, [ {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': None}, {'name': 'Closed'}, {'name': 'High'}, {'name': 'Low'}, {'name': 'Open'} ], ) await self.assert_query_result( r
test_edgeql_select_polymorphic_08
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_polymorphic_10(self): await self.assert_query_result( r''' SELECT count(Object[IS Named][IS Text]) != count(Object[IS Text]); ''', [True] ) await self.assert_query_result( r''' SELECT count(User.<owner[IS Named][IS Text]) != count(User.<owner[IS Text]); ''', [True] )
, [True] ) await self.assert_query_result( r
test_edgeql_select_polymorphic_10
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_splat_05(self): # Polymorphic splat conflicts res = [ { "id": str, "name": "Elvis", "body": None, "due_date": None, "number": None, "start_date": None, "tags": None, "time_estimate": None, }, { "id": str, "name": "Release EdgeDB", "body": "Initial public release of EdgeDB.", "due_date": None, "number": "1", "start_date": str, "tags": None, "time_estimate": 3000, }, ] await self.assert_query_result( r''' select Named { *, [is Issue].* } filter .name in {'Elvis', 'Release EdgeDB'} order by .name; ''', res, ) await self.assert_query_result( r''' select Named { [is Issue].*, * } filter .name in {'Elvis', 'Release EdgeDB'} order by .name; ''', res, ) await self.assert_query_result( r''' select {Issue, User} { [is Issue].*, * } filter .name in {'Elvis', 'Release EdgeDB'} order by .name; ''', res, ) await self.assert_query_result( r''' select {Issue, User} { *, [is Issue].* } filter .name in {'Elvis', 'Release EdgeDB'} order by .name; ''', res, ) await self.assert_query_result( r''' select Object { [is Named].*, [is Issue].* } filter .name in {'Elvis', 'Release EdgeDB'} order by .name; ''', res ) await self.assert_query_result( r''' select Object { [is Issue].*, [is Named].* } filter .name in {'Elvis', 'Release EdgeDB'} order by .name; ''', res ) # TODO: Ideally this would work with self.assertRaisesRegex( edgedb.QueryError, "appears in splats for unrelated types", ): await self.con.execute(''' select Object { [is User].*, [is Issue].* } filter .name in {'Elvis', 'Release EdgeDB'} order by .name; ''')
, res, ) await self.assert_query_result( r
test_edgeql_select_splat_05
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_reverse_link_02(self): await self.assert_query_result( r''' SELECT User.<owner[IS Issue]@since ''', ['2018-01-01T00:00:00+00:00'], ) await self.assert_query_result( r''' SELECT User.<owner[IS Named]@since ''', ['2018-01-01T00:00:00+00:00'], )
, ['2018-01-01T00:00:00+00:00'], ) await self.assert_query_result( r
test_edgeql_select_reverse_link_02
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_setops_02(self): await self.assert_query_result( r''' WITH Obj := (SELECT Issue UNION Comment) SELECT Obj { [IS Issue].name, [IS Text].body }; ''', tb.bag([ {'body': 'EdgeDB needs to happen soon.'}, {'body': 'Fix regression introduced by lexer tweak.'}, {'body': 'Initial public release of EdgeDB.'}, {'body': 'Minor lexer tweaks.'}, {'body': 'We need to be able to render ' 'data in tabular format.'} ]), ) await self.assert_query_result( r''' # XXX: I think we should be able to drop [IS Text] from # the query below. WITH Obj := (SELECT Issue UNION Comment) SELECT Obj[IS Text] { id, body } ORDER BY Obj[IS Text].body; ''', [ {'body': 'EdgeDB needs to happen soon.'}, {'body': 'Fix regression introduced by lexer tweak.'}, {'body': 'Initial public release of EdgeDB.'}, {'body': 'Minor lexer tweaks.'}, {'body': 'We need to be able to render ' 'data in tabular format.'} ], )
, tb.bag([ {'body': 'EdgeDB needs to happen soon.'}, {'body': 'Fix regression introduced by lexer tweak.'}, {'body': 'Initial public release of EdgeDB.'}, {'body': 'Minor lexer tweaks.'}, {'body': 'We need to be able to render ' 'data in tabular format.'} ]), ) await self.assert_query_result( r
test_edgeql_select_setops_02
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_setops_19(self): await self.assert_query_result( r""" # UNION between Issue and empty set Issue should be # duck-typed to be effectively equivalent to Issue[IS # Issue], which is just an Issue. SELECT (Issue UNION <Issue>{}).name; """, { 'Release EdgeDB', 'Improve EdgeDB repl output rendering.', 'Repl tweak.', 'Regression.', }, ) await self.assert_query_result( r""" SELECT (Issue UNION <Issue>{}).number; """, {'1', '2', '3', '4'}, )
, { 'Release EdgeDB', 'Improve EdgeDB repl output rendering.', 'Repl tweak.', 'Regression.', }, ) await self.assert_query_result( r
test_edgeql_select_setops_19
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_setops_23(self): await self.assert_query_result( r""" WITH X := (insert Publication { title := "x" }), Y := (insert Publication { title := "y" }), foo := X union Y, select foo { title1 }; """, tb.bag([ {'title1': 'x'}, {'title1': 'y'}, ]) ) await self.assert_query_result( r""" WITH X := (select Publication filter .title = 'x'), Y := (select Publication filter .title = 'y'), foo := X union Y, select foo { title1 }; """, tb.bag([ {'title1': 'x'}, {'title1': 'y'}, ]) ) await self.assert_query_result( r""" SELECT (Issue UNION <Issue>{}).number; """, {'1', '2', '3', '4'}, )
, tb.bag([ {'title1': 'x'}, {'title1': 'y'}, ]) ) await self.assert_query_result( r
test_edgeql_select_setops_23
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_setops_24(self): # Establish that EXCEPT and INTERSECT filter out the objects we'd # expect. await self.assert_query_result( r""" with A := Owned except {LogEntry, Comment} select all(A in Issue) and all(Issue in A) """, { True }, ) await self.assert_query_result( r""" with A := Owned intersect Issue select all(A in Owned[is Issue]) and all(Owned[is Issue] in A) """, { True }, )
, { True }, ) await self.assert_query_result( r
test_edgeql_select_setops_24
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_setops_25(self): # Establish that EXCEPT and INTERSECT filter out the objects we'd # expect. await self.assert_query_result( r""" with A := (select Issue filter .name ilike '%edgedb%'), B := (select Issue filter .owner.name = 'Elvis') select (B except A) {name}; """, [ {'name': 'Regression.'}, ], ) await self.assert_query_result( r""" with A := (select Issue filter .name ilike '%edgedb%'), B := (select Issue filter .owner.name = 'Elvis') select (B intersect A) {name}; """, [ {'name': 'Release EdgeDB'}, ], )
, [ {'name': 'Regression.'}, ], ) await self.assert_query_result( r
test_edgeql_select_setops_25
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_setops_27(self): await self.assert_query_result( r""" with A := (select Issue filter .name not ilike '%edgedb%').body select _ := str_lower(array_unpack(str_split(A, ' '))) except {'minor', 'fix', 'lexer'} order by _ """, [ "by", "introduced", "lexer", "regression", "tweak.", "tweaks.", ], ) await self.assert_query_result( r""" with A := (select Issue filter .name not ilike '%edgedb%') select _ := str_lower(array_unpack(str_split(A.body, ' '))) except str_lower(array_unpack(str_split(A.name, ' '))) order by _ """, [ "by", "fix", "introduced", "lexer", "lexer", "minor", "regression", "tweaks.", ], )
, [ "by", "introduced", "lexer", "regression", "tweak.", "tweaks.", ], ) await self.assert_query_result( r
test_edgeql_select_setops_27
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_setops_28(self): await self.assert_query_result( r""" select _ := len(array_unpack(str_split(Issue.body, ' '))) intersect {1, 2, 2, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7} order by _ """, [ 2, 2, 3, 7, 7, 7, 7, 7, 7 ], ) await self.assert_query_result( r""" select _ := str_lower(array_unpack(str_split(Issue.name, ' '))) except str_lower(array_unpack(str_split(Issue.body, ' '))) order by _ """, [ "edgedb", "edgedb", "improve", "output", "regression.", "rendering.", "repl", "repl", ], )
, [ 2, 2, 3, 7, 7, 7, 7, 7, 7 ], ) await self.assert_query_result( r
test_edgeql_select_setops_28
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_order_01(self): await self.assert_query_result( r''' SELECT Issue {name} ORDER BY Issue.priority.name ASC EMPTY LAST THEN Issue.name; ''', [ {'name': 'Improve EdgeDB repl output rendering.'}, {'name': 'Repl tweak.'}, {'name': 'Regression.'}, {'name': 'Release EdgeDB'}, ], ) await self.assert_query_result( r''' SELECT Issue {name} ORDER BY Issue.priority.name ASC EMPTY FIRST THEN Issue.name; ''', [ {'name': 'Regression.'}, {'name': 'Release EdgeDB'}, {'name': 'Improve EdgeDB repl output rendering.'}, {'name': 'Repl tweak.'}, ] )
, [ {'name': 'Improve EdgeDB repl output rendering.'}, {'name': 'Repl tweak.'}, {'name': 'Regression.'}, {'name': 'Release EdgeDB'}, ], ) await self.assert_query_result( r
test_edgeql_select_order_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_coalesce_03(self): issues_h = await self.con.query(r''' SELECT Issue{number} FILTER Issue.priority.name = 'High' ORDER BY Issue.number; ''') issues_n = await self.con.query(r''' SELECT Issue{number} FILTER NOT EXISTS Issue.priority ORDER BY Issue.number; ''') await self.assert_query_result( r''' SELECT Issue{number} FILTER Issue.priority.name ?? 'High' = 'High' ORDER BY Issue.priority.name EMPTY LAST THEN Issue.number; ''', [{'number': o.number} for o in [*issues_h, *issues_n]] )
) issues_n = await self.con.query(r
test_edgeql_select_coalesce_03
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_or_01(self): issues_h = await self.con.query(r''' SELECT Issue{number} FILTER Issue.priority.name = 'High' ORDER BY Issue.number; ''') issues_l = await self.con.query(r''' SELECT Issue{number} FILTER Issue.priority.name = 'Low' ORDER BY Issue.number; ''') # XXX(factor): need to follow multiple steps in warn analysis await self.assert_query_result( r''' SELECT Issue{number} FILTER Issue.priority.name = 'High' OR Issue.priority.name = 'Low' ORDER BY Issue.priority.name THEN Issue.number; ''', [{'number': o.number} for o in [*issues_h, *issues_l]] )
) issues_l = await self.con.query(r
test_edgeql_select_or_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_or_04(self): # XXX(factor): need to follow multiple steps in warn analysis await self.assert_query_result( r''' SELECT Issue{number} FILTER Issue.priority.name = 'High' OR Issue.status.name = 'Closed' ORDER BY Issue.number; ''', [{'number': '2'}, {'number': '3'}], ) await self.assert_query_result( r''' SELECT Issue{number} FILTER Issue.priority.name = 'High' OR Issue.priority.name = 'Low' OR Issue.status.name = 'Closed' ORDER BY Issue.number; ''', # it so happens that all low priority issues are also closed [{'number': '2'}, {'number': '3'}], ) await self.assert_query_result( r''' SELECT Issue{number} FILTER Issue.priority.name IN {'High', 'Low'} OR Issue.status.name = 'Closed' ORDER BY Issue.number; ''', [{'number': '2'}, {'number': '3'}], )
, [{'number': '2'}, {'number': '3'}], ) await self.assert_query_result( r
test_edgeql_select_or_04
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_or_05(self): await self.assert_query_result( r''' SELECT Issue{number} FILTER NOT EXISTS Issue.priority.id OR Issue.status.name = 'Closed' ORDER BY Issue.number; ''', [{'number': '1'}, {'number': '3'}, {'number': '4'}], ) await self.assert_query_result( r''' # should be identical SELECT Issue{number} FILTER NOT EXISTS Issue.priority OR Issue.status.name = 'Closed' ORDER BY Issue.number; ''', [{'number': '1'}, {'number': '3'}, {'number': '4'}], )
, [{'number': '1'}, {'number': '3'}, {'number': '4'}], ) await self.assert_query_result( r
test_edgeql_select_or_05
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_not_01(self): await self.assert_query_result( r''' SELECT Issue{number} FILTER NOT Issue.priority.name = 'High' ORDER BY Issue.number; ''', [{'number': '3'}], ) await self.assert_query_result( r''' SELECT Issue{number} FILTER Issue.priority.name != 'High' ORDER BY Issue.number; ''', [{'number': '3'}], )
, [{'number': '3'}], ) await self.assert_query_result( r
test_edgeql_select_not_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_not_04(self): # testing double negation await self.assert_query_result( r''' select BooleanTest { name, val, x := not (.val < 5) } order by .name; ''', [ {'name': 'circle', 'val': 2, 'x': False}, {'name': 'hexagon', 'val': 4, 'x': False}, {'name': 'pentagon', 'val': None, 'x': None}, {'name': 'square', 'val': None, 'x': None}, {'name': 'triangle', 'val': 10, 'x': True}, ], ) await self.assert_query_result( r''' select BooleanTest { name, val, x := not not (.val < 5) } order by .name; ''', [ {'name': 'circle', 'val': 2, 'x': True}, {'name': 'hexagon', 'val': 4, 'x': True}, {'name': 'pentagon', 'val': None, 'x': None}, {'name': 'square', 'val': None, 'x': None}, {'name': 'triangle', 'val': 10, 'x': False}, ], )
, [ {'name': 'circle', 'val': 2, 'x': False}, {'name': 'hexagon', 'val': 4, 'x': False}, {'name': 'pentagon', 'val': None, 'x': None}, {'name': 'square', 'val': None, 'x': None}, {'name': 'triangle', 'val': 10, 'x': True}, ], ) await self.assert_query_result( r
test_edgeql_select_not_04
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_not_05(self): # testing double negation await self.assert_query_result( r''' select BooleanTest { name, tags, x := (select _ := not (.tags = 'red') order by _) } order by .name; ''', [{ 'name': 'circle', 'tags': {'red', 'black'}, 'x': [False, True], }, { 'name': 'hexagon', 'tags': [], 'x': [], }, { 'name': 'pentagon', 'tags': [], 'x': [], }, { 'name': 'square', 'tags': {'red'}, 'x': [False], }, { 'name': 'triangle', 'tags': {'red', 'green'}, 'x': [False, True], }], ) await self.assert_query_result( r''' select BooleanTest { name, tags, x := (select _ := not not (.tags = 'red') order by _) } order by .name; ''', [{ 'name': 'circle', 'tags': {'red', 'black'}, 'x': [False, True], }, { 'name': 'hexagon', 'tags': [], 'x': [], }, { 'name': 'pentagon', 'tags': [], 'x': [], }, { 'name': 'square', 'tags': {'red'}, 'x': [True], }, { 'name': 'triangle', 'tags': {'red', 'green'}, 'x': [False, True], }], )
, [{ 'name': 'circle', 'tags': {'red', 'black'}, 'x': [False, True], }, { 'name': 'hexagon', 'tags': [], 'x': [], }, { 'name': 'pentagon', 'tags': [], 'x': [], }, { 'name': 'square', 'tags': {'red'}, 'x': [False], }, { 'name': 'triangle', 'tags': {'red', 'green'}, 'x': [False, True], }], ) await self.assert_query_result( r
test_edgeql_select_not_05
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_empty_03(self): await self.assert_query_result( r""" # Test short-circuiting operations with empty SELECT count(Issue.number = '1' OR <bool>{}); """, [0], ) await self.assert_query_result( r""" SELECT count(Issue.number = 'X' OR <bool>{}); """, [0], ) await self.assert_query_result( r""" SELECT count(Issue.number = '1' AND <bool>{}); """, [0], ) await self.assert_query_result( r""" SELECT count(Issue.number = 'X' AND <bool>{}); """, [0], )
, [0], ) await self.assert_query_result( r
test_edgeql_select_empty_03
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_cross_07(self): await self.assert_query_result( r""" SELECT _ := count(Issue.owner.name ++ Issue.watchers.name); """, [3], ) await self.assert_query_result( r""" SELECT _ := count(DISTINCT ( Issue.owner.name ++ Issue.watchers.name)); """, [2], )
, [3], ) await self.assert_query_result( r
test_edgeql_select_cross_07
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_cross_13(self): await self.assert_query_result( r""" SELECT count(count(Issue.watchers)); """, [1], ) await self.assert_query_result( r""" SELECT count( (Issue, count(Issue.watchers)) ); """, [4], )
, [1], ) await self.assert_query_result( r
test_edgeql_select_cross_13
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_subqueries_11(self): await self.assert_query_result( r""" SELECT Text{ [IS Issue].number, body_length := len(Text.body) } ORDER BY len(Text.body); """, [ {'number': '3', 'body_length': 19}, {'number': None, 'body_length': 21}, {'number': None, 'body_length': 28}, {'number': '1', 'body_length': 33}, {'number': '4', 'body_length': 41}, {'number': '2', 'body_length': 52}, ], ) await self.assert_query_result( r""" # find all issues such that there's at least one more # Text item of similar body length (+/-5 characters) SELECT Issue{ number, } FILTER EXISTS ( SELECT Text FILTER Text != Issue AND (len(Text.body) - len(Issue.body)) ^ 2 <= 25 ) ORDER BY Issue.number; """, [{'number': '1'}, {'number': '3'}], )
, [ {'number': '3', 'body_length': 19}, {'number': None, 'body_length': 21}, {'number': None, 'body_length': 28}, {'number': '1', 'body_length': 33}, {'number': '4', 'body_length': 41}, {'number': '2', 'body_length': 52}, ], ) await self.assert_query_result( r
test_edgeql_select_subqueries_11
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_subqueries_18(self): await self.assert_query_result( r""" # here, DETACHED doesn't do anything special, because the # symbol U2 is reused on both sides of '+' WITH U2 := DETACHED User SELECT U2.name ++ U2.name; """, {'ElvisElvis', 'YuryYury'}, ) await self.assert_query_result( r""" # DETACHED is reused on both sides of '+' directly SELECT (DETACHED User).name ++ (DETACHED User).name; """, {'ElvisElvis', 'ElvisYury', 'YuryElvis', 'YuryYury'}, )
, {'ElvisElvis', 'YuryYury'}, ) await self.assert_query_result( r
test_edgeql_select_subqueries_18
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_slice_01(self): await self.assert_query_result( r""" # full name of the Issue is 'Release EdgeDB' SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[2]; """, ['l'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[-2]; """, ['D'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[2:4]; """, ['le'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[2:]; """, ['lease EdgeDB'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[:2]; """, ['Re'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[2:-1]; """, ['lease EdgeD'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[-2:]; """, ['DB'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).name[:-2]; """, ['Release Edge'], )
, ['l'], ) await self.assert_query_result( r
test_edgeql_select_slice_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_slice_02(self): await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name; """, ['default::Issue'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[2]; """, ['f'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[-2]; """, ['u'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[2:4]; """, ['fa'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[2:]; """, ['fault::Issue'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[:2]; """, ['de'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[2:-1]; """, ['fault::Issu'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[-2:]; """, ['ue'], ) await self.assert_query_result( r""" SELECT ( SELECT Issue FILTER Issue.number = '1' ).__type__.name[:-2]; """, ['default::Iss'], )
, ['default::Issue'], ) await self.assert_query_result( r
test_edgeql_select_slice_02
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_slice_04(self): await self.assert_query_result( r""" select [1,2,3,4,5][1:]; """, [[2, 3, 4, 5]], ) await self.assert_query_result( r""" select [1,2,3,4,5][:3]; """, [[1, 2, 3]], ) await self.assert_query_result( r""" select [1,2,3][1:<int64>{}]; """, [], ) # try to trick the compiler and to pass NULL into edgedb._slice await self.assert_query_result( r""" select [1,2,3][1:<optional int64>$0]; """, [], variables=(None,), ) await self.assert_query_result( r""" select [1,2,3][<optional int64>$0:2]; """, [], variables=(None,), ) await self.assert_query_result( r""" select [1,2,3][<optional int64>$0:<optional int64>$1]; """, [], variables=( None, None, ), ) self.assertEqual( await self.con.query( r""" select to_json('[true, 3, 4, null]')[1:]; """ ), edgedb.Set(('[3, 4, null]',)), ) self.assertEqual( await self.con.query( r""" select to_json('[true, 3, 4, null]')[:2]; """ ), edgedb.Set(('[true, 3]',)), ) await self.assert_query_result( r""" select (<optional json>$0)[2:]; """, [], variables=(None,), ) self.assertEqual( await self.con.query( r""" select to_json('"hello world"')[2:]; """ ), edgedb.Set(('"llo world"',)), ) self.assertEqual( await self.con.query( r""" select to_json('"hello world"')[:4]; """ ), edgedb.Set(('"hell"',)), ) await self.assert_query_result( r""" select (<array<str>>[])[0:]; """, [[]], ) await self.assert_query_result( r'''select to_json('[]')[0:];''', # JSON: [[]], # Binary: ['[]'], ) await self.assert_query_result( r'''select [(1,'foo'), (2,'bar'), (3,'baz')][1:];''', [[(2, 'bar'), (3, 'baz')]], ) await self.assert_query_result( r'''select [(1,'foo'), (2,'bar'), (3,'baz')][:2];''', [[(1, 'foo'), (2, 'bar')]], ) await self.assert_query_result( r'''select [(1,'foo'), (2,'bar'), (3,'baz')][1:2];''', [[(2, 'bar')]], ) await self.assert_query_result( r''' select [(1,'foo'), (2,'bar'), (3,'baz')][<optional int32>$0:]; ''', [], variables=(None,), ) await self.assert_query_result( r''' select (<optional array<int32>>$0)[2]; ''', [], variables=(None,), ) await self.assert_query_result( r''' select (<optional str>$0)[2]; ''', [], variables=(None,), ) await self.assert_query_result( r''' select to_json(<optional str>$0)[2]; ''', [], variables=(None,), ) await self.assert_query_result( r''' select (<optional array<int32>>$0)[1:2]; ''', [], variables=(None,), ) await self.assert_query_result( r''' select (<optional str>$0)[1:2]; ''', [], variables=(None,), ) await self.assert_query_result( r''' select to_json(<optional str>$0)[1:2]; ''', [], variables=(None,), )
, [[2, 3, 4, 5]], ) await self.assert_query_result( r
test_edgeql_select_slice_04
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_if_else_04(self): await self.assert_query_result( r""" SELECT Issue{ kind := (Issue.priority.name IF EXISTS Issue.priority.name ELSE Issue.status.name) } ORDER BY Issue.number; """, [{'kind': 'Open'}, {'kind': 'High'}, {'kind': 'Low'}, {'kind': 'Closed'}], ) await self.assert_query_result( r""" # Above IF is equivalent to ??, SELECT Issue{ kind := Issue.priority.name ?? Issue.status.name } ORDER BY Issue.number; """, [{'kind': 'Open'}, {'kind': 'High'}, {'kind': 'Low'}, {'kind': 'Closed'}], )
, [{'kind': 'Open'}, {'kind': 'High'}, {'kind': 'Low'}, {'kind': 'Closed'}], ) await self.assert_query_result( r
test_edgeql_select_if_else_04
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_if_else_05(self): await self.assert_query_result( r""" SELECT Issue {number} FILTER Issue.priority.name = 'High' IF EXISTS Issue.priority.name AND EXISTS 'High' ELSE EXISTS Issue.priority.name = EXISTS 'High' ORDER BY Issue.number; """, [{'number': '2'}], ) await self.assert_query_result( r""" # Above IF is equivalent to ?=, SELECT Issue {number} FILTER Issue.priority.name ?= 'High' ORDER BY Issue.number; """, [{'number': '2'}], )
, [{'number': '2'}], ) await self.assert_query_result( r
test_edgeql_select_if_else_05
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_union_target_01(self): await self.assert_query_result( r''' SELECT Issue { number, } FILTER EXISTS (.references) ORDER BY .number DESC; ''', [{ 'number': '2' }], ) await self.assert_query_result( r''' SELECT Issue { number, } FILTER .references[IS URL].address = 'https://edgedb.com' ORDER BY .number DESC; ''', [{ 'number': '2' }], ) await self.assert_query_result( r''' SELECT Issue { number, } FILTER .references[IS Named].name = 'screenshot.png' ORDER BY .number DESC; ''', [{ 'number': '2' }], ) await self.assert_query_result( r''' SELECT Issue { number, references[IS Named]: { __type__: { name }, name } ORDER BY .name } FILTER EXISTS (.references) ORDER BY .number DESC; ''', [{ 'number': '2', 'references': [ { 'name': 'edgedb.com', '__type__': { 'name': 'default::URL' } }, { 'name': 'screenshot.png', '__type__': { 'name': 'default::File' } } ] }] )
, [{ 'number': '2' }], ) await self.assert_query_result( r
test_edgeql_union_target_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_bad_reference_05(self): with self.assertRaisesRegex( edgedb.QueryError, "object type 'default::Issue' has no link or property 'referrnce'", _hint="did you mean 'references'?", ): await self.con.query( """ select Issue filter .referrnce = '#4418'; """ )
select Issue filter .referrnce = '#4418';
test_edgeql_select_bad_reference_05
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_precedence_03(self): await self.assert_query_result( r''' SELECT (<str>1)[0]; ''', ['1'], ) await self.assert_query_result( r''' SELECT (<str>Issue.time_estimate)[0]; ''', ['3'], )
, ['1'], ) await self.assert_query_result( r
test_edgeql_select_precedence_03
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_is_incompatible_union_01(self): await self.con.execute(''' CREATE TYPE Dummy1 { CREATE PROPERTY foo -> int64; }; CREATE TYPE Dummy2 { CREATE PROPERTY foo -> str; }; ''') with self.assertRaisesRegex( edgedb.SchemaError, r"cannot create union \(default::Dummy1 \| default::Dummy2\) " r"with property 'foo' using incompatible types std::int64, " r"std::str"): await self.con.query( r''' SELECT Object is Dummy1 | Dummy2; ''', )
) with self.assertRaisesRegex( edgedb.SchemaError, r"cannot create union \(default::Dummy1 \| default::Dummy2\) " r"with property 'foo' using incompatible types std::int64, " r"std::str"): await self.con.query( r
test_edgeql_select_is_incompatible_union_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_expr_objects_03(self): await self.con.execute( ''' CREATE FUNCTION issues() -> SET OF Issue USING (Issue); ''' ) await self.assert_query_result( r''' SELECT _ := issues().owner.name ORDER BY _; ''', ["Elvis", "Yury"], )
CREATE FUNCTION issues() -> SET OF Issue USING (Issue);
test_edgeql_select_expr_objects_03
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_expr_objects_07(self): # get the User names and ids res = await self.con.query(r''' SELECT User { name, id } ORDER BY User.name; ''') # we want to make sure that the reference to L is actually # populated with 'id', since there was a bug in which in JSON # mode it was populated with 'name' instead! await self.assert_query_result( r''' WITH L := ('x', User), SELECT _ := (L, L.1 {name}) ORDER BY _.1.name; ''', [ [['x', {'id': str(user.id)}], {'name': user.name}] for user in res ] ) await self.assert_query_result( r''' WITH L := ('x', User), SELECT _ := (L.1 {name}, L) ORDER BY _.0.name; ''', [ [{'name': user.name}, ['x', {'id': str(user.id)}]] for user in res ] )
) # we want to make sure that the reference to L is actually # populated with 'id', since there was a bug in which in JSON # mode it was populated with 'name' instead! await self.assert_query_result( r
test_edgeql_select_expr_objects_07
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_expr_objects_08(self): await self.assert_query_result( r''' SELECT DISTINCT [(SELECT Issue {number, name} FILTER .number = "1")]; ''', [ [{'number': '1', 'name': 'Release EdgeDB'}], ] ) await self.assert_query_result( r''' SELECT DISTINCT ((SELECT Issue {number, name} FILTER .number = "1"), Issue.status.name); ''', [ [{'number': '1', 'name': 'Release EdgeDB'}, "Open"], ] )
, [ [{'number': '1', 'name': 'Release EdgeDB'}], ] ) await self.assert_query_result( r
test_edgeql_select_expr_objects_08
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_banned_free_shape_01(self): async with self.assertRaisesRegexTx( edgedb.QueryError, "it is illegal to create a type union that causes a " "computed property 'z' to mix with other versions of the " "same property 'z'" ): await self.con.execute(""" SELECT DISTINCT {{ z := 1 }, { z := 2 }}; """) async with self.assertRaisesRegexTx( edgedb.QueryError, "cannot use DISTINCT on free shape", ): await self.con.execute(""" SELECT DISTINCT { z := 1 } = { z := 2 }; """)
) async with self.assertRaisesRegexTx( edgedb.QueryError, "cannot use DISTINCT on free shape", ): await self.con.execute(
test_edgeql_select_banned_free_shape_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_reverse_overload_03(self): await self.con.execute(''' CREATE TYPE Dummy1 { CREATE LINK whatever -> User; }; CREATE TYPE Dummy2 { CREATE LINK whatever := (SELECT User FILTER .name = 'Elvis'); }; INSERT Dummy1 { whatever := (SELECT User FILTER .name = 'Yury') }; ''') # We should be able to query the whatever backlink as long as we # filter it properly await self.assert_query_result( r''' SELECT User.<whatever[IS Dummy1]; ''', [{}], ) with self.assertRaisesRegex( edgedb.QueryError, r"cannot follow backlink 'whatever' because link 'whatever' " r"of object type 'default::Dummy2' is computed"): await self.con.query( r''' SELECT User.<whatever ''', )
) # We should be able to query the whatever backlink as long as we # filter it properly await self.assert_query_result( r
test_edgeql_select_reverse_overload_03
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_incompatible_union_02(self): await self.con.execute(''' CREATE TYPE Bar; CREATE TYPE Dummy1 { CREATE PROPERTY foo -> int64; }; CREATE TYPE Dummy2 { CREATE LINK foo -> Bar; }; ''') with self.assertRaisesRegex( edgedb.SchemaError, r"cannot create union \(default::Dummy1 \| default::Dummy2\) " r"with link 'foo' using incompatible types default::Bar, " r"std::int64"): await self.con.query( r''' SELECT Dummy1 union Dummy2; ''', )
) with self.assertRaisesRegex( edgedb.SchemaError, r"cannot create union \(default::Dummy1 \| default::Dummy2\) " r"with link 'foo' using incompatible types default::Bar, " r"std::int64"): await self.con.query( r
test_edgeql_select_incompatible_union_02
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_incompatible_union_03(self): await self.con.execute(''' CREATE TYPE Bar; CREATE TYPE Dummy1 { CREATE LINK foo -> Bar { CREATE PROPERTY baz -> int64 } }; CREATE TYPE Dummy2 { CREATE LINK foo -> Bar { CREATE PROPERTY baz -> str } }; ''') with self.assertRaisesRegex( edgedb.SchemaError, r"cannot create union \(default::Dummy1 \| default::Dummy2\) " r"with link 'foo' with property 'baz' using incompatible types " r"std::int64, std::str"): await self.con.query( r''' SELECT Dummy1 union Dummy2; ''', )
) with self.assertRaisesRegex( edgedb.SchemaError, r"cannot create union \(default::Dummy1 \| default::Dummy2\) " r"with link 'foo' with property 'baz' using incompatible types " r"std::int64, std::str"): await self.con.query( r
test_edgeql_select_incompatible_union_03
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_collection_shape_01(self): await self.assert_query_result( r''' SELECT <array<User>>{} UNION [User] ''', [[{"id": str}], [{"id": str}]], ) await self.assert_query_result( r''' SELECT <array<User>>{} ?? [User] ''', [[{"id": str}], [{"id": str}]], ) await self.assert_query_result( r''' SELECT <array<User>>{} IF false ELSE [User] ''', [[{"id": str}], [{"id": str}]], ) await self.assert_query_result( r''' SELECT assert_exists([User]) ''', [[{"id": str}], [{"id": str}]], )
, [[{"id": str}], [{"id": str}]], ) await self.assert_query_result( r
test_edgeql_collection_shape_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_collection_shape_02(self): await self.assert_query_result( r''' SELECT <array<User>>{} UNION array_agg(User) ''', [[{"id": str}, {"id": str}]], ) await self.assert_query_result( r''' SELECT <array<User>>{} ?? array_agg(User) ''', [[{"id": str}, {"id": str}]], ) await self.assert_query_result( r''' SELECT <array<User>>{} IF false ELSE array_agg(User) ''', [[{"id": str}, {"id": str}]], ) await self.assert_query_result( r''' SELECT assert_exists(array_agg(User)) ''', [[{"id": str}, {"id": str}]], )
, [[{"id": str}, {"id": str}]], ) await self.assert_query_result( r
test_edgeql_collection_shape_02
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_collection_shape_03(self): await self.assert_query_result( r''' SELECT <tuple<User, int64>>{} UNION (User, 2) ''', [[{"id": str}, 2], [{"id": str}, 2]], ) await self.assert_query_result( r''' SELECT <tuple<User, int64>>{} ?? (User, 2) ''', [[{"id": str}, 2], [{"id": str}, 2]], ) await self.assert_query_result( r''' SELECT <tuple<User, int64>>{} IF false ELSE (User, 2) ''', [[{"id": str}, 2], [{"id": str}, 2]], ) await self.assert_query_result( r''' SELECT assert_exists((User, 2)) ''', [[{"id": str}, 2], [{"id": str}, 2]], )
, [[{"id": str}, 2], [{"id": str}, 2]], ) await self.assert_query_result( r
test_edgeql_collection_shape_03
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_collection_shape_04(self): await self.assert_query_result( r''' SELECT [(User,)][0] ''', [[{"id": str}], [{"id": str}]] ) await self.assert_query_result( r''' SELECT [((SELECT User {name} ORDER BY .name),)][0] ''', [[{"name": "Elvis"}], [{"name": "Yury"}]] )
, [[{"id": str}], [{"id": str}]] ) await self.assert_query_result( r
test_edgeql_collection_shape_04
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_collection_shape_08(self): await self.assert_query_result( r''' SELECT X := array_agg(User) FILTER X[0].name != 'Sully'; ''', [[{"id": str}, {"id": str}]] ) await self.assert_query_result( r''' SELECT X := [User] FILTER X[0].name = 'Elvis'; ''', [[{"id": str}]] )
, [[{"id": str}, {"id": str}]] ) await self.assert_query_result( r
test_edgeql_collection_shape_08
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_assert_fail_object_computed_01(self): # check that accessing a trivial computable on an object # that will fail to evaluate still fails async with self.assertRaisesRegexTx( edgedb.CardinalityViolationError, "assert_exists violation", ): await self.con.query(""" SELECT assert_exists((SELECT User {m := 10} FILTER false)).m; """) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, "array index 1000 is out of bounds", ): await self.con.query(""" SELECT array_agg((SELECT User {m := Issue}))[{1000}].m; """) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, "array index 1000 is out of bounds", ): await self.con.query(""" SELECT array_agg((SELECT User {m := 10}))[{1000}].m; """)
) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, "array index 1000 is out of bounds", ): await self.con.query(
test_edgeql_assert_fail_object_computed_01
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
async def test_edgeql_select_null_tuple_02(self): await self.assert_query_result( r''' SELECT { lol := array_get([(1, '2')], 1) } ''', [ {'lol': None} ], ) await self.assert_query_result( r''' SELECT { lol := array_get([(a := 1, b := '2')], 1) } ''', [ {'lol': None} ], )
, [ {'lol': None} ], ) await self.assert_query_result( r
test_edgeql_select_null_tuple_02
python
geldata/gel
tests/test_edgeql_select.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_select.py
Apache-2.0
def test_graphql_mutation_insert_scalars_01(self): data = { 'p_bool': False, 'p_str': 'New ScalarTest01', 'p_datetime': '2019-05-01T01:02:35.196811+00:00', 'p_local_datetime': '2019-05-01T01:02:35.196811', 'p_local_date': '2019-05-01', 'p_local_time': '01:02:35.196811', 'p_duration': 'PT21H30M', 'p_int16': 12345, 'p_int32': 1234567890, # Some GraphQL implementations seem to have a limitation # of not being able to handle 64-bit integer literals # (GraphiQL is among them). 'p_int64': 1234567890, 'p_bigint': 123456789123456789123456789, 'p_float32': 4.5, 'p_float64': 4.5, 'p_decimal': 123456789123456789123456789.123456789123456789123456789, } validation_query = r""" query { ScalarTest(filter: {p_str: {eq: "New ScalarTest01"}}) { p_bool p_str p_datetime p_local_datetime p_local_date p_local_time p_duration p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """ self.assert_graphql_query_result(r""" mutation insert_ScalarTest { insert_ScalarTest( data: [{ p_bool: false, p_str: "New ScalarTest01", p_datetime: "2019-05-01T01:02:35.196811+00:00", p_local_datetime: "2019-05-01T01:02:35.196811", p_local_date: "2019-05-01", p_local_time: "01:02:35.196811", p_duration: "21:30:00", p_int16: 12345, p_int32: 1234567890, p_int64: 1234567890, p_bigint: 123456789123456789123456789, p_float32: 4.5, p_float64: 4.5, p_decimal: 123456789123456789123456789.123456789123456789123456789, }] ) { p_bool p_str p_datetime p_local_datetime p_local_date p_local_time p_duration p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "insert_ScalarTest": [data] }) self.assert_graphql_query_result(validation_query, { "ScalarTest": [data] }) self.assert_graphql_query_result(r""" mutation delete_ScalarTest { delete_ScalarTest(filter: {p_str: {eq: "New ScalarTest01"}}) { p_bool p_str p_datetime p_local_datetime p_local_date p_local_time p_duration p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "delete_ScalarTest": [data] }) # validate that the deletion worked self.assert_graphql_query_result(validation_query, { "ScalarTest": [] })
self.assert_graphql_query_result(r
test_graphql_mutation_insert_scalars_01
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_insert_scalars_04(self): # This tests JSON insertion. JSON can only be inserted via a variable. data = { 'p_str': 'New ScalarTest04', 'p_json': {"foo": [1, None, "aardvark"]}, } validation_query = r""" query { ScalarTest(filter: {p_str: {eq: "New ScalarTest04"}}) { p_str p_json } } """ self.assert_graphql_query_result( r""" mutation insert_ScalarTest( $p_str: String!, $p_json: JSON ) { insert_ScalarTest( data: [{ p_str: $p_str, p_json: $p_json, }] ) { p_str p_json } } """, { "insert_ScalarTest": [data] }, variables=data, ) self.assert_graphql_query_result(validation_query, { "ScalarTest": [data] }) self.assert_graphql_query_result( r""" mutation delete_ScalarTest( $p_json: JSON ) { delete_ScalarTest(filter: {p_json: {eq: $p_json}}) { p_str p_json } } """, { "delete_ScalarTest": [data] }, variables=data, ) # validate that the deletion worked self.assert_graphql_query_result(validation_query, { "ScalarTest": [] })
self.assert_graphql_query_result( r
test_graphql_mutation_insert_scalars_04
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_insert_nested_02(self): # Test insert with nested existing object. data = { 'name': 'New UserGroup02', 'settings': [{ 'name': 'setting02', 'value': 'aardvark02' }], } validation_query = r""" query { UserGroup(filter: {name: {eq: "New UserGroup02"}}) { name settings { name value } } } """ setting = self.graphql_query(r""" mutation insert_Setting { insert_Setting(data: [{ name: "setting02", value: "aardvark02" }]) { id name value } } """)['insert_Setting'][0] self.assert_graphql_query_result(rf""" mutation insert_UserGroup {{ insert_UserGroup( data: [{{ name: "New UserGroup02", settings: [{{ filter: {{ id: {{eq: "{setting['id']}"}} }} }}], }}] ) {{ name settings {{ name value }} }} }} """, { "insert_UserGroup": [data] }) self.assert_graphql_query_result(validation_query, { "UserGroup": [data] }) self.assert_graphql_query_result(r""" mutation delete_UserGroup { delete_UserGroup(filter: {name: {eq: "New UserGroup02"}}) { name settings { name value } } } """, { "delete_UserGroup": [data] }) # validate that the deletion worked self.assert_graphql_query_result(validation_query, { "UserGroup": [] })
setting = self.graphql_query(r
test_graphql_mutation_insert_nested_02
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_insert_nested_03(self): # Test insert with nested existing object. data = { 'name': 'New UserGroup03', 'settings': [{ 'name': 'setting031', 'value': 'aardvark03', }, { 'name': 'setting032', 'value': 'other03', }, { 'name': 'setting033', 'value': 'special03', }], } validation_query = r""" query { UserGroup(filter: {name: {eq: "New UserGroup03"}}) { name settings(order: {name: {dir: ASC}}) { name value } } } """ settings = self.graphql_query(r""" mutation insert_Setting { insert_Setting(data: [{ name: "setting031", value: "aardvark03" }, { name: "setting032", value: "other03" }]) { id name value } } """)['insert_Setting'] # nested results aren't fetching correctly self.assert_graphql_query_result(rf""" mutation insert_UserGroup {{ insert_UserGroup( data: [{{ name: "New UserGroup03", settings: [{{ filter: {{ id: {{eq: "{settings[0]['id']}"}} }} }}, {{ data: {{ name: "setting033", value: "special03", }} }}, {{ filter: {{ name: {{eq: "{settings[1]['name']}"}} }} }}], }}] ) {{ name settings(order: {{name: {{dir: ASC}}}}) {{ name value }} }} }} """, { "insert_UserGroup": [data] }) self.assert_graphql_query_result(validation_query, { "UserGroup": [data] }) self.assert_graphql_query_result(r""" mutation delete_UserGroup { delete_UserGroup(filter: {name: {eq: "New UserGroup03"}}) { name settings(order: {name: {dir: ASC}}) { name value } } } """, { "delete_UserGroup": [data] }) # validate that the deletion worked self.assert_graphql_query_result(validation_query, { "UserGroup": [] })
settings = self.graphql_query(r
test_graphql_mutation_insert_nested_03
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_insert_nested_05(self): # Test nested insert for a singular link. profile = self.graphql_query(r""" query { Profile(filter: { name: {eq: "Alice profile"} }) { id name value } } """)['Profile'][0] data = { "name": "New User05", "age": 99, "score": 99.99, "profile": profile } validation_query = r""" query { User(filter: {name: {eq: "New User05"}}) { name age score profile { id name value } } } """ self.assert_graphql_query_result(rf""" mutation insert_User {{ insert_User( data: [{{ name: "New User05", active: false, age: 99, score: 99.99, profile: {{ filter: {{ id: {{eq: "{profile['id']}"}} }}, first: 1 }}, }}] ) {{ name age score profile {{ id name value }} }} }} """, { "insert_User": [data] }) self.assert_graphql_query_result(validation_query, { "User": [data] }) self.assert_graphql_query_result(r""" mutation delete_User { delete_User(filter: {name: {eq: "New User05"}}) { name age score profile { id name value } } } """, { "delete_User": [data] }) # validate that the deletion worked self.assert_graphql_query_result(validation_query, { "User": [] })
)['Profile'][0] data = { "name": "New User05", "age": 99, "score": 99.99, "profile": profile } validation_query = r
test_graphql_mutation_insert_nested_05
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_insert_nested_07(self): # Test insert with nested object filter. data = { "name": "New User07", "age": 33, "score": 33.33, "groups": [{ 'name': 'New UserGroup07', 'settings': [{ 'name': 'setting07', 'value': 'aardvark07', }], }] } validation_query = r""" query { User( filter: {groups: {settings: {name: {eq: "setting07"}}}} ) { name age score groups { name settings { name value } } } } """ # insert the user groups first self.assert_graphql_query_result(r""" mutation insert_UserGroup { insert_UserGroup( data: [{ name: "New UserGroup07", settings: [{ data: { name: "setting07", value: "aardvark07" } }], }] ) { name settings { name value } } } """, { "insert_UserGroup": [data['groups'][0]] }) # insert the User self.assert_graphql_query_result(r""" mutation insert_User { insert_User( data: [{ name: "New User07", active: true, age: 33, score: 33.33, groups: { filter: { settings: {name: {eq: "setting07"}} }, first: 1 }, }] ) { name age score groups { name settings { name value } } } } """, { "insert_User": [data] }) self.assert_graphql_query_result(validation_query, { "User": [data] }) self.assert_graphql_query_result(r""" mutation delete_User { delete_User( filter: {groups: {settings: {name: {eq: "setting07"}}}} ) { name age score groups { name settings { name value } } } } """, { "delete_User": [data] }) # validate that the deletion worked self.assert_graphql_query_result(validation_query, { "User": [] }) # cleanup self.assert_graphql_query_result(r""" mutation delete_UserGroup { delete_UserGroup( filter: {settings: {name: {eq: "setting07"}}} ) { name settings { name value } } } """, { "delete_UserGroup": data['groups'] })
# insert the user groups first self.assert_graphql_query_result(r
test_graphql_mutation_insert_nested_07
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_insert_readonly_02(self): # Test insert object without any properties that can be set data = { '__typename': 'Fixed_Type', 'computed': 123, } validation_query = r""" query { Fixed { __typename computed } } """ self.assert_graphql_query_result(validation_query, { "Fixed": [data] }) self.assert_graphql_query_result(r""" mutation delete_Fixed { delete_Fixed { __typename computed } } """, { "delete_Fixed": [data] }) # validate that the deletion worked self.assert_graphql_query_result(validation_query, { "Fixed": [] }) self.assert_graphql_query_result(r""" mutation insert_Fixed { insert_Fixed { __typename computed } } """, { "insert_Fixed": [data] }) self.assert_graphql_query_result(validation_query, { "Fixed": [data] })
self.assert_graphql_query_result(validation_query, { "Fixed": [data] }) self.assert_graphql_query_result(r
test_graphql_mutation_insert_readonly_02
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_scalars_01(self): orig_data = { 'p_bool': True, 'p_str': 'Hello world', 'p_datetime': '2018-05-07T20:01:22.306916+00:00', 'p_local_datetime': '2018-05-07T20:01:22.306916', 'p_local_date': '2018-05-07', 'p_local_time': '20:01:22.306916', 'p_duration': 'PT20H', 'p_int16': 12345, 'p_int32': 1234567890, 'p_int64': 1234567890123, 'p_bigint': 123456789123456789123456789, 'p_float32': 2.5, 'p_float64': 2.5, 'p_decimal': 123456789123456789123456789.123456789123456789123456789, } data = { 'p_bool': False, 'p_str': 'Update ScalarTest01', 'p_datetime': '2019-05-01T01:02:35.196811+00:00', 'p_local_datetime': '2019-05-01T01:02:35.196811', 'p_local_date': '2019-05-01', 'p_local_time': '01:02:35.196811', 'p_duration': 'PT21H30M', 'p_int16': 4321, 'p_int32': 876543210, # Some GraphQL implementations seem to have a limitation # of not being able to handle 64-bit integer literals # (GraphiQL is among them). 'p_int64': 876543210, 'p_bigint': 333333333333333333333333333, 'p_float32': 4.5, 'p_float64': 4.5, 'p_decimal': 444444444444444444444444444.222222222222222222222222222, } validation_query = rf""" query {{ ScalarTest( filter: {{ or: [{{ p_str: {{eq: "{orig_data['p_str']}"}} }}, {{ p_str: {{eq: "{data['p_str']}"}} }}] }} ) {{ p_bool p_str p_datetime p_local_datetime p_local_date p_local_time p_duration p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal }} }} """ self.assert_graphql_query_result(validation_query, { "ScalarTest": [orig_data] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( data: { p_bool: {set: false}, p_str: {set: "Update ScalarTest01"}, p_datetime: {set: "2019-05-01T01:02:35.196811+00:00"}, p_local_datetime: {set: "2019-05-01T01:02:35.196811"}, p_local_date: {set: "2019-05-01"}, p_local_time: {set: "01:02:35.196811"}, p_duration: {set: "PT21H30M"}, p_int16: {set: 4321}, p_int32: {set: 876543210}, # Some GraphQL implementations seem to have a # limitation of not being able to handle 64-bit # integer literals (GraphiQL is among them). p_int64: {set: 876543210}, p_bigint: {set: 333333333333333333333333333}, p_float32: {set: 4.5}, p_float64: {set: 4.5}, p_decimal: {set: 444444444444444444444444444.222222222222222222222222222}, } ) { p_bool p_str p_datetime p_local_datetime p_local_date p_local_time p_duration p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "update_ScalarTest": [data] }) self.assert_graphql_query_result(validation_query, { "ScalarTest": [data] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest( $p_bool: Boolean, $p_str: String, $p_datetime: String, $p_local_datetime: String, $p_local_date: String, $p_local_time: String, $p_duration: String, $p_int16: Int, $p_int32: Int, $p_int64: Int64, $p_bigint: Bigint, $p_float32: Float, $p_float64: Float, $p_decimal: Decimal, ) { update_ScalarTest( data: { p_bool: {set: $p_bool}, p_str: {set: $p_str}, p_datetime: {set: $p_datetime}, p_local_datetime: {set: $p_local_datetime}, p_local_date: {set: $p_local_date}, p_local_time: {set: $p_local_time}, p_duration: {set: $p_duration}, p_int16: {set: $p_int16}, p_int32: {set: $p_int32}, p_int64: {set: $p_int64}, p_bigint: {set: $p_bigint}, p_float32: {set: $p_float32}, p_float64: {set: $p_float64}, p_decimal: {set: $p_decimal}, } ) { p_bool p_str p_datetime p_local_datetime p_local_date p_local_time p_duration p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "update_ScalarTest": [orig_data] }, variables=orig_data) # validate that the final update worked self.assert_graphql_query_result(validation_query, { "ScalarTest": [orig_data] })
self.assert_graphql_query_result(validation_query, { "ScalarTest": [orig_data] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_scalars_01
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_scalars_03(self): orig_data = { 'p_str': 'Hello world', 'p_json': {"foo": [1, None, "bar"]}, } data = { 'p_str': 'Update ScalarTest03', 'p_json': {"bar": [None, 2, "aardvark"]}, } validation_query = rf""" query {{ ScalarTest( filter: {{ or: [{{ p_str: {{eq: "{orig_data['p_str']}"}} }}, {{ p_str: {{eq: "{data['p_str']}"}} }}] }} ) {{ p_str p_json }} }} """ self.assert_graphql_query_result(validation_query, { "ScalarTest": [orig_data] }) # Test that basic and complex JSON values can be updated for json_val in [data['p_json'], data['p_json']['bar'], True, 123, "hello world", None]: data['p_json'] = json_val self.assert_graphql_query_result( r""" mutation update_ScalarTest( $p_str: String!, $p_json: JSON ) { update_ScalarTest( data: { p_str: {set: $p_str}, p_json: {set: $p_json}, } ) { p_str p_json } } """, { "update_ScalarTest": [data] }, variables=data ) self.assert_graphql_query_result(validation_query, { "ScalarTest": [data] }) self.assert_graphql_query_result( r""" mutation update_ScalarTest( $p_str: String, $p_json: JSON, ) { update_ScalarTest( data: { p_str: {set: $p_str}, p_json: {set: $p_json}, } ) { p_str p_json } } """, { "update_ScalarTest": [orig_data] }, variables=orig_data ) # validate that the final update worked self.assert_graphql_query_result(validation_query, { "ScalarTest": [orig_data] })
self.assert_graphql_query_result(validation_query, { "ScalarTest": [orig_data] }) # Test that basic and complex JSON values can be updated for json_val in [data['p_json'], data['p_json']['bar'], True, 123, "hello world", None]: data['p_json'] = json_val self.assert_graphql_query_result( r
test_graphql_mutation_update_scalars_03
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_scalars_04(self): # This tests update ops for various numerical types. self.assert_graphql_query_result(r""" mutation insert_ScalarTest { insert_ScalarTest( data: [{ p_str: "Update ScalarTest04", p_int16: 0, p_int32: 0, p_int64: 0, p_bigint: 0, p_float32: 0, p_float64: 0, p_decimal: 0, }] ) { p_str p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest04', 'p_int16': 0, 'p_int32': 0, 'p_int64': 0, 'p_bigint': 0, 'p_float32': 0, 'p_float64': 0, 'p_decimal': 0, }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest04"}} data: { p_int16: {increment: 2}, p_int32: {increment: 2}, p_int64: {increment: 2}, p_bigint: {increment: 2}, p_float32: {increment: 1.5}, p_float64: {increment: 1.5}, p_decimal: {increment: 1.5}, } ) { p_str p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest04', 'p_int16': 2, 'p_int32': 2, 'p_int64': 2, 'p_bigint': 2, 'p_float32': 1.5, 'p_float64': 1.5, 'p_decimal': 1.5, }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest04"}} data: { p_int16: {decrement: 1}, p_int32: {decrement: 1}, p_int64: {decrement: 1}, p_bigint: {decrement: 1}, p_float32: {decrement: 0.4}, p_float64: {decrement: 0.4}, p_decimal: {decrement: 0.4}, } ) { p_str p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest04', 'p_int16': 1, 'p_int32': 1, 'p_int64': 1, 'p_bigint': 1, 'p_float32': 1.1, 'p_float64': 1.1, 'p_decimal': 1.1, }] }) # clean up self.assert_graphql_query_result(r""" mutation delete_ScalarTest { delete_ScalarTest( filter: {p_str: {eq: "Update ScalarTest04"}} ) { p_str p_int16 p_int32 p_int64 p_bigint p_float32 p_float64 p_decimal } } """, { "delete_ScalarTest": [{ 'p_str': 'Update ScalarTest04', 'p_int16': 1, 'p_int32': 1, 'p_int64': 1, 'p_bigint': 1, 'p_float32': 1.1, 'p_float64': 1.1, 'p_decimal': 1.1, }] })
, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest04', 'p_int16': 0, 'p_int32': 0, 'p_int64': 0, 'p_bigint': 0, 'p_float32': 0, 'p_float64': 0, 'p_decimal': 0, }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_scalars_04
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_scalars_05(self): # This tests update ops for various numerical types. self.assert_graphql_query_result(r""" mutation insert_ScalarTest { insert_ScalarTest( data: [{ p_str: "Update ScalarTest05", }] ) { p_str } } """, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest05', }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {like: "%Update ScalarTest05%"}} data: { p_str: {prepend: "--"}, } ) { p_str } } """, { "update_ScalarTest": [{ 'p_str': '--Update ScalarTest05', }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {like: "%Update ScalarTest05%"}} data: { p_str: {append: "!!!"}, } ) { p_str } } """, { "update_ScalarTest": [{ 'p_str': '--Update ScalarTest05!!!', }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {like: "%Update ScalarTest05%"}} data: { p_str: {slice: [1]}, } ) { p_str } } """, { "update_ScalarTest": [{ 'p_str': '-Update ScalarTest05!!!', }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {like: "%Update ScalarTest05%"}} data: { p_str: {slice: [0, -1]}, } ) { p_str } } """, { "update_ScalarTest": [{ 'p_str': '-Update ScalarTest05!!', }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {like: "%Update ScalarTest05%"}} data: { p_str: {slice: [1, -2]}, } ) { p_str } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest05', }] }) # clean up self.assert_graphql_query_result(r""" mutation delete_ScalarTest { delete_ScalarTest( filter: {p_str: {like: "%Update ScalarTest05%"}} ) { p_str } } """, { "delete_ScalarTest": [{ 'p_str': 'Update ScalarTest05', }] })
, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest05', }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_scalars_05
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_scalars_06(self): # This tests update ops for various numerical types. self.assert_graphql_query_result(r""" mutation insert_ScalarTest { insert_ScalarTest( data: [{ p_str: "Update ScalarTest06", p_array_str: ["world"], p_array_int64: [0], }] ) { p_str p_array_str p_array_int64 } } """, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest06', 'p_array_str': ['world'], 'p_array_int64': [0], }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest06"}} data: { p_array_str: {prepend: ["Hello"]}, p_array_int64: {prepend: [1, 2]}, } ) { p_str p_array_str p_array_int64 } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest06', 'p_array_str': ['Hello', 'world'], 'p_array_int64': [1, 2, 0], }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest06"}} data: { p_array_str: {append: ["!"]}, p_array_int64: {append: [3, 4]}, } ) { p_str p_array_str p_array_int64 } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest06', 'p_array_str': ['Hello', 'world', '!'], 'p_array_int64': [1, 2, 0, 3, 4], }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest06"}} data: { p_array_str: {slice: [1]}, p_array_int64: {slice: [1]}, } ) { p_str p_array_str p_array_int64 } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest06', 'p_array_str': ['world', '!'], 'p_array_int64': [2, 0, 3, 4], }] }) self.assert_graphql_query_result(r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest06"}} data: { p_array_str: {slice: [1, -2]}, p_array_int64: {slice: [1, -2]}, } ) { p_str p_array_str p_array_int64 } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest06', 'p_array_str': [], 'p_array_int64': [0], }] }) # clean up self.assert_graphql_query_result(r""" mutation delete_ScalarTest { delete_ScalarTest( filter: {p_str: {eq: "Update ScalarTest06"}} ) { p_str p_array_str p_array_int64 } } """, { "delete_ScalarTest": [{ 'p_str': 'Update ScalarTest06', 'p_array_str': [], 'p_array_int64': [0], }] })
, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest06', 'p_array_str': ['world'], 'p_array_int64': [0], }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_scalars_06
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_scalars_07(self): # This tests array of JSON mutations. JSON can only be # mutated via a variable. data = { 'el0': {"foo": [1, None, "aardvark"]}, 'el1': False, } self.assert_graphql_query_result( r""" mutation insert_ScalarTest($el0: JSON!, $el1: JSON!) { insert_ScalarTest( data: [{ p_str: "Update ScalarTest07", p_array_json: [$el0, $el1], }] ) { p_str p_array_json } } """, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest07', 'p_array_json': [data['el0'], data['el1']], }] }, variables=data, ) self.assert_graphql_query_result( r""" mutation update_ScalarTest($el: JSON!) { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest07"}} data: { p_array_json: {prepend: [$el]}, } ) { p_str p_array_json } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest07', 'p_array_json': ["first", data['el0'], data['el1']], }] }, variables={"el": "first"} ) self.assert_graphql_query_result( r""" mutation update_ScalarTest($el: JSON!) { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest07"}} data: { p_array_json: {append: [$el]}, } ) { p_str p_array_json } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest07', 'p_array_json': ["first", data['el0'], data['el1'], 9999], }] }, variables={"el": 9999} ) self.assert_graphql_query_result( r""" mutation update_ScalarTest { update_ScalarTest( filter: {p_str: {eq: "Update ScalarTest07"}} data: { p_array_json: {slice: [1, 3]}, } ) { p_str p_array_json } } """, { "update_ScalarTest": [{ 'p_str': 'Update ScalarTest07', 'p_array_json': [data['el0'], data['el1']], }] } ) # clean up self.assert_graphql_query_result( r""" mutation delete_ScalarTest { delete_ScalarTest( filter: {p_str: {eq: "Update ScalarTest07"}} ) { p_str p_array_json } } """, { "delete_ScalarTest": [{ 'p_str': 'Update ScalarTest07', 'p_array_json': [data['el0'], data['el1']], }] } )
, { "insert_ScalarTest": [{ 'p_str': 'Update ScalarTest07', 'p_array_json': [data['el0'], data['el1']], }] }, variables=data, ) self.assert_graphql_query_result( r
test_graphql_mutation_update_scalars_07
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_enum_01(self): # This tests enum values in updates. self.assert_graphql_query_result(r""" mutation insert_other__Foo { insert_other__Foo( data: [{ select: "Update EnumTest01", color: BLUE }] ) { select color } } """, { "insert_other__Foo": [{ 'select': 'Update EnumTest01', 'color': 'BLUE', }] }) self.assert_graphql_query_result(r""" mutation update_other__Foo { update_other__Foo( filter: {select: {eq: "Update EnumTest01"}} data: { color: {set: RED} } ) { select color } } """, { "update_other__Foo": [{ 'select': 'Update EnumTest01', 'color': 'RED', }] }) # clean up self.assert_graphql_query_result(r""" mutation delete_other__Foo { delete_other__Foo( filter: {select: {eq: "Update EnumTest01"}} ) { select color } } """, { "delete_other__Foo": [{ 'select': 'Update EnumTest01', 'color': 'RED', }] })
, { "insert_other__Foo": [{ 'select': 'Update EnumTest01', 'color': 'BLUE', }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_enum_01
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_enum_02(self): # This tests enum values in updates using variables. self.assert_graphql_query_result(r""" mutation insert_other__Foo { insert_other__Foo( data: [{ select: "Update EnumTest02", color: BLUE }] ) { select color } } """, { "insert_other__Foo": [{ 'select': 'Update EnumTest02', 'color': 'BLUE', }] }) self.assert_graphql_query_result(r""" mutation update_other__Foo ( $color: other__ColorEnum! ) { update_other__Foo( filter: {select: {eq: "Update EnumTest02"}} data: { color: {set: $color} } ) { select color } } """, { "update_other__Foo": [{ 'select': 'Update EnumTest02', 'color': 'RED', }] }, variables={"color": "RED"}) # clean up self.assert_graphql_query_result(r""" mutation delete_other__Foo { delete_other__Foo( filter: {select: {eq: "Update EnumTest02"}} ) { select color } } """, { "delete_other__Foo": [{ 'select': 'Update EnumTest02', 'color': 'RED', }] })
, { "insert_other__Foo": [{ 'select': 'Update EnumTest02', 'color': 'BLUE', }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_enum_02
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_enum_03(self): # This tests enum values in updates. self.assert_graphql_query_result(r""" mutation insert_other__Foo { insert_other__Foo( data: [{ select: "Update EnumTest03", color: BLUE, color_array: [RED, BLUE, BLUE] }] ) { select color color_array } } """, { "insert_other__Foo": [{ 'select': 'Update EnumTest03', 'color': 'BLUE', 'color_array': ['RED', 'BLUE', 'BLUE'], }] }) self.assert_graphql_query_result(r""" mutation update_other__Foo { update_other__Foo( filter: {select: {eq: "Update EnumTest03"}} data: { color_array: {append: [GREEN]} } ) { select color_array } } """, { "update_other__Foo": [{ 'select': 'Update EnumTest03', 'color_array': ['RED', 'BLUE', 'BLUE', 'GREEN'], }] }) # clean up self.assert_graphql_query_result(r""" mutation delete_other__Foo { delete_other__Foo( filter: {select: {eq: "Update EnumTest03"}} ) { select color_array } } """, { "delete_other__Foo": [{ 'select': 'Update EnumTest03', 'color_array': ['RED', 'BLUE', 'BLUE', 'GREEN'], }] })
, { "insert_other__Foo": [{ 'select': 'Update EnumTest03', 'color': 'BLUE', 'color_array': ['RED', 'BLUE', 'BLUE'], }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_enum_03
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_enum_04(self): # This tests enum values in updates. self.assert_graphql_query_result(r""" mutation insert_other__Foo { insert_other__Foo( data: [{ select: "Update EnumTest04", color: BLUE, multi_color: [RED, BLUE] }] ) { select color multi_color } } """, { "insert_other__Foo": [{ 'select': 'Update EnumTest04', 'color': 'BLUE', 'multi_color': ['RED', 'BLUE'], }] }) self.assert_graphql_query_result(r""" mutation update_other__Foo { update_other__Foo( filter: {select: {eq: "Update EnumTest04"}} data: { multi_color: {add: GREEN} } ) { select multi_color } } """, { "update_other__Foo": [{ 'select': 'Update EnumTest04', 'multi_color': {'RED', 'BLUE', 'GREEN'}, }] }) # clean up self.assert_graphql_query_result(r""" mutation delete_other__Foo { delete_other__Foo( filter: {select: {eq: "Update EnumTest04"}} ) { select multi_color } } """, { "delete_other__Foo": [{ 'select': 'Update EnumTest04', 'multi_color': {'RED', 'BLUE', 'GREEN'}, }] })
, { "insert_other__Foo": [{ 'select': 'Update EnumTest04', 'color': 'BLUE', 'multi_color': ['RED', 'BLUE'], }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_enum_04
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_range_01(self): # This tests range and multirange values in updates. self.assert_graphql_query_result(r""" mutation insert_RangeTest { insert_RangeTest( data: [{ name: "Update RangeTest01", rval: { lower: -1.2, upper: 3.4, inc_lower: true, inc_upper: false }, mval: [ { lower: null, upper: -10, inc_lower: false, inc_upper: false }, { lower: -3, upper: 12, inc_lower: true, inc_upper: false }, ], rdate: { lower: "2019-02-13", upper: "2023-08-29", inc_lower: true, inc_upper: false }, mdate: [ { lower: "2019-02-13", upper: "2023-08-29", inc_lower: true, inc_upper: false }, { lower: "2026-10-20", upper: null, inc_lower: true, inc_upper: false } ] }] ) { name rval mval rdate mdate } } """, { "insert_RangeTest": [{ "name": "Update RangeTest01", "rval": { "lower": -1.2, "upper": 3.4, "inc_lower": True, "inc_upper": False }, "mval": [ { "lower": None, "upper": -10, "inc_lower": False, "inc_upper": False }, { "lower": -3, "upper": 12, "inc_lower": True, "inc_upper": False }, ], "rdate": { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, "mdate": [ { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, { "lower": "2026-10-20", "upper": None, "inc_lower": True, "inc_upper": False } ] }] }) self.assert_graphql_query_result(r""" mutation update_RangeTest { update_RangeTest( filter: {name: {eq: "Update RangeTest01"}}, data: { rval: { set: { lower: 5.6, upper: 7.8, inc_lower: true, inc_upper: true } }, mval: { set: [ { lower: 0, upper: 1.2, inc_lower: true, inc_upper: false }, ] }, rdate: { set: { lower: "2018-12-10", upper: "2022-10-20", inc_lower: true, inc_upper: false } }, mdate: { set: [ { lower: null, upper: "2019-02-13", inc_lower: true, inc_upper: false }, { lower: "2023-08-29", upper: "2026-10-20", inc_lower: true, inc_upper: false } ] } } ) { name rval mval rdate mdate } } """, { "update_RangeTest": [{ "name": "Update RangeTest01", "rval": { "lower": 5.6, "upper": 7.8, "inc_lower": True, "inc_upper": True }, "mval": [ { "lower": 0, "upper": 1.2, "inc_lower": True, "inc_upper": False }, ], "rdate": { "lower": "2018-12-10", "upper": "2022-10-20", "inc_lower": True, "inc_upper": False }, "mdate": [ { "lower": None, "upper": "2019-02-13", "inc_lower": False, "inc_upper": False }, { "lower": "2023-08-29", "upper": "2026-10-20", "inc_lower": True, "inc_upper": False } ] }] }) # Cleanup self.assert_graphql_query_result(r""" mutation delete_RangeTest { delete_RangeTest( filter: {name: {eq: "Update RangeTest01"}} ) { name } } """, { "delete_RangeTest": [{"name": "Update RangeTest01"}] })
, { "insert_RangeTest": [{ "name": "Update RangeTest01", "rval": { "lower": -1.2, "upper": 3.4, "inc_lower": True, "inc_upper": False }, "mval": [ { "lower": None, "upper": -10, "inc_lower": False, "inc_upper": False }, { "lower": -3, "upper": 12, "inc_lower": True, "inc_upper": False }, ], "rdate": { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, "mdate": [ { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, { "lower": "2026-10-20", "upper": None, "inc_lower": True, "inc_upper": False } ] }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_range_01
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_range_02(self): # This tests range and multirange values in insertion. self.assert_graphql_query_result(r""" mutation insert_RangeTest { insert_RangeTest( data: [{ name: "Update RangeTest02", rval: { lower: -1.2, upper: 3.4, inc_lower: true, inc_upper: false }, mval: [ { lower: null, upper: -10, inc_lower: false, inc_upper: false }, { lower: -3, upper: 12, inc_lower: true, inc_upper: false }, ], rdate: { lower: "2019-02-13", upper: "2023-08-29", inc_lower: true, inc_upper: false }, mdate: [ { lower: "2019-02-13", upper: "2023-08-29", inc_lower: true, inc_upper: false }, { lower: "2026-10-20", upper: null, inc_lower: true, inc_upper: false } ] }] ) { name rval mval rdate mdate } } """, { "insert_RangeTest": [{ "name": "Update RangeTest02", "rval": { "lower": -1.2, "upper": 3.4, "inc_lower": True, "inc_upper": False }, "mval": [ { "lower": None, "upper": -10, "inc_lower": False, "inc_upper": False }, { "lower": -3, "upper": 12, "inc_lower": True, "inc_upper": False }, ], "rdate": { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, "mdate": [ { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, { "lower": "2026-10-20", "upper": None, "inc_lower": True, "inc_upper": False } ] }] }) self.assert_graphql_query_result(r""" mutation update_RangeTest( $rval: RangeOfFloat, $mval: [RangeOfFloat!], $rdate: RangeOfString, $mdate: [RangeOfString!] ) { update_RangeTest( filter: {name: {eq: "Update RangeTest02"}}, data: { rval: {set: $rval}, mval: {set: $mval}, rdate: {set: $rdate}, mdate: {set: $mdate} } ) { name rval mval rdate mdate } } """, { "update_RangeTest": [{ "name": "Update RangeTest02", "rval": { "lower": 5.6, "upper": 7.8, "inc_lower": True, "inc_upper": True }, "mval": [ { "lower": 0, "upper": 1.2, "inc_lower": True, "inc_upper": False }, ], "rdate": { "lower": "2018-12-10", "upper": "2022-10-20", "inc_lower": True, "inc_upper": False }, "mdate": [ { "lower": None, "upper": "2019-02-13", "inc_lower": False, "inc_upper": False }, { "lower": "2023-08-29", "upper": "2026-10-20", "inc_lower": True, "inc_upper": False } ] }] }, variables={ "rval": { "lower": 5.6, "upper": 7.8, "inc_lower": True, "inc_upper": True }, "mval": [ { "lower": 0, "upper": 1.2, "inc_lower": True, "inc_upper": False }, ], "rdate": { "lower": "2018-12-10", "upper": "2022-10-20", "inc_lower": True, "inc_upper": False }, "mdate": [ { "lower": None, "upper": "2019-02-13", "inc_lower": True, "inc_upper": False }, { "lower": "2023-08-29", "upper": "2026-10-20", "inc_lower": True, "inc_upper": False } ] }) # Cleanup self.assert_graphql_query_result(r""" mutation delete_RangeTest { delete_RangeTest( filter: {name: {eq: "Update RangeTest02"}} ) { name } } """, { "delete_RangeTest": [{"name": "Update RangeTest02"}] })
, { "insert_RangeTest": [{ "name": "Update RangeTest02", "rval": { "lower": -1.2, "upper": 3.4, "inc_lower": True, "inc_upper": False }, "mval": [ { "lower": None, "upper": -10, "inc_lower": False, "inc_upper": False }, { "lower": -3, "upper": 12, "inc_lower": True, "inc_upper": False }, ], "rdate": { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, "mdate": [ { "lower": "2019-02-13", "upper": "2023-08-29", "inc_lower": True, "inc_upper": False }, { "lower": "2026-10-20", "upper": None, "inc_lower": True, "inc_upper": False } ] }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_range_02
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_link_01(self): orig_data = { 'name': 'John', 'groups': [{ 'name': 'basic' }], } data1 = { 'name': 'John', 'groups': [], } data2 = { 'name': 'John', 'groups': [{ 'name': 'basic' }, { 'name': 'unused' }, { 'name': 'upgraded' }], } validation_query = r""" query { User( filter: { name: {eq: "John"} } ) { name groups(order: {name: {dir: ASC}}) { name } } } """ self.assert_graphql_query_result(validation_query, { "User": [orig_data] }) self.assert_graphql_query_result(r""" mutation update_User { update_User( data: { groups: { clear: true } }, filter: { name: {eq: "John"} } ) { name groups(order: {name: {dir: ASC}}) { name } } } """, { "update_User": [data1] }) self.assert_graphql_query_result(validation_query, { "User": [data1] }) self.assert_graphql_query_result(r""" mutation update_User { update_User( data: { groups: { set: [{ filter: { name: {like: "%"} } }] } }, filter: { name: {eq: "John"} } ) { name groups(order: {name: {dir: ASC}}) { name } } } """, { "update_User": [data2] }) self.assert_graphql_query_result(validation_query, { "User": [data2] }) self.assert_graphql_query_result(r""" mutation update_User { update_User( data: { groups: { set: [{ filter: { name: {eq: "basic"} } }] } }, filter: { name: {eq: "John"} } ) { name groups(order: {name: {dir: ASC}}) { name } } } """, { "update_User": [orig_data] }) self.assert_graphql_query_result(validation_query, { "User": [orig_data] })
self.assert_graphql_query_result(validation_query, { "User": [orig_data] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_link_01
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_link_03(self): # test set ops for update of multi link self.assert_graphql_query_result(r""" mutation update_User { update_User( filter: { name: {eq: "Jane"} }, data: { groups: { add: [{ filter: { name: {eq: "basic"} } }] } } ) { name groups(order: {name: {dir: ASC}}) { name } } } """, { "update_User": [{ 'name': 'Jane', 'groups': [{ 'name': 'basic' }, { 'name': 'upgraded' }], }] }) # add an existing group self.assert_graphql_query_result(r""" mutation update_User { update_User( filter: { name: {eq: "Jane"} }, data: { groups: { add: [{ filter: { name: {eq: "basic"} } }] } } ) { name groups(order: {name: {dir: ASC}}) { name } } } """, { "update_User": [{ 'name': 'Jane', 'groups': [{ 'name': 'basic' }, { 'name': 'upgraded' }], }] }) self.assert_graphql_query_result(r""" mutation update_User { update_User( filter: { name: {eq: "Jane"} }, data: { groups: { remove: [{ filter: { name: {eq: "basic"} } }] } } ) { name groups(order: {name: {dir: ASC}}) { name } } } """, { "update_User": [{ 'name': 'Jane', 'groups': [{ 'name': 'upgraded' }], }] })
, { "update_User": [{ 'name': 'Jane', 'groups': [{ 'name': 'basic' }, { 'name': 'upgraded' }], }] }) # add an existing group self.assert_graphql_query_result(r
test_graphql_mutation_update_link_03
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_link_06(self): # updating a single link targeting a type union orig_data = { 'name': 'combo 0', 'data': None, } data1 = { 'name': 'combo 0', 'data': { "__typename": "Setting_Type", "name": "perks", }, } data2 = { 'name': 'combo 0', 'data': { "__typename": "Profile_Type", "name": "Bob profile", }, } validation_query = r""" query { Combo( filter: {name: {eq: "combo 0"}} ) { name data { __typename name } } } """ self.assert_graphql_query_result(validation_query, { "Combo": [orig_data] }) self.assert_graphql_query_result(r""" mutation update_Combo { update_Combo( data: { data: { set: { filter: {name: {eq: "perks"}} } } }, filter: { name: {eq: "combo 0"} } ) { name data { __typename name } } } """, { "update_Combo": [data1] }) self.assert_graphql_query_result(validation_query, { "Combo": [data1] }) self.assert_graphql_query_result(r""" mutation update_Combo { update_Combo( data: { data: { set: { filter: {name: {eq: "Bob profile"}} } } }, filter: { name: {eq: "combo 0"} } ) { name data { __typename name } } } """, { "update_Combo": [data2] }) self.assert_graphql_query_result(validation_query, { "Combo": [data2] }) self.assert_graphql_query_result(r""" mutation update_Combo { update_Combo( data: { data: { clear: true } }, filter: { name: {eq: "combo 0"} } ) { name data { __typename name } } } """, { "update_Combo": [orig_data] }) self.assert_graphql_query_result(validation_query, { "Combo": [orig_data] })
self.assert_graphql_query_result(validation_query, { "Combo": [orig_data] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_link_06
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_multiple_02(self): # Issue #3470 # Test nested update of the same type. data = { 'after': 'BaseFoo02', 'color': 'GREEN', 'foos': [{ 'after': 'NestedFoo020', 'color': 'RED', }, { 'after': 'NestedFoo021', 'color': 'BLUE', }], } validation_query = r""" query { other__Foo(filter: {after: {eq: "BaseFoo02"}}) { after color foos(order: {color: {dir: ASC}}) { after color } } } """ self.graphql_query(r""" mutation insert_other__Foo { insert_other__Foo( data: [{ after: "NestedFoo020", color: RED }, { after: "BaseFoo02", color: GREEN }, { after: "NestedFoo021", color: BLUE }] ) { color } } """) self.assert_graphql_query_result(r""" mutation update_other__Foo { update_other__Foo( filter: {after: {eq: "BaseFoo02"}}, data: { foos: { set: [{ filter: { after: {like: "NestedFoo02%"}, } }] } } ) { after color foos(order: {color: {dir: ASC}}) { after color } } } """, { "update_other__Foo": [data] }) self.assert_graphql_query_result(validation_query, { "other__Foo": [data] }) self.assert_graphql_query_result(r""" mutation delete_other__Foo { delete_other__Foo( filter: {after: {like: "%Foo02%"}}, order: {color: {dir: ASC}} ) { after color } } """, { "delete_other__Foo": [{ 'after': 'NestedFoo020', 'color': 'RED', }, { 'after': 'BaseFoo02', 'color': 'GREEN', }, { 'after': 'NestedFoo021', 'color': 'BLUE', }] })
self.graphql_query(r
test_graphql_mutation_update_multiple_02
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_multiple_03(self): # Issue #3470 # Test nested update of the same type. self.graphql_query(r""" mutation insert_other__Foo { insert_other__Foo( data: [{ after: "NestedFoo030", color: RED }, { after: "BaseFoo03", color: GREEN }, { after: "NestedFoo031", color: BLUE }] ) { color } } """) self.assert_graphql_query_result(r""" mutation update_other__Foo { update_other__Foo( filter: {after: {eq: "BaseFoo03"}}, data: { foos: { add: [{ filter: { after: {like: "NestedFoo03%"}, } }] } } ) { after color foos(order: {color: {dir: ASC}}) { after color } } } """, { "update_other__Foo": [{ 'after': 'BaseFoo03', 'color': 'GREEN', 'foos': [{ 'after': 'NestedFoo030', 'color': 'RED', }, { 'after': 'NestedFoo031', 'color': 'BLUE', }], }] }) self.assert_graphql_query_result(r""" mutation update_other__Foo { update_other__Foo( filter: {after: {eq: "BaseFoo03"}}, data: { foos: { remove: [{ filter: { after: {eq: "NestedFoo031"}, } }] } } ) { after color foos(order: {color: {dir: ASC}}) { after color } } } """, { "update_other__Foo": [{ 'after': 'BaseFoo03', 'color': 'GREEN', 'foos': [{ 'after': 'NestedFoo030', 'color': 'RED', }], }] }) self.assert_graphql_query_result(r""" mutation delete_other__Foo { delete_other__Foo( filter: {after: {like: "%Foo03%"}}, order: {color: {dir: ASC}} ) { after color } } """, { "delete_other__Foo": [{ 'after': 'NestedFoo030', 'color': 'RED', }, { 'after': 'BaseFoo03', 'color': 'GREEN', }, { 'after': 'NestedFoo031', 'color': 'BLUE', }] })
) self.assert_graphql_query_result(r
test_graphql_mutation_update_multiple_03
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_update_typename_01(self): # This tests the typename funcitonality after insertion. # Issue #5985 self.assert_graphql_query_result(r""" mutation insert_other__Foo { __typename insert_other__Foo( data: [{ select: "Update TypenameTest01", color: BLUE }] ) { __typename select color } } """, { "__typename": 'Mutation', "insert_other__Foo": [{ '__typename': 'other__Foo_Type', 'select': 'Update TypenameTest01', 'color': 'BLUE', }] }) self.assert_graphql_query_result(r""" mutation update_other__Foo { __typename update_other__Foo( filter: {select: {eq: "Update TypenameTest01"}} data: { color: {set: RED} } ) { __typename select color } } """, { "__typename": 'Mutation', "update_other__Foo": [{ '__typename': 'other__Foo_Type', 'select': 'Update TypenameTest01', 'color': 'RED', }] }) # clean up self.assert_graphql_query_result(r""" mutation delete_other__Foo { __typename delete_other__Foo( filter: {select: {eq: "Update TypenameTest01"}} ) { __typename select color } } """, { "__typename": 'Mutation', "delete_other__Foo": [{ '__typename': 'other__Foo_Type', 'select': 'Update TypenameTest01', 'color': 'RED', }] })
, { "__typename": 'Mutation', "insert_other__Foo": [{ '__typename': 'other__Foo_Type', 'select': 'Update TypenameTest01', 'color': 'BLUE', }] }) self.assert_graphql_query_result(r
test_graphql_mutation_update_typename_01
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_mutation_delete_alias_01(self): self.assert_graphql_query_result(r""" mutation insert_Setting { insert_Setting( data: [{ name: "delsetting01", value: "red" }] ) { name value } } """, { "insert_Setting": [{ 'name': 'delsetting01', 'value': 'red', }] }) self.assert_graphql_query_result(r""" mutation delete_SettingAlias { delete_SettingAlias( filter: { name: {eq: "delsetting01"} } ) { name value } } """, { "delete_SettingAlias": [{ 'name': 'delsetting01', 'value': 'red', }] }) self.assert_graphql_query_result(r""" query get_SettingAlias { SettingAlias( filter: { name: {eq: "delsetting01"} } ) { name value } } """, { "SettingAlias": [] })
, { "insert_Setting": [{ 'name': 'delsetting01', 'value': 'red', }] }) self.assert_graphql_query_result(r
test_graphql_mutation_delete_alias_01
python
geldata/gel
tests/test_http_graphql_mutation.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py
Apache-2.0
def test_graphql_http_keepalive_01(self): with self.http_con() as con: for _ in range(3): req1_data = { 'query': ''' { Setting(order: {value: {dir: ASC}}) { value } } ''' } data, headers, status = self.http_con_request( con, req1_data, headers={ 'Authorization': self.make_auth_header(), }, ) self.assertEqual(status, 200) self.assertNotIn('connection', headers) self.assertEqual( headers.get('content-type'), 'application/json') self.assertEqual( json.loads(data)['data'], {'Setting': [{'value': 'blue'}, {'value': 'full'}, {'value': 'none'}]}) req2_data = { 'query': ''' { NON_EXISTING_TYPE { name } } ''' } data, headers, status = self.http_con_request( con, req2_data, headers={ 'Authorization': self.make_auth_header(), }, ) self.assertEqual(status, 200) self.assertNotIn('connection', headers) self.assertEqual( headers.get('content-type'), 'application/json') self.assertIn( 'QueryError:', json.loads(data)['errors'][0]['message'])
} data, headers, status = self.http_con_request( con, req1_data, headers={ 'Authorization': self.make_auth_header(), }, ) self.assertEqual(status, 200) self.assertNotIn('connection', headers) self.assertEqual( headers.get('content-type'), 'application/json') self.assertEqual( json.loads(data)['data'], {'Setting': [{'value': 'blue'}, {'value': 'full'}, {'value': 'none'}]}) req2_data = { 'query':
test_graphql_http_keepalive_01
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
def test_graphql_functional_query_08(self): self.assert_graphql_query_result( r""" query names { Setting { name } } query values { Setting { value } } """, { 'Setting': [{ 'name': 'perks', }, { 'name': 'template', }, { 'name': 'template', }], }, sort=lambda x: x['name'], operation_name='names' ) self.assert_graphql_query_result( r""" query names { Setting { name } } query values { Setting { value } } """, { 'Setting': [{ 'value': 'blue', }, { 'value': 'full', }, { 'value': 'none', }], }, sort=lambda x: x['value'], operation_name='values', use_http_post=False )
, { 'Setting': [{ 'name': 'perks', }, { 'name': 'template', }, { 'name': 'template', }], }, sort=lambda x: x['name'], operation_name='names' ) self.assert_graphql_query_result( r
test_graphql_functional_query_08
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
def test_graphql_functional_query_17(self): # Test unused & null variables self.assert_graphql_query_result( r""" query Person { Person { name } } """, { 'Person': [{ 'name': 'Bob', }], }, variables={'name': None}, ) self.assert_graphql_query_result( r""" query Person($name: String) { Person(filter: {name: {eq: $name}}) { name } } """, { 'Person': [], }, variables={'name': None}, )
, { 'Person': [{ 'name': 'Bob', }], }, variables={'name': None}, ) self.assert_graphql_query_result( r
test_graphql_functional_query_17
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
def test_graphql_functional_alias_04(self): self.assert_graphql_query_result( r""" { ProfileAlias { __typename name value owner { __typename id } } } """, { "ProfileAlias": [ { "__typename": "ProfileAlias", "name": "Alice profile", "value": "special", "owner": [ { "__typename": "User_Type", "id": uuid.UUID, } ] }, { "__typename": "ProfileAlias", "name": "Bob profile", "value": "special", "owner": [ { "__typename": "Person_Type", "id": uuid.UUID, } ] } ] }, ) result = self.graphql_query(r""" query { ProfileAlias { owner { id } } } """) user_id = result['ProfileAlias'][0]['owner'][0]['id'] self.assert_graphql_query_result(f""" query {{ User(filter: {{id: {{eq: "{user_id}"}}}}) {{ name }} }} """, { 'User': [{'name': 'Alice'}] })
, { "ProfileAlias": [ { "__typename": "ProfileAlias", "name": "Alice profile", "value": "special", "owner": [ { "__typename": "User_Type", "id": uuid.UUID, } ] }, { "__typename": "ProfileAlias", "name": "Bob profile", "value": "special", "owner": [ { "__typename": "Person_Type", "id": uuid.UUID, } ] } ] }, ) result = self.graphql_query(r
test_graphql_functional_alias_04
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
def test_graphql_functional_arguments_01(self): result = self.graphql_query(r""" query { User { id name age } } """) alice = [res for res in result['User'] if res['name'] == 'Alice'][0] self.assert_graphql_query_result(f""" query {{ User(filter: {{id: {{eq: "{alice['id']}"}}}}) {{ id name age }} }} """, { 'User': [alice] })
) alice = [res for res in result['User'] if res['name'] == 'Alice'][0] self.assert_graphql_query_result(f
test_graphql_functional_arguments_01
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
def test_graphql_functional_fragment_20(self): # ISSUE #1800 # # After using a typed inline fragment the nested fields or # fields following after the fragment are erroneously using # the type intersection. self.assert_graphql_query_result(r""" query { NamedObject(filter: {name: {eq: "Alice"}}) { ... on User { active profile(filter: {name: {eq: "Alice profile"}}) { value } } name } } """, { 'NamedObject': [{ 'name': 'Alice', 'active': True, 'profile': { 'value': 'special', } }], }) self.assert_graphql_query_result(r""" query { NamedObject(filter: {name: {eq: "Alice"}}) { ... on User { active profile(filter: {name: {eq: "no such profile"}}) { value } } name } } """, { 'NamedObject': [{ 'name': 'Alice', 'active': True, 'profile': None, }], })
, { 'NamedObject': [{ 'name': 'Alice', 'active': True, 'profile': { 'value': 'special', } }], }) self.assert_graphql_query_result(r
test_graphql_functional_fragment_20
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
def test_graphql_functional_fragment_24(self): # ISSUE #5985 # # Types from non-default module should be recognized in fragments. self.assert_graphql_query_result(r""" fragment myFrag on other__Foo { id, color, } query { other__Foo(filter: {color: {eq: RED}}) { ... myFrag } } """, { 'other__Foo': [{ 'id': uuid.UUID, 'color': 'RED', }], }) self.assert_graphql_query_result(r""" fragment myFrag on other__Foo_Type { id, color, } query { other__Foo(filter: {color: {eq: RED}}) { ... myFrag } } """, { 'other__Foo': [{ 'id': uuid.UUID, 'color': 'RED', }], })
, { 'other__Foo': [{ 'id': uuid.UUID, 'color': 'RED', }], }) self.assert_graphql_query_result(r
test_graphql_functional_fragment_24
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
def test_graphql_functional_variables_34(self): # Test multiple requests to make sure that caching works correctly for _ in range(2): for _ in range(2): self.assert_graphql_query_result( r""" query($val: Boolean!, $min_age: Int64!) { User(filter: {age: {gt: $min_age}}) { name @include(if: $val), age } } """, {'User': [{'age': 27, 'name': 'Alice'}]}, variables={'val': True, 'min_age': 26} ) self.assert_graphql_query_result( r""" query($val: Boolean!, $min_age: Int64!) { User(filter: {age: {gt: $min_age}}) { name @include(if: $val), age } } """, {'User': [{'age': 27}]}, variables={'val': False, 'min_age': 26} )
, {'User': [{'age': 27, 'name': 'Alice'}]}, variables={'val': True, 'min_age': 26} ) self.assert_graphql_query_result( r
test_graphql_functional_variables_34
python
geldata/gel
tests/test_http_graphql_query.py
https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py
Apache-2.0
async def test_edgeql_casts_bytes_04(self): async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'expected JSON string or null', ): await self.con.query_single("SELECT <bytes>to_json('1');") self.assertEqual( await self.con.query_single(r''' SELECT <bytes>to_json('"aGVsbG8="'); '''), b'hello', ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid symbol'): await self.con.query_single(""" SELECT <bytes>to_json('"not base64!"'); """) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid base64 end sequence'): await self.con.query_single(""" SELECT <bytes>to_json('"a"'); """)
), b'hello', ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid symbol'): await self.con.query_single(
test_edgeql_casts_bytes_04
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_str_02(self): # Certain strings can be cast into other types losslessly, # making them "canonical" string representations of those # values. await self.assert_query_result( r''' FOR x in {'true', 'false'} SELECT <str><bool>x = x; ''', [True, True], ) await self.assert_query_result( r''' FOR x in {'True', 'False', 'TRUE', 'FALSE', ' TrUe '} SELECT <str><bool>x = x; ''', [False, False, False, False, False], ) await self.assert_query_result( r''' FOR x in {'True', 'False', 'TRUE', 'FALSE', 'TrUe'} SELECT <str><bool>x = str_lower(x); ''', [True, True, True, True, True], ) for variant in {'😈', 'yes', '1', 'no', 'on', 'OFF', 't', 'f', 'tr', 'fa'}: async with self.assertRaisesRegexTx( edgedb.InvalidValueError, fr"invalid input syntax for type std::bool: '{variant}'"): await self.con.query_single(f'SELECT <bool>"{variant}"') self.assertTrue( await self.con.query_single('SELECT <bool>" TruE "')) self.assertFalse( await self.con.query_single('SELECT <bool>" FalsE "'))
, [True, True], ) await self.assert_query_result( r
test_edgeql_casts_str_02
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_str_04(self): # canonical uuid representation as a string is using lowercase await self.assert_query_result( r''' FOR x in 'd4288330-eea3-11e8-bc5f-7faf132b1d84' SELECT <str><uuid>x = x; ''', [True], ) await self.assert_query_result( # non-canonical r''' FOR x in { 'D4288330-EEA3-11E8-BC5F-7FAF132B1D84', 'D4288330-Eea3-11E8-Bc5F-7Faf132B1D84', 'D4288330-eea3-11e8-bc5f-7faf132b1d84', } SELECT <str><uuid>x = x; ''', [False, False, False], ) await self.assert_query_result( r''' FOR x in { 'D4288330-EEA3-11E8-BC5F-7FAF132B1D84', 'D4288330-Eea3-11E8-Bc5F-7Faf132B1D84', 'D4288330-eea3-11e8-bc5f-7faf132b1d84', } SELECT <str><uuid>x = str_lower(x); ''', [True, True, True], )
, [True], ) await self.assert_query_result( # non-canonical r
test_edgeql_casts_str_04
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_str_05(self): # Canonical date and time str representations must follow ISO # 8601. This test assumes that the server is configured to be # in UTC time zone. await self.assert_query_result( r''' FOR x in '2018-05-07T20:01:22.306916+00:00' SELECT <str><datetime>x = x; ''', [True], ) await self.assert_query_result( # validating that these are all in fact the same datetime r''' FOR x in { '2018-05-07T15:01:22.306916-05:00', '2018-05-07T15:01:22.306916-05', '2018-05-07T20:01:22.306916Z', '2018-05-07T20:01:22.306916+0000', '2018-05-07T20:01:22.306916+00', # the '-' and ':' separators may be omitted '20180507T200122.306916+00', # acceptable RFC 3339 '2018-05-07 20:01:22.306916+00:00', '2018-05-07t20:01:22.306916z', } SELECT <datetime>x = <datetime>'2018-05-07T20:01:22.306916+00:00'; ''', [True, True, True, True, True, True, True, True], ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax'): await self.con.query_single( 'SELECT <datetime>"2018-05-07;20:01:22.306916+00:00"') async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax'): await self.con.query_single( 'SELECT <datetime>"2018-05-07T20:01:22.306916"') async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax'): await self.con.query_single( 'SELECT <datetime>"2018-05-07T20:01:22.306916 1000"') async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax'): await self.con.query_single( 'SELECT <datetime>"2018-05-07T20:01:22.306916 US/Central"') async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax'): await self.con.query_single( 'SELECT <datetime>"2018-05-07T20:01:22.306916 +GMT1"')
, [True], ) await self.assert_query_result( # validating that these are all in fact the same datetime r
test_edgeql_casts_str_05
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_str_07(self): # Canonical date and time str representations must follow ISO # 8601. await self.assert_query_result( r''' FOR x in '2018-05-07' SELECT <str><cal::local_date>x = x; ''', [True], ) await self.assert_query_result( # validating that these are all in fact the same date r''' FOR x in { # the '-' separators may be omitted '20180507', } SELECT <cal::local_date>x = <cal::local_date>'2018-05-07'; ''', [True], ) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax for type'): await self.con.query_single( 'SELECT <cal::local_date>"2018-05-07T20:01:22.306916"') async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax for type'): await self.con.query_single( 'SELECT <cal::local_date>"2018/05/07"') async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax for type'): await self.con.query_single( 'SELECT <cal::local_date>"2018.05.07"') async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'invalid input syntax for type'): await self.con.query_single( 'SELECT <cal::local_date>"2018-05-07+01:00"')
, [True], ) await self.assert_query_result( # validating that these are all in fact the same date r
test_edgeql_casts_str_07
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_str_12(self): # The canonical string representation of decimals is without # use of scientific notation. await self.assert_query_result( r''' FOR x in { '-20', '0', '7.2', '0.0000000001234', '1234.00000001234' } SELECT <str><decimal>x = x; ''', [True, True, True, True, True], ) await self.assert_query_result( # non-canonical r''' FOR x in { '1234E-13', '0.1234e-9', } SELECT <str><decimal>x = x; ''', [False, False], ) await self.assert_query_result( # validating that these are all in fact the same date r''' FOR x in { '1234E-13', '0.1234e-9', } SELECT <decimal>x = <decimal>'0.0000000001234'; ''', [True, True], )
, [True, True, True, True, True], ) await self.assert_query_result( # non-canonical r
test_edgeql_casts_str_12
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_numeric_01(self): # Casting to decimal and back should be lossless for any other # integer type. for numtype in {'bigint', 'decimal'}: await self.assert_query_result( # technically we're already casting a literal int64 # to int16 first f''' FOR x in <int16>{{-32768, -32767, -100, 0, 13, 32766, 32767}} SELECT <int16><{numtype}>x = x; ''', [True, True, True, True, True, True, True], ) await self.assert_query_result( # technically we're already casting a literal int64 # to int32 first f''' FOR x in <int32>{{-2147483648, -2147483647, -65536, -100, 0, 13, 32768, 2147483646, 2147483647}} SELECT <int32><{numtype}>x = x; ''', [True, True, True, True, True, True, True, True, True], ) await self.assert_query_result( f''' FOR x in <int64>{{ -9223372036854775808, -9223372036854775807, -4294967296, -65536, -100, 0, 13, 65536, 4294967296, 9223372036854775806, 9223372036854775807 }} SELECT <int64><{numtype}>x = x; ''', [True, True, True, True, True, True, True, True, True, True, True], )
, [True, True, True, True, True, True, True], ) await self.assert_query_result( # technically we're already casting a literal int64 # to int32 first f
test_edgeql_casts_numeric_01
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_numeric_02(self): # Casting to decimal and back should be lossless for any other # float type of low precision (a couple of digits less than # the maximum possible float precision). await self.assert_query_result( # technically we're already casting a literal int64 or # float64 to float32 first r''' FOR x in <float32>{-3.31234e+38, -1.234e+12, -1.234e-12, -100, 0, 13, 1.234e-12, 1.234e+12, 3.4e+38} SELECT <float32><decimal>x = x; ''', [True, True, True, True, True, True, True, True, True], ) await self.assert_query_result( r''' FOR x in <float64>{-1.61234e+308, -1.234e+42, -1.234e-42, -100, 0, 13, 1.234e-42, 1.234e+42, 1.7e+308} SELECT <float64><decimal>x = x; ''', [True, True, True, True, True, True, True, True, True], )
, [True, True, True, True, True, True, True, True, True], ) await self.assert_query_result( r
test_edgeql_casts_numeric_02
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_numeric_03(self): # It is especially dangerous to cast an int32 into float32 and # back because float32 cannot losslessly represent the entire # range of int32, but it can represent some of it, so no # obvious errors would be raised (as any int32 value is # technically withing valid range of float32), but the value # could be mangled. await self.assert_query_result( # ints <= 2^24 can be represented exactly in a float32 r''' FOR x in <int32>{16777216, 16777215, 16777214, 1677721, 167772, 16777} SELECT <int32><float32>x = x; ''', [True, True, True, True, True, True], ) await self.assert_query_result( # max int32 -100, -1000 r''' FOR x in <int32>{2147483548, 2147482648} SELECT <int32><float32>x = x; ''', [False, False], ) await self.assert_query_result( r''' FOR x in <int32>{2147483548, 2147482648} SELECT <int32><float32>x; ''', [2147483520, 2147482624], )
, [True, True, True, True, True, True], ) await self.assert_query_result( # max int32 -100, -1000 r
test_edgeql_casts_numeric_03
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_numeric_04(self): await self.assert_query_result( # ints <= 2^24 can be represented exactly in a float32 r''' FOR x in <int32>{16777216, 16777215, 16777214, 1677721, 167772, 16777} SELECT <int32><float64>x = x; ''', [True, True, True, True, True, True], ) await self.assert_query_result( # max int32 -1, -2, -3, -10, -100, -1000 r''' FOR x in <int32>{2147483647, 2147483646, 2147483645, 2147483638, 2147483548, 2147482648} SELECT <int32><float64>x = x; ''', [True, True, True, True, True, True], )
, [True, True, True, True, True, True], ) await self.assert_query_result( # max int32 -1, -2, -3, -10, -100, -1000 r
test_edgeql_casts_numeric_04
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_numeric_05(self): # Due to the sparseness of float values large integers may not # be representable exactly if they require better precision # than float provides. await self.assert_query_result( r''' # 2^31 -1, -2, -3, -10 FOR x in <int32>{2147483647, 2147483646, 2147483645, 2147483638} # 2147483647 is the max int32 SELECT x <= <int32>2147483647; ''', [True, True, True, True], ) async with self.assertRaisesRegexTx( edgedb.NumericOutOfRangeError, r"std::int32 out of range"): async with self.con.transaction(): await self.con.execute(""" SELECT <int32><float32><int32>2147483647; """) async with self.assertRaisesRegexTx( edgedb.NumericOutOfRangeError, r"std::int32 out of range"): async with self.con.transaction(): await self.con.execute(""" SELECT <int32><float32><int32>2147483646; """) async with self.assertRaisesRegexTx( edgedb.NumericOutOfRangeError, r"std::int32 out of range"): async with self.con.transaction(): await self.con.execute(""" SELECT <int32><float32><int32>2147483645; """) async with self.assertRaisesRegexTx( edgedb.NumericOutOfRangeError, r"std::int32 out of range"): async with self.con.transaction(): await self.con.execute(""" SELECT <int32><float32><int32>2147483638; """)
, [True, True, True, True], ) async with self.assertRaisesRegexTx( edgedb.NumericOutOfRangeError, r"std::int32 out of range"): async with self.con.transaction(): await self.con.execute(
test_edgeql_casts_numeric_05
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_collections_02(self): await self.assert_query_result( R''' WITH std AS MODULE math, foo := (SELECT [1, 2, 3]) SELECT <array<str>>foo; ''', [['1', '2', '3']], ) await self.assert_query_result( R''' WITH std AS MODULE math, foo := (SELECT [<int32>1, <int32>2, <int32>3]) SELECT <array<str>>foo; ''', [['1', '2', '3']], ) await self.assert_query_result( R''' WITH std AS MODULE math, foo := (SELECT [(1,), (2,), (3,)]) SELECT <array<tuple<str>>>foo; ''', [[['1'], ['2'], ['3']]], )
, [['1', '2', '3']], ) await self.assert_query_result( R
test_edgeql_casts_collections_02
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_json_11(self): await self.assert_query_result( r"SELECT <array<int64>><json>[1, 1, 2, 3, 5]", [[1, 1, 2, 3, 5]] ) # string to array async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'expected JSON array; got JSON string'): await self.con.query_single( r"SELECT <array<int64>><json>'asdf'") # array of string to array of int async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'array<std::int64>', " r"in array elements, " r"expected JSON number or null; got JSON string"): await self.con.query_single( r"SELECT <array<int64>><json>['asdf']") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'array<std::int64>', " r"in array elements, " r"expected JSON number or null; got JSON string"): await self.con.query_single( r"SELECT <array<int64>>to_json('[1, 2, \"asdf\"]')") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'array<std::int64>', " r"in array elements, " r"expected JSON number or null; got JSON string"): await self.con.execute(""" SELECT <array<int64>>to_json('["a"]'); """) # array with null to array async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'array<std::json>' " r"to 'array<std::int64>', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"SELECT <array<int64>>[to_json('1'), to_json('null')]") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"array<std::int64>', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"SELECT <array<int64>>to_json('[1, 2, null]')") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'array<std::json>' " r"to 'array<std::int64>', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"SELECT <array<int64>><array<json>>to_json('[1, 2, null]')") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<array<std::str>>', " r"at tuple element '0', " r"invalid null value in cast"): await self.con.query_single( r"select <tuple<array<str>>>to_json('[null]')") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<array<std::str>>', " r"at tuple element '0', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"select <tuple<array<str>>>to_json('[[null]]')") # object to array async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON array; got JSON object"): await self.con.execute(""" SELECT <array<int64>>to_json('{"a": 1}'); """) # array of object to array of scalar async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'array<std::int64>', " r"in array elements, " r"expected JSON number or null; got JSON object"): await self.con.execute(""" SELECT <array<int64>>to_json('[{"a": 1}]'); """) # nested array async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'array<tuple<array<std::str>>>', " r"in array elements, " r"at tuple element '0', " r"in array elements, " r"expected JSON string or null; got JSON number"): await self.con.execute(""" SELECT <array<tuple<array<str>>>>to_json('[[[1]]]'); """)
) # array with null to array async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'array<std::json>' " r"to 'array<std::int64>', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"SELECT <array<int64>>[to_json('1'), to_json('null')]") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"array<std::int64>', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"SELECT <array<int64>>to_json('[1, 2, null]')") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'array<std::json>' " r"to 'array<std::int64>', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"SELECT <array<int64>><array<json>>to_json('[1, 2, null]')") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<array<std::str>>', " r"at tuple element '0', " r"invalid null value in cast"): await self.con.query_single( r"select <tuple<array<str>>>to_json('[null]')") async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<array<std::str>>', " r"at tuple element '0', " r"in array elements, " r"invalid null value in cast"): await self.con.query_single( r"select <tuple<array<str>>>to_json('[[null]]')") # object to array async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON array; got JSON object"): await self.con.execute(
test_edgeql_casts_json_11
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_json_12(self): self.assertEqual( await self.con.query( r""" SELECT <tuple<a: int64, b: int64>> to_json('{"a": 1, "b": 2}') """ ), [edgedb.NamedTuple(a=1, b=2)], ) await self.assert_query_result( r""" SELECT <tuple<a: int64, b: int64>> to_json({'{"a": 3000, "b": -1}', '{"a": 1, "b": 12}'}); """, [{"a": 3000, "b": -1}, {"a": 1, "b": 12}], ) await self.assert_query_result( r""" SELECT <tuple<int64, int64>> to_json({'[3000, -1]', '[1, 12]'}) """, [[3000, -1], [1, 12]], ) self.assertEqual( await self.con.query( r""" SELECT <tuple<int64, int64>> to_json({'[3000, -1]', '[1, 12]'}) """ ), [(3000, -1), (1, 12)], ) self.assertEqual( await self.con.query( r""" SELECT <tuple<json, json>> to_json({'[3000, -1]', '[1, 12]'}) """ ), [('3000', '-1'), ('1', '12')], ) self.assertEqual( await self.con.query( r""" SELECT <tuple<json, json>> to_json({'[3000, -1]', '[1, null]'}) """ ), [('3000', '-1'), ('1', 'null')], ) self.assertEqual( await self.con.query_single( r""" SELECT <tuple<int64, tuple<a: int64, b: int64>>> to_json('[3000, {"a": 1, "b": 2}]') """ ), (3000, edgedb.NamedTuple(a=1, b=2)) ) self.assertEqual( await self.con.query_single( r""" SELECT <tuple<int64, array<tuple<a: int64, b: str>>>> to_json('[3000, [{"a": 1, "b": "foo"}, {"a": 12, "b": "bar"}]]') """ ), (3000, [edgedb.NamedTuple(a=1, b="foo"), edgedb.NamedTuple(a=12, b="bar")]) ) # object with wrong element type to tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: std::int64, b: std::int64>', " r"at tuple element 'b', " r"expected JSON number or null; got JSON string"): await self.con.query( r""" SELECT <tuple<a: int64, b: int64>> to_json('{"a": 1, "b": "2"}') """ ) # object with null value to tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: std::int64>', " r"at tuple element 'a', " r"invalid null value in cast"): await self.con.query( r"""SELECT <tuple<a: int64>>to_json('{"a": null}')""" ) # object with missing element to tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: std::int64, b: std::int64>', " r"at tuple element 'b', " r"missing value in JSON object"): await self.con.query( r"""SELECT <tuple<a: int64, b: int64>>to_json('{"a": 1}')""" ) # short array to unnamed tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<std::int64, std::int64>', " r"at tuple element '1', " r"missing value in JSON object"): await self.con.query( r"""SELECT <tuple<int64, int64>>to_json('[3000]')""" ) # array to named tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: std::int64, b: std::int64>', " r"at tuple element 'a', " r"missing value in JSON object"): await self.con.query( r""" SELECT <tuple<a: int64, b: int64>> to_json('[3000, 1000]') """ ) # string to tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r'expected JSON array or object or null; got JSON string'): await self.con.query( r"""SELECT <tuple<a: int64, b: int64>> to_json('"test"')""" ) # short array to unnamed tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<std::json, std::json>', " r"at tuple element '1', " r"missing value in JSON object"): await self.con.query( r"""SELECT <tuple<json, json>> to_json('[3000]')""" ) # object to unnamed tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' to " r"'tuple<std::int64>', " r"at tuple element '0', " r"missing value in JSON object"): await self.con.execute(""" SELECT <tuple<int64>>to_json('{"a": 1}'); """) # nested tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: tuple<b: std::str>>', " r"at tuple element 'a', " r"at tuple element 'b', " r"expected JSON string or null; got JSON number"): await self.con.execute(""" SELECT <tuple<a: tuple<b: str>>>to_json('{"a": {"b": 1}}'); """) # array with null to tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<std::int64, std::int64>', " r"at tuple element '1', " r"invalid null value in cast"): await self.con.execute(""" SELECT <tuple<int64, int64>>to_json('[1, null]'); """) # object with null to tuple async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: std::int64>', " r"at tuple element 'a', " r"invalid null value in cast"): await self.con.execute(""" SELECT <tuple<a: int64>>to_json('{"a": null}'); """) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: array<std::int64>>', " r"at tuple element 'a', " r"invalid null value in cast"): await self.con.execute(""" SELECT <tuple<a: array<int64>>>to_json('{"a": null}'); """) async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'tuple<a: tuple<b: std::str>>', " r"at tuple element 'a', " r"invalid null value in cast"): await self.con.execute(""" SELECT <tuple<a: tuple<b: str>>>to_json('{"a": null}'); """)
), [edgedb.NamedTuple(a=1, b=2)], ) await self.assert_query_result( r
test_edgeql_casts_json_12
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_json_14(self): await self.assert_query_result( r''' select <array<json>>to_json('[]') ''', [[]], ) await self.assert_query_result( r''' select <array<str>>to_json('[]') ''', [[]], )
, [[]], ) await self.assert_query_result( r
test_edgeql_casts_json_14
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_json_16(self): # number to range async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON object or null; got JSON number"): await self.con.execute(""" SELECT <range<int64>>to_json('1'); """) # array to range async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON object or null; got JSON array"): await self.con.execute(""" SELECT <range<int64>>to_json('[1]'); """) # object to range, bad empty async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'range<std::int64>', " r"in range parameter 'empty', " r"expected JSON boolean or null; got JSON number"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "empty": 1 }'); """) # object to range, empty with distinct lower and upper async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"conflicting arguments in range constructor: 'empty' is " r"`true` while the specified bounds suggest otherwise"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "empty": true, "lower": 1, "upper": 2 }'); """) # object to range, empty with same lower and upper # and inc_lower and inc_upper async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"conflicting arguments in range constructor: 'empty' is " r"`true` while the specified bounds suggest otherwise"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "empty": true, "lower": 1, "upper": 2, "inc_lower": true, "inc_upper": true }'); """) # object to range, missing inc_lower async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"JSON object representing a range must include an " r"'inc_lower'"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "inc_upper": false }'); """) # object to range, missing inc_upper async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"JSON object representing a range must include an " r"'inc_upper'"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "inc_lower": false }'); """) # object to range, bad inc_lower async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'range<std::int64>', " r"in range parameter 'inc_lower', " r"expected JSON boolean or null; got JSON number"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "inc_lower": 1, "inc_upper": false }'); """) # object to range, bad inc_upper async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"while casting 'std::json' " r"to 'range<std::int64>', " r"in range parameter 'inc_upper', " r"expected JSON boolean or null; got JSON number"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "inc_lower": false, "inc_upper": 1 }'); """) # object to range, extra parameters async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"JSON object representing a range contains unexpected keys: " r"bar, foo"): await self.con.execute(""" SELECT <range<int64>>to_json('{ "lower": 1, "upper": 2, "inc_lower": true, "inc_upper": true, "foo": "foo", "bar": "bar" }'); """)
) # array to range async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON object or null; got JSON array"): await self.con.execute(
test_edgeql_casts_json_16
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_json_17(self): # number to multirange async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON array; got JSON number"): await self.con.execute(""" SELECT <multirange<int64>>to_json('1'); """) # object to multirange async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON array; got JSON object"): await self.con.execute(""" SELECT <multirange<int64>>to_json('{"a": 1}'); """)
) # object to multirange async with self.assertRaisesRegexTx( edgedb.InvalidValueError, r"expected JSON array; got JSON object"): await self.con.execute(
test_edgeql_casts_json_17
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_assignment_03(self): async with self._run_and_rollback(): # in particular, bigint and decimal are not assignment-castable # into any other numeric type for typename in ['int16', 'int32', 'int64', 'float32', 'float64']: for numtype in {'bigint', 'decimal'}: query = f''' INSERT ScalarTest {{ p_{typename} := <{numtype}>3, p_{numtype} := 1001, }}; ''' async with self.assertRaisesRegexTx( edgedb.QueryError, r'invalid target for property', msg=query): await self.con.execute(query + f''' # clean up, so other tests can proceed DELETE ( SELECT ScalarTest FILTER .p_{numtype} = 1001 ); ''')
async with self.assertRaisesRegexTx( edgedb.QueryError, r'invalid target for property', msg=query): await self.con.execute(query + f
test_edgeql_casts_assignment_03
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0
async def test_edgeql_casts_custom_scalar_02(self): await self.assert_query_result( """ SELECT <foo><bar>'test' """, ['test'], ) await self.assert_query_result( """ SELECT <array<foo>><array<bar>>['test'] """, [['test']], )
SELECT <foo><bar>'test' """, ['test'], ) await self.assert_query_result(
test_edgeql_casts_custom_scalar_02
python
geldata/gel
tests/test_edgeql_casts.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py
Apache-2.0