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
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def test_edgeql_select_interpreter_not_05(self):
# testing double negation
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],
},
],
)
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],
},
],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_not_05 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_empty_02(self):
self.assert_query_result(
r"""
# Test short-circuiting operations with empty
SELECT Issue.number = '1' OR <bool>{};
""",
[],
)
self.assert_query_result(
r"""
SELECT Issue.number = 'X' OR <bool>{};
""",
[],
)
self.assert_query_result(
r"""
SELECT Issue.number = '1' AND <bool>{};
""",
[],
)
self.assert_query_result(
r"""
SELECT Issue.number = 'X' AND <bool>{};
""",
[],
) | ,
[],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_empty_02 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_empty_03(self):
self.assert_query_result(
r"""
# Test short-circuiting operations with empty
SELECT count(Issue.number = '1' OR <bool>{});
""",
[0],
)
self.assert_query_result(
r"""
SELECT count(Issue.number = 'X' OR <bool>{});
""",
[0],
)
self.assert_query_result(
r"""
SELECT count(Issue.number = '1' AND <bool>{});
""",
[0],
)
self.assert_query_result(
r"""
SELECT count(Issue.number = 'X' AND <bool>{});
""",
[0],
) | ,
[0],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_empty_03 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_cross_07(self):
self.assert_query_result(
r"""
SELECT _ := count(Issue.owner.name ++ Issue.watchers.name);
""",
[3],
)
self.assert_query_result(
r"""
SELECT _ := count(DISTINCT (
Issue.owner.name ++ Issue.watchers.name));
""",
[2],
) | ,
[3],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_cross_07 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_cross_13(self):
self.assert_query_result(
r"""
SELECT count(count(Issue.watchers));
""",
[1],
)
self.assert_query_result(
r"""
SELECT count(
(Issue, count(Issue.watchers))
);
""",
[4],
) | ,
[1],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_cross_13 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_subqueries_18(self):
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'},
)
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'},
)
self.assert_query_result(
r | test_edgeql_select_interpreter_subqueries_18 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_slice_01(self):
self.assert_query_result(
r"""
# full name of the Issue is 'Release EdgeDB'
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[2];
""",
['l'],
)
self.assert_query_result(
r"""
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[-2];
""",
['D'],
)
self.assert_query_result(
r"""
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[2:4];
""",
['le'],
)
self.assert_query_result(
r"""
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[2:];
""",
['lease EdgeDB'],
)
self.assert_query_result(
r"""
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[:2];
""",
['Re'],
)
self.assert_query_result(
r"""
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[2:-1];
""",
['lease EdgeD'],
)
self.assert_query_result(
r"""
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[-2:];
""",
['DB'],
)
self.assert_query_result(
r"""
SELECT (
SELECT Issue
FILTER Issue.number = '1'
).name[:-2];
""",
['Release Edge'],
) | ,
['l'],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_slice_01 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_slice_04(self):
self.assert_query_result(
r"""
select [1,2,3,4,5][1:];
""",
[[2, 3, 4, 5]],
)
self.assert_query_result(
r"""
select [1,2,3,4,5][:3];
""",
[[1, 2, 3]],
)
self.assert_query_result(
r"""
select [1,2,3][1:<int64>{}];
""",
[],
)
# try to trick the compiler and to pass NULL into edgedb._slice
self.assert_query_result(
r"""
select [1,2,3][1:<optional int64>$0];
""",
[],
variables=(None,),
)
self.assert_query_result(
r"""
select [1,2,3][<optional int64>$0:2];
""",
[],
variables=(None,),
)
self.assert_query_result(
r"""
select [1,2,3][<optional int64>$0:<optional int64>$1];
""",
[],
variables=(
None,
None,
),
)
self.assertEqual(
self.execute(
r"""
select to_json('[true, 3, 4, null]')[1:];
"""
),
edgedb.Set(('[3, 4, null]',)),
)
self.assertEqual(
self.execute(
r"""
select to_json('[true, 3, 4, null]')[:2];
"""
),
edgedb.Set(('[true, 3]',)),
)
self.assert_query_result(
r"""
select (<optional json>$0)[2:];
""",
[],
variables=(None,),
)
self.assertEqual(
self.execute(
r"""
select to_json('"hello world"')[2:];
"""
),
edgedb.Set(('"llo world"',)),
)
self.assertEqual(
self.execute(
r"""
select to_json('"hello world"')[:4];
"""
),
edgedb.Set(('"hell"',)),
)
self.assert_query_result(
r"""
select (<array<str>>[])[0:];
""",
[[]],
)
self.assert_query_result(
r'''select to_json('[]')[0:];''',
# JSON:
[[]],
# Binary:
['[]'],
)
self.assert_query_result(
r'''select [(1,'foo'), (2,'bar'), (3,'baz')][1:];''',
[[(2, 'bar'), (3, 'baz')]],
)
self.assert_query_result(
r'''select [(1,'foo'), (2,'bar'), (3,'baz')][:2];''',
[[(1, 'foo'), (2, 'bar')]],
)
self.assert_query_result(
r'''select [(1,'foo'), (2,'bar'), (3,'baz')][1:2];''',
[[(2, 'bar')]],
)
self.assert_query_result(
r'''
select [(1,'foo'), (2,'bar'), (3,'baz')][<optional int64>$0:];
''',
[],
variables=(None,),
)
self.assert_query_result(
r'''
select (<optional array<int32>>$0)[2];
''',
[],
variables=(None,),
)
self.assert_query_result(
r'''
select (<optional str>$0)[2];
''',
[],
variables=(None,),
)
self.assert_query_result(
r'''
select to_json(<optional str>$0)[2];
''',
[],
variables=(None,),
)
self.assert_query_result(
r'''
select (<optional array<int32>>$0)[1:2];
''',
[],
variables=(None,),
)
self.assert_query_result(
r'''
select (<optional str>$0)[1:2];
''',
[],
variables=(None,),
)
self.assert_query_result(
r'''
select to_json(<optional str>$0)[1:2];
''',
[],
variables=(None,),
) | ,
[[2, 3, 4, 5]],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_slice_04 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_tuple_10(self):
# Tuple comparison
self.assert_query_result(
r"""
WITH
U1 := User,
U2 := User
SELECT
(user := (SELECT U1{name} FILTER U1.name = 'Yury'))
=
(user := (SELECT U2{name} FILTER U2.name = 'Yury'));
""",
[True],
)
self.assert_query_result(
r"""
WITH
U1 := User,
U2 := User
SELECT
(user := (SELECT U1{name} FILTER U1.name = 'Yury'))
=
(user := (SELECT U2{name} FILTER U2.name = 'Elvis'));
""",
[False],
) | ,
[True],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_tuple_10 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_if_else_04(self):
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'},
],
)
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'},
],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_if_else_04 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_if_else_05(self):
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'}],
)
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'}],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_if_else_05 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_if_else_06(self):
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': '1'}, {'number': '3'}, {'number': '4'}],
)
self.assert_query_result(
r"""
# Above IF is equivalent to !?=,
SELECT Issue {number}
FILTER
Issue.priority.name ?!= 'High'
ORDER BY Issue.number;
""",
[{'number': '1'}, {'number': '3'}, {'number': '4'}],
) | ,
[{'number': '1'}, {'number': '3'}, {'number': '4'}],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_if_else_06 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_union_target_01(self):
self.assert_query_result(
r'''
SELECT Issue {
number,
} FILTER EXISTS (.references)
ORDER BY .number DESC;
''',
[{'number': '2'}],
)
self.assert_query_result(
r'''
SELECT Issue {
number,
} FILTER .references[IS URL].address = 'https://edgedb.com'
ORDER BY .number DESC;
''',
[{'number': '2'}],
)
self.assert_query_result(
r'''
SELECT Issue {
number,
} FILTER .references[IS Named].name = 'screenshot.png'
ORDER BY .number DESC;
''',
[{'number': '2'}],
) | ,
[{'number': '2'}],
)
self.assert_query_result(
r | test_edgeql_union_target_01 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_json_01(self):
self.assert_query_result(
r'''
# cast a type variant into a set of json
SELECT (
SELECT <json>Issue {
number,
time_estimate
} FILTER Issue.number = '1'
) = to_json('{"number": "1", "time_estimate": 3000}');
''',
[True],
)
self.assert_query_result(
r'''
SELECT (
SELECT <json>Issue {
number,
time_estimate
} FILTER Issue.number = '2'
) = to_json('{"number": "2", "time_estimate": null}');
''',
[True],
) | ,
[True],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_json_01 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_precedence_03(self):
self.assert_query_result(
r'''
SELECT (<str>1)[0];
''',
['1'],
)
self.assert_query_result(
r'''
SELECT (<str>Issue.time_estimate)[0];
''',
['3'],
) | ,
['1'],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_precedence_03 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_precedence_04(self):
self.assert_query_result(
r'''
SELECT EXISTS Issue{number};
''',
[True],
)
self.assert_query_result(
r'''
SELECT EXISTS Issue;
''',
[True],
) | ,
[True],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_precedence_04 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_big_set_literal(self):
res = self.execute(
"""
SELECT {
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
};
"""
)
assert len(res) == 100 | SELECT {
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,),
}; | test_edgeql_select_interpreter_big_set_literal | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_big_unions(self):
res = self.execute(
"""
SELECT (
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,)
);
"""
)
assert len(res) == 100 | SELECT (
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,) union
(1,) union (1,) union (1,) union (1,) union (1,)
); | test_edgeql_select_interpreter_big_unions | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_expr_objects_04(self):
self.assert_query_result(
r'''
WITH items := array_agg((SELECT Named ORDER BY .name))
SELECT items[0] IS Status;
''',
[True],
)
self.assert_query_result(
r'''
WITH items := array_agg((
SELECT Named ORDER BY .name LIMIT 1))
SELECT (items, items[0], items[0].name,
items[0] IS Status);
''',
[[[{}], {}, "Closed", True]],
)
self.assert_query_result(
r'''
WITH items := (User.name, array_agg(User.todo ORDER BY .name))
SELECT _ := (items.0, items.1, items.1[0].name) ORDER BY _.0;
''',
[
["Elvis", [{}, {}], "Improve EdgeDB repl output rendering."],
["Yury", [{}, {}], "Regression."],
],
) | ,
[True],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_expr_objects_04 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_expr_objects_07(self):
# get the User names and ids
res = self.execute(
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!
self.assert_query_result(
r'''
WITH
L := ('x', User),
SELECT _ := (L, L.1 {name})
ORDER BY _.1.name;
''',
[
[['x', {'id': (user['id'])}], {'name': user['name']}]
for user in res
],
)
self.assert_query_result(
r'''
WITH
L := ('x', User),
SELECT _ := (L.1 {name}, L)
ORDER BY _.0.name;
''',
[
[{'name': user['name']}, ['x', {'id': (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!
self.assert_query_result(
r | test_edgeql_select_interpreter_expr_objects_07 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_expr_objects_08(self):
self.assert_query_result(
r'''
SELECT DISTINCT
[(SELECT Issue {number, name} FILTER .number = "1")];
''',
[
[{'number': '1', 'name': 'Release EdgeDB'}],
],
)
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'}],
],
)
self.assert_query_result(
r | test_edgeql_select_interpreter_expr_objects_08 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_banned_free_shape_01(self):
self.execute(
"""
SELECT DISTINCT {{ z := 1 }, { z := 2 }};
"""
)
self.execute(
"""
SELECT DISTINCT { z := 1 } = { z := 2 };
"""
) | SELECT DISTINCT {{ z := 1 }, { z := 2 }}; | test_edgeql_select_interpreter_banned_free_shape_01 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_collection_shape_01(self):
self.assert_query_result(
r'''
SELECT <array<User>>{} UNION [User]
''',
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r'''
SELECT <array<User>>{} ?? [User]
''',
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r'''
SELECT <array<User>>{} IF false ELSE [User]
''',
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r'''
SELECT assert_exists([User])
''',
[[{"id": str}], [{"id": str}]],
) | ,
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r | test_edgeql_collection_shape_01 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_collection_shape_02(self):
self.assert_query_result(
r'''
SELECT <array<User>>{} UNION array_agg(User)
''',
[[{"id": str}, {"id": str}]],
)
self.assert_query_result(
r'''
SELECT <array<User>>{} ?? array_agg(User)
''',
[[{"id": str}, {"id": str}]],
)
self.assert_query_result(
r'''
SELECT <array<User>>{} IF false ELSE array_agg(User)
''',
[[{"id": str}, {"id": str}]],
)
self.assert_query_result(
r'''
SELECT assert_exists(array_agg(User))
''',
[[{"id": str}, {"id": str}]],
) | ,
[[{"id": str}, {"id": str}]],
)
self.assert_query_result(
r | test_edgeql_collection_shape_02 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_collection_shape_03(self):
self.assert_query_result(
r'''
SELECT <tuple<User, int64>>{} UNION (User, 2)
''',
[[{"id": str}, 2], [{"id": str}, 2]],
)
self.assert_query_result(
r'''
SELECT <tuple<User, int64>>{} ?? (User, 2)
''',
[[{"id": str}, 2], [{"id": str}, 2]],
)
self.assert_query_result(
r'''
SELECT <tuple<User, int64>>{} IF false ELSE (User, 2)
''',
[[{"id": str}, 2], [{"id": str}, 2]],
)
self.assert_query_result(
r'''
SELECT assert_exists((User, 2))
''',
[[{"id": str}, 2], [{"id": str}, 2]],
) | ,
[[{"id": str}, 2], [{"id": str}, 2]],
)
self.assert_query_result(
r | test_edgeql_collection_shape_03 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_collection_shape_04(self):
self.assert_query_result(
r'''
SELECT [(User,)][0]
''',
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r'''
SELECT [((SELECT User {name} ORDER BY .name),)][0]
''',
[[{"name": "Elvis"}], [{"name": "Yury"}]],
) | ,
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r | test_edgeql_collection_shape_04 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_collection_shape_05(self):
self.assert_query_result(
r'''
SELECT ([User],).0
''',
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r'''
SELECT ([(SELECT User {name} ORDER BY .name)],).0
''',
[[{"name": "Elvis"}], [{"name": "Yury"}]],
) | ,
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r | test_edgeql_collection_shape_05 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_collection_shape_07(self):
self.assert_query_result(
r'''
WITH Z := (<array<User>>{} IF false ELSE [User]),
SELECT (Z, array_agg(array_unpack(Z))).1;
''',
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r'''
WITH Z := (SELECT assert_exists([User]))
SELECT (Z, array_agg(array_unpack(Z))).1;
''',
[[{"id": str}], [{"id": str}]],
) | ,
[[{"id": str}], [{"id": str}]],
)
self.assert_query_result(
r | test_edgeql_collection_shape_07 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_collection_shape_08(self):
self.assert_query_result(
r'''
SELECT X := array_agg(User) FILTER X[0].name != 'Sully';
''',
[[{"id": str}, {"id": str}]],
)
self.assert_query_result(
r'''
SELECT X := [User] FILTER X[0].name = 'Elvis';
''',
[[{"id": str}]],
) | ,
[[{"id": str}, {"id": str}]],
)
self.assert_query_result(
r | test_edgeql_collection_shape_08 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_assert_fail_object_computed_02(self):
# Publication is empty, and so
with self.assertRaisesRegex(
edgedb.InvalidValueError,
"array index 1000 is out of bounds",
):
self.execute(
"""
SELECT array_agg((SELECT User {m := Publication}))[{1000}].m;
"""
) | SELECT array_agg((SELECT User {m := Publication}))[{1000}].m; | test_edgeql_assert_fail_object_computed_02 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
def test_edgeql_select_interpreter_card_blowup_01(self):
# This used to really blow up cardinality inference
self.execute(
'''
SELECT Comment {
issue := assert_exists(( .issue {
status1 := ( .status { a := .__type__.name, b := .__type__.id } ),
status2 := ( .status { a := .__type__.name, b := .__type__.id } ),
status3 := ( .status { a := .__type__.name, b := .__type__.id } ),
status4 := ( .status { a := .__type__.name, b := .__type__.id } ),
status5 := ( .status { a := .__type__.name, b := .__type__.id } ),
status6 := ( .status { a := .__type__.name, b := .__type__.id } ),
status7 := ( .status { a := .__type__.name, b := .__type__.id } ),
status8 := ( .status { a := .__type__.name, b := .__type__.id } ),
})),
};
'''
) | SELECT Comment {
issue := assert_exists(( .issue {
status1 := ( .status { a := .__type__.name, b := .__type__.id } ),
status2 := ( .status { a := .__type__.name, b := .__type__.id } ),
status3 := ( .status { a := .__type__.name, b := .__type__.id } ),
status4 := ( .status { a := .__type__.name, b := .__type__.id } ),
status5 := ( .status { a := .__type__.name, b := .__type__.id } ),
status6 := ( .status { a := .__type__.name, b := .__type__.id } ),
status7 := ( .status { a := .__type__.name, b := .__type__.id } ),
status8 := ( .status { a := .__type__.name, b := .__type__.id } ),
})),
}; | test_edgeql_select_interpreter_card_blowup_01 | python | geldata/gel | tests/test_edgeql_select_interpreter.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_select_interpreter.py | Apache-2.0 |
async def test_edgeql_delete_simple_01(self):
# ensure a clean slate, not part of functionality testing
await self.con.execute(r"""
DELETE DeleteTest;
""")
await self.con.execute(r"""
INSERT DeleteTest {
name := 'delete-test'
};
""")
await self.assert_query_result(
r"""
SELECT DeleteTest;
""",
[{}],
)
await self.con.execute(r"""
DELETE DeleteTest;
""")
await self.assert_query_result(
r"""
SELECT DeleteTest;
""",
[],
) | )
await self.con.execute(r | test_edgeql_delete_simple_01 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_simple_02(self):
id1 = str((await self.con.query_single(r"""
SELECT(INSERT DeleteTest {
name := 'delete-test1'
}) LIMIT 1;
""")).id)
id2 = str((await self.con.query_single(r"""
SELECT(INSERT DeleteTest {
name := 'delete-test2'
}) LIMIT 1;
""")).id)
await self.assert_query_result(
r"""
DELETE (SELECT DeleteTest
FILTER DeleteTest.name = 'bad name');
""",
[],
)
await self.assert_query_result(
r"""
SELECT DeleteTest ORDER BY DeleteTest.name;
""",
[{'id': id1}, {'id': id2}],
)
await self.assert_query_result(
r"""
SELECT (DELETE (SELECT DeleteTest
FILTER DeleteTest.name = 'delete-test1'));
""",
[{'id': id1}],
)
await self.assert_query_result(
r"""
SELECT DeleteTest ORDER BY DeleteTest.name;
""",
[{'id': id2}],
)
await self.assert_query_result(
r"""
SELECT (DELETE (SELECT DeleteTest
FILTER DeleteTest.name = 'delete-test2'));
""",
[{'id': id2}],
)
await self.assert_query_result(
r"""
SELECT DeleteTest ORDER BY DeleteTest.name;
""",
[],
) | )).id)
id2 = str((await self.con.query_single(r | test_edgeql_delete_simple_02 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_returning_01(self):
id1 = str((await self.con.query_single(r"""
SELECT (INSERT DeleteTest {
name := 'delete-test1'
}) LIMIT 1;
""")).id)
await self.con.execute(r"""
INSERT DeleteTest {
name := 'delete-test2'
};
INSERT DeleteTest {
name := 'delete-test3'
};
""")
await self.assert_query_result(
r"""
SELECT (DELETE DeleteTest
FILTER DeleteTest.name = 'delete-test1');
""",
[{'id': id1}],
)
await self.assert_query_result(
r"""
WITH
D := (DELETE DeleteTest
FILTER DeleteTest.name = 'delete-test2')
SELECT D {name};
""",
[{'name': 'delete-test2'}],
)
await self.assert_query_result(
r"""
SELECT
(DELETE DeleteTest
FILTER DeleteTest.name = 'delete-test3'
).name ++ '--DELETED';
""",
['delete-test3--DELETED'],
) | )).id)
await self.con.execute(r | test_edgeql_delete_returning_01 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_returning_02(self):
await self.con.execute(r"""
INSERT DeleteTest {
name := 'delete-test1'
};
INSERT DeleteTest {
name := 'delete-test2'
};
INSERT DeleteTest {
name := 'delete-test3'
};
""")
await self.assert_query_result(
r"""
WITH D := (DELETE DeleteTest)
SELECT count(D);
""",
[3],
) | )
await self.assert_query_result(
r | test_edgeql_delete_returning_02 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_returning_03(self):
await self.con.execute(r"""
INSERT DeleteTest {
name := 'dt1.1'
};
INSERT DeleteTest {
name := 'dt1.2'
};
INSERT DeleteTest {
name := 'dt1.3'
};
# create a different object
INSERT DeleteTest2 {
name := 'dt2.1'
};
INSERT DeleteTest2 {
name := 'delete test2.2'
};
""")
await self.assert_query_result(
r"""
WITH
D := (DELETE DeleteTest)
SELECT DeleteTest2 {
name,
foo := 'bar'
} FILTER any(DeleteTest2.name LIKE D.name[:2] ++ '%');
""",
[{
'name': 'dt2.1',
'foo': 'bar',
}],
)
deleted = await self.con._fetchall(
r"""
DELETE DeleteTest2;
""",
__typeids__=True,
__typenames__=True
)
self.assertTrue(hasattr(deleted[0], '__tid__'))
self.assertEqual(deleted[0].__tname__, 'default::DeleteTest2') | )
await self.assert_query_result(
r | test_edgeql_delete_returning_03 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_returning_04(self):
await self.con.execute(r"""
INSERT DeleteTest {
name := 'dt1.1'
};
INSERT DeleteTest {
name := 'dt1.2'
};
INSERT DeleteTest {
name := 'dt1.3'
};
# create a different object
INSERT DeleteTest2 {
name := 'dt2.1'
};
""")
await self.assert_query_result(
r"""
WITH
# make sure that aliased deletion works as an expression
#
Q := (DELETE DeleteTest)
SELECT DeleteTest2 {
name,
count := count(Q),
} FILTER DeleteTest2.name = 'dt2.1';
""",
[{
'name': 'dt2.1',
'count': 3,
}],
)
await self.assert_query_result(
r"""
SELECT (DELETE DeleteTest2) {name};
""",
[{
'name': 'dt2.1',
}],
) | )
await self.assert_query_result(
r | test_edgeql_delete_returning_04 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_returning_05(self):
await self.con.execute(r"""
INSERT DeleteTest {
name := 'dt1.1'
};
INSERT DeleteTest {
name := 'dt1.2'
};
INSERT DeleteTest {
name := 'dt1.3'
};
# create a different object
INSERT DeleteTest2 {
name := 'dt2.1'
};
""")
await self.assert_query_result(
r"""
WITH
D := (DELETE DeleteTest)
# the returning clause is actually trying to simulate
# returning "stats" of deleted objects
#
SELECT DeleteTest2 {
name,
count := count(D),
} FILTER DeleteTest2.name = 'dt2.1';
""",
[{
'name': 'dt2.1',
'count': 3
}],
)
await self.assert_query_result(
r"""
SELECT (DELETE DeleteTest2) {name};
""",
[{
'name': 'dt2.1',
}],
) | )
await self.assert_query_result(
r | test_edgeql_delete_returning_05 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_sugar_01(self):
await self.con.execute(r"""
FOR x IN {'1', '2', '3', '4', '5', '6'}
UNION (INSERT DeleteTest {
name := 'sugar delete ' ++ x
});
""")
await self.con.execute(r"""
DELETE
DeleteTest
FILTER
.name[-1] != '2'
ORDER BY .name
OFFSET 2 LIMIT 2;
# should delete 4 and 5
""")
await self.assert_query_result(
r"""
SELECT DeleteTest.name;
""",
{
'sugar delete 1',
'sugar delete 2',
'sugar delete 3',
'sugar delete 6',
},
) | )
await self.con.execute(r | test_edgeql_delete_sugar_01 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_union(self):
await self.con.execute(r"""
FOR x IN {'1', '2', '3', '4', '5', '6'}
UNION (INSERT DeleteTest {
name := 'delete union ' ++ x
});
FOR x IN {'7', '8', '9'}
UNION (INSERT DeleteTest2 {
name := 'delete union ' ++ x
});
INSERT DeleteTest { name := 'not delete union 1' };
INSERT DeleteTest2 { name := 'not delete union 2' };
""")
await self.con.execute(r"""
WITH
ToDelete := (
(SELECT DeleteTest FILTER .name ILIKE 'delete union%')
UNION
(SELECT DeleteTest2 FILTER .name ILIKE 'delete union%')
)
DELETE ToDelete;
""")
await self.assert_query_result(
r"""
SELECT
DeleteTest
FILTER
.name ILIKE 'delete union%';
""",
[],
)
await self.assert_query_result(
r"""
SELECT
DeleteTest {name}
FILTER
.name ILIKE 'not delete union%';
""",
[{
'name': 'not delete union 1'
}],
)
await self.assert_query_result(
r"""
SELECT
DeleteTest2
FILTER
.name ILIKE 'delete union%';
""",
[],
)
await self.assert_query_result(
r"""
SELECT
DeleteTest2 {name}
FILTER
.name ILIKE 'not delete union%';
""",
[{
'name': 'not delete union 2'
}],
) | )
await self.con.execute(r | test_edgeql_delete_union | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_abstract_01(self):
await self.con.execute(r"""
INSERT DeleteTest { name := 'child of abstract 1' };
INSERT DeleteTest2 { name := 'child of abstract 2' };
""")
await self.assert_query_result(
r"""
WITH
D := (
DELETE
AbstractDeleteTest
FILTER
.name ILIKE 'child of abstract%'
)
SELECT D { name } ORDER BY .name;
""",
[{
'name': 'child of abstract 1'
}, {
'name': 'child of abstract 2'
}],
) | )
await self.assert_query_result(
r | test_edgeql_delete_abstract_01 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_assert_exists(self):
await self.con.execute(r"""
INSERT DeleteTest2 { name := 'x' };
""")
await self.assert_query_result(
r"""
select assert_exists((delete DeleteTest2 filter .name = 'x'));
""",
[{}],
) | )
await self.assert_query_result(
r | test_edgeql_delete_assert_exists | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_then_union(self):
await self.con.execute(r"""
INSERT DeleteTest2 { name := 'x' };
INSERT DeleteTest2 { name := 'y' };
""")
await self.assert_query_result(
r"""
with
delete1 := assert_exists((delete DeleteTest2 filter .name = 'x')),
delete2 := assert_exists((delete DeleteTest2 filter .name = 'y')),
select {delete1, delete2};
""",
[{}, {}],
) | )
await self.assert_query_result(
r | test_edgeql_delete_then_union | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_multi_simultaneous_01(self):
await self.con.execute(r"""
with
a := (insert DeleteTest { name := '1' }),
b := (insert DeleteTest { name := '2' }),
c := (insert LinkingType { objs := {a, b} })
select c;
""")
dels = {
'a': '(DELETE DeleteTest)',
'b': '(DELETE LinkingType)',
}
# We want to try all the different permutations of deletion
# binding order and order that the variables are referenced in
# the body. (Somewhat upsettingly, the order that the delete CTEs
# are included into the SQL union affected the behavior.)
# All the queries look like some variant on:
#
# with
# a := (DELETE DeleteTest),
# b := (DELETE LinkingType),
# select {a, b};
for binds, uses in itertools.product(
list(itertools.permutations(dels.keys())),
list(itertools.permutations(dels.keys())),
):
bind_q = '\n'.join(
' ' * 18 + f'{k} := {dels[k]},' for k in binds
).lstrip()
q = f'''
with
{bind_q}
select {{{', '.join(uses)}}};
'''
async with self._run_and_rollback():
with self.annotate(binds=binds, uses=uses):
await self.con.execute(q) | )
dels = {
'a': '(DELETE DeleteTest)',
'b': '(DELETE LinkingType)',
}
# We want to try all the different permutations of deletion
# binding order and order that the variables are referenced in
# the body. (Somewhat upsettingly, the order that the delete CTEs
# are included into the SQL union affected the behavior.)
# All the queries look like some variant on:
#
# with
# a := (DELETE DeleteTest),
# b := (DELETE LinkingType),
# select {a, b};
for binds, uses in itertools.product(
list(itertools.permutations(dels.keys())),
list(itertools.permutations(dels.keys())),
):
bind_q = '\n'.join(
' ' * 18 + f'{k} := {dels[k]},' for k in binds
).lstrip()
q = f | test_edgeql_delete_multi_simultaneous_01 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_multi_simultaneous_02(self):
populate = r"""
with
a := (insert DeleteTest { name := '1' }),
b := (insert DeleteTest2 { name := '2' }),
c := (insert LinkingType { objs := {a, b} })
select c;
"""
await self.con.execute(populate)
await self.con.execute(r"""
with
a := (DELETE AbstractDeleteTest),
b := (DELETE LinkingType),
select {a, b};
""")
await self.con.execute(populate)
await self.con.execute(r"""
with
a := (DELETE AbstractDeleteTest),
b := (DELETE LinkingType),
select {b, a};
""") | await self.con.execute(populate)
await self.con.execute(r | test_edgeql_delete_multi_simultaneous_02 | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_delete_where_order_dml(self):
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"INSERT statements cannot be used in a FILTER clause"):
await self.con.query('''
delete DeleteTest
filter
(INSERT DeleteTest {
name := 't1',
})
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"UPDATE statements cannot be used in a FILTER clause"):
await self.con.query('''
delete DeleteTest
filter
(UPDATE DeleteTest set {
name := 't1',
})
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"DELETE statements cannot be used in a FILTER clause"):
await self.con.query('''
delete DeleteTest
filter
(DELETE DeleteTest filter .name = 't1')
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"INSERT statements cannot be used in an ORDER BY clause"):
await self.con.query('''
delete DeleteTest
order by
(INSERT DeleteTest {
name := 't1',
})
limit 1
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"UPDATE statements cannot be used in an ORDER BY clause"):
await self.con.query('''
delete DeleteTest
order by
(UPDATE DeleteTest set {
name := 't1',
})
limit 1
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"DELETE statements cannot be used in an ORDER BY clause"):
await self.con.query('''
delete DeleteTest
order by
(DELETE DeleteTest filter .name = 't1')
limit 1
''') | )
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"UPDATE statements cannot be used in a FILTER clause"):
await self.con.query( | test_edgeql_delete_where_order_dml | python | geldata/gel | tests/test_edgeql_delete.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_delete.py | Apache-2.0 |
async def test_edgeql_enums_cast_05(self):
await self.con.execute(
r'''
INSERT Foo {
color := 'BLUE'
};
''')
await self.assert_query_result(
r'''
SELECT 'The test color is: ' ++ <str>Foo.color;
''',
['The test color is: BLUE'],
) | )
await self.assert_query_result(
r | test_edgeql_enums_cast_05 | python | geldata/gel | tests/test_edgeql_enums.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_enums.py | Apache-2.0 |
async def test_edgeql_enums_pathsyntax_02(self):
await self.assert_query_result(
r'''
SELECT color_enum_t.GREEN;
''',
{'GREEN'},
)
await self.assert_query_result(
r'''
SELECT default::color_enum_t.BLUE;
''',
{'BLUE'},
)
await self.assert_query_result(
r'''
WITH x := default::color_enum_t.RED SELECT x;
''',
{'RED'},
) | ,
{'GREEN'},
)
await self.assert_query_result(
r | test_edgeql_enums_pathsyntax_02 | python | geldata/gel | tests/test_edgeql_enums.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_enums.py | Apache-2.0 |
async def test_edgeql_enums_assignment_01(self):
# testing the INSERT assignment cast
await self.con.execute(
r'''
INSERT Foo {
color := 'RED'
};
''')
await self.assert_query_result(
r'''
SELECT Foo {
color
};
''',
[{
'color': 'RED',
}],
) | )
await self.assert_query_result(
r | test_edgeql_enums_assignment_01 | python | geldata/gel | tests/test_edgeql_enums.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_enums.py | Apache-2.0 |
async def test_edgeql_enums_assignment_02(self):
await self.con.execute(
r'''
INSERT Foo {
color := 'RED'
};
''')
# testing the UPDATE assignment cast
await self.con.execute(
r'''
UPDATE Foo
SET {
color := 'GREEN'
};
''')
await self.assert_query_result(
r'''
SELECT Foo {
color
};
''',
[{
'color': 'GREEN',
}],
) | )
# testing the UPDATE assignment cast
await self.con.execute(
r | test_edgeql_enums_assignment_02 | python | geldata/gel | tests/test_edgeql_enums.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_enums.py | Apache-2.0 |
async def test_edgeql_enums_assignment_03(self):
# testing the INSERT assignment cast
await self.con.execute(
r'''
INSERT Bar;
''')
await self.assert_query_result(
r'''
SELECT Bar {
color
};
''',
[{
'color': 'RED',
}],
) | )
await self.assert_query_result(
r | test_edgeql_enums_assignment_03 | python | geldata/gel | tests/test_edgeql_enums.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_enums.py | Apache-2.0 |
async def test_edgeql_enums_assignment_04(self):
await self.con.execute(
r'''
INSERT Bar;
''')
# testing the UPDATE assignment cast
await self.con.execute(
r'''
UPDATE Bar
SET {
color := 'GREEN'
};
''')
await self.assert_query_result(
r'''
SELECT Bar {
color
};
''',
[{
'color': 'GREEN',
}],
) | )
# testing the UPDATE assignment cast
await self.con.execute(
r | test_edgeql_enums_assignment_04 | python | geldata/gel | tests/test_edgeql_enums.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_enums.py | Apache-2.0 |
async def test_edgeql_enums_anonymous(self):
with self.assertRaisesRegex(
edgedb.InvalidPropertyDefinitionError,
r'this type cannot be anonymous',
):
await self.con.execute(
"""
create type X {
create property tier -> enum<"Basic", "Common", "Rare">;
}
"""
) | create type X {
create property tier -> enum<"Basic", "Common", "Rare">;
} | test_edgeql_enums_anonymous | python | geldata/gel | tests/test_edgeql_enums.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_enums.py | Apache-2.0 |
async def _ensure_schema_data_integrity(self):
await self.assert_query_result(
r'''
SELECT _ := schema::Module.name
FILTER _ LIKE 'default%'
''',
{'default', 'default::nested', 'default::back`ticked'},
)
# We don't bother to validate these but we need them to work
await self.con.query('describe schema as sdl')
await self.con.query('describe schema as ddl')
# We took a dev version snapshot for 3.0, but then needed to
# add more stuff to the 3.0 dump tests. It didn't seem worth
# adding a new dump test for it (both ergonomically and
# because it would be slower), so just quit early in that case.
if (
self._testMethodName
== 'test_dumpv3_restore_compatibility_3_0_dev_7258'
):
return
await self.assert_query_result(
r'''
select schema::Migration { script, message, generated_by }
order by exists .parents then exists .parents.parents
limit 3
''',
[
{"message": None, "generated_by": None},
{"message": "test", "generated_by": None},
{"message": None, "generated_by": "DDLStatement"},
],
)
await self.assert_query_result(
r'''
select schema::Trigger {
name, scope, kinds, sname := .subject.name
};
''',
[
{
"name": "log",
"scope": "Each",
"kinds": ["Insert"],
"sname": "default::Foo"
}
]
)
await self.assert_query_result(
r'''
select schema::Rewrite {
sname := .subject.source.name ++ "." ++ .subject.name,
name,
};
''',
tb.bag([
{"sname": "default::Log.timestamp", "name": "Insert"},
{"sname": "default::Log.timestamp", "name": "Update"},
]),
)
await self.assert_query_result(
r'''
select schema::AccessPolicy { name, errmessage }
filter .name = 'whatever_no';
''',
[{"name": "whatever_no", "errmessage": "aaaaaa"}],
)
await self.assert_query_result(
r'''
select cfg::Config.allow_user_specified_id;
''',
[True],
)
await self.assert_query_result(
r'''
select <str>cfg::Config.query_execution_timeout;
''',
['PT1H20M13S'],
) | ,
{'default', 'default::nested', 'default::back`ticked'},
)
# We don't bother to validate these but we need them to work
await self.con.query('describe schema as sdl')
await self.con.query('describe schema as ddl')
# We took a dev version snapshot for 3.0, but then needed to
# add more stuff to the 3.0 dump tests. It didn't seem worth
# adding a new dump test for it (both ergonomically and
# because it would be slower), so just quit early in that case.
if (
self._testMethodName
== 'test_dumpv3_restore_compatibility_3_0_dev_7258'
):
return
await self.assert_query_result(
r | _ensure_schema_data_integrity | python | geldata/gel | tests/test_dump_v3.py | https://github.com/geldata/gel/blob/master/tests/test_dump_v3.py | Apache-2.0 |
async def test_edgeql_calls_01(self):
await self.con.execute('''
CREATE FUNCTION call1(
s: str,
VARIADIC a: int64,
NAMED ONLY suffix: str = '-suf',
NAMED ONLY prefix: str = 'pref-'
) -> std::str
USING (
SELECT prefix ++ s ++ <str>sum(array_unpack(a)) ++ suffix
);
''')
await self.assert_query_result(
r'''SELECT call1('-');''',
['pref--0-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', suffix := 's1');''',
['pref--0s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', prefix := 'p1');''',
['p1-0-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', suffix := 's1', prefix := 'p1');''',
['p1-0s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1);''',
['pref--1-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, suffix := 's1');''',
['pref--1s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, prefix := 'p1');''',
['p1-1-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, 2, 3, 4, 5);''',
['pref--15-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, 2, 3, 4, 5, suffix := 's1');''',
['pref--15s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, 2, 3, 4, 5, prefix := 'p1');''',
['p1-15-suf'],
)
await self.assert_query_result(
r'''
SELECT call1('-', 1, 2, 3, 4, 5, prefix := 'p1',
suffix := 'aaa');
''',
['p1-15aaa'],
) | )
await self.assert_query_result(
r'''SELECT call1('-');''',
['pref--0-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', suffix := 's1');''',
['pref--0s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', prefix := 'p1');''',
['p1-0-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', suffix := 's1', prefix := 'p1');''',
['p1-0s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1);''',
['pref--1-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, suffix := 's1');''',
['pref--1s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, prefix := 'p1');''',
['p1-1-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, 2, 3, 4, 5);''',
['pref--15-suf'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, 2, 3, 4, 5, suffix := 's1');''',
['pref--15s1'],
)
await self.assert_query_result(
r'''SELECT call1('-', 1, 2, 3, 4, 5, prefix := 'p1');''',
['p1-15-suf'],
)
await self.assert_query_result(
r | test_edgeql_calls_01 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_calls_05(self):
await self.con.execute('''
CREATE FUNCTION call5(
a: int64,
NAMED ONLY b: OPTIONAL int64 = <int64>{}
) -> int64
USING EdgeQL $$
SELECT a + b ?? -100
$$;
''')
await self.assert_query_result(
r'''SELECT call5(1);''',
[-99],
)
await self.assert_query_result(
r'''SELECT call5(<int32>2);''',
[-98],
)
await self.assert_query_result(
r'''SELECT call5(1, b := 20);''',
[21],
)
await self.assert_query_result(
r'''SELECT call5(1, b := <int16>10);''',
[11],
)
await self.assert_query_result(
r'''SELECT call5(<int32>{});''',
[],
)
await self.assert_query_result(
r'''SELECT call5(<int32>{}, b := <int32>{});''',
[],
)
await self.assert_query_result(
r'''SELECT call5(<int32>{}, b := 50);''',
[],
)
await self.assert_query_result(
r'''SELECT call5(1, b := <int32>{});''',
[-99],
)
await self.assert_query_result(
r'''
WITH X := (SELECT _:={1,2,3} FILTER _ < 0)
SELECT call5(1, b := X);''',
[-99],
) | )
await self.assert_query_result(
r'''SELECT call5(1);''',
[-99],
)
await self.assert_query_result(
r'''SELECT call5(<int32>2);''',
[-98],
)
await self.assert_query_result(
r'''SELECT call5(1, b := 20);''',
[21],
)
await self.assert_query_result(
r'''SELECT call5(1, b := <int16>10);''',
[11],
)
await self.assert_query_result(
r'''SELECT call5(<int32>{});''',
[],
)
await self.assert_query_result(
r'''SELECT call5(<int32>{}, b := <int32>{});''',
[],
)
await self.assert_query_result(
r'''SELECT call5(<int32>{}, b := 50);''',
[],
)
await self.assert_query_result(
r'''SELECT call5(1, b := <int32>{});''',
[-99],
)
await self.assert_query_result(
r | test_edgeql_calls_05 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_calls_10(self):
await self.assert_query_result(
r'''SELECT (INTROSPECT TYPEOF sum({1, 2, 3})).name;''',
{'std::int64'},
)
await self.assert_query_result(
r'''SELECT (INTROSPECT TYPEOF sum({<int32>1, 2, 3})).name;''',
{'std::int64'},
)
await self.assert_query_result(
r'''SELECT (INTROSPECT TYPEOF sum({<float32>1, 2, 3})).name;''',
{'std::float64'},
)
await self.assert_query_result(
r'''
SELECT (INTROSPECT TYPEOF
sum({<float32>1, <int32>2, 3})).name;
''',
{'std::float64'},
)
await self.assert_query_result(
r'''
SELECT (INTROSPECT TYPEOF
sum({<int16>1, <int32>2, <decimal>3})).name;
''',
{'std::decimal'},
)
await self.assert_query_result(
r'''
SELECT (INTROSPECT TYPEOF
sum({<int16>1, <int32>2, <bigint>3})).name;
''',
{'std::bigint'},
)
await self.assert_query_result(
r'''
SELECT (INTROSPECT TYPEOF
sum({<int16>1, 2, <decimal>3})).name;
''',
{'std::decimal'},
)
await self.assert_query_result(
r'''
SELECT (INTROSPECT TYPEOF
sum({1, <float32>2.1, <float64>3})).name;
''',
{'std::float64'},
)
await self.assert_query_result(
r'''SELECT (INTROSPECT TYPEOF sum({1.1, 2.2, 3.3})).name;''',
{'std::float64'},
)
await self.assert_query_result(
r'''SELECT (INTROSPECT TYPEOF
sum({<float32>1, <int32>2, <float32>3})).name;''',
{'std::float64'},
)
await self.assert_query_result(
r'''SELECT (INTROSPECT TYPEOF
sum({<float32>1, <float32>2, <float32>3})).name;''',
{'std::float32'},
)
await self.assert_query_result(
r'''SELECT (INTROSPECT TYPEOF sum({1.1, 2.2, 3})).name;''',
{'std::float64'},
) | ,
{'std::float64'},
)
await self.assert_query_result(
r | test_edgeql_calls_10 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_calls_13(self):
await self.con.execute('''
CREATE FUNCTION inner(
a: anytype
) -> int64
USING (
SELECT 1
);
CREATE FUNCTION call13(
a: anytype
) -> int64
USING (
SELECT inner(a)
);
''')
await self.assert_query_result(
r'''SELECT call13('aaa');''',
[1],
)
await self.assert_query_result(
r'''SELECT call13(b'aaaa');''',
[1],
)
await self.assert_query_result(
r'''SELECT call13([1, 2, 3, 4, 5]);''',
[1],
)
await self.assert_query_result(
r'''SELECT call13(['a', 'b']);''',
[1],
)
await self.con.execute('''
CREATE FUNCTION inner(
a: str
) -> int64
USING EdgeQL $$
SELECT 2
$$;
CREATE FUNCTION call13_2(
a: anytype
) -> int64
USING EdgeQL $$
SELECT inner(a)
$$;
''')
await self.assert_query_result(
r'''SELECT call13_2('aaa');''',
[2],
)
await self.assert_query_result(
r'''SELECT call13_2(b'aaaa');''',
[1],
)
await self.assert_query_result(
r'''SELECT call13_2([1, 2, 3, 4, 5]);''',
[1],
)
await self.assert_query_result(
r'''SELECT call13_2(['a', 'b']);''',
[1],
) | )
await self.assert_query_result(
r'''SELECT call13('aaa');''',
[1],
)
await self.assert_query_result(
r'''SELECT call13(b'aaaa');''',
[1],
)
await self.assert_query_result(
r'''SELECT call13([1, 2, 3, 4, 5]);''',
[1],
)
await self.assert_query_result(
r'''SELECT call13(['a', 'b']);''',
[1],
)
await self.con.execute( | test_edgeql_calls_13 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_calls_obj_01(self):
await self.con.execute("""
CREATE TYPE Shape;
CREATE TYPE FlatShape;
CREATE TYPE Rectangle EXTENDING FlatShape {
CREATE REQUIRED PROPERTY w -> float64;
CREATE REQUIRED PROPERTY h -> float64;
};
CREATE TYPE Circle EXTENDING FlatShape {
CREATE REQUIRED PROPERTY r -> float64;
};
# Use -1 as the error indicator, as we don't have the means
# to raise errors directly yet.
CREATE FUNCTION area(s: FlatShape) -> float64 USING (-1);
CREATE FUNCTION area(s: Rectangle) -> float64 USING (s.w * s.h);
CREATE FUNCTION area(s: Circle) -> float64 USING (s.r ^ 2 * 3.14);
INSERT Rectangle { w := 10, h := 20 };
INSERT Circle { r := 10 };
""")
# Check for "manual" abstract function dispatch, where the top
# function is defined to explicitly return an error condition.
await self.assert_query_result(
r"""
SELECT FlatShape {
tn := .__type__.name,
area := area(FlatShape),
}
ORDER BY .tn
""",
[{
"tn": "default::Circle",
"area": 314.0,
}, {
"tn": "default::Rectangle",
"area": 200.0,
}]
)
# Non-polymorphic calls should work also.
await self.assert_query_result(
r"""
SELECT area(Circle);
""",
[314.0],
)
await self.assert_query_result(
r"""
SELECT area(Rectangle);
""",
[200.0],
)
# Test that opaque object sources work as well.
await self.assert_query_result(
r"""
WITH r := (Rectangle, [Rectangle])
SELECT (area(r.0), area(r.1[0]))
""",
[[200.0, 200.0]],
)
# The top parent does _not_ have a definition of area, so
# calling it on it is still an error (even if there are definitions
# for all subtypes).
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r'function "area\(.*: default::Shape\)" does not exist',
):
await self.con.execute("SELECT area(Shape)") | )
# Check for "manual" abstract function dispatch, where the top
# function is defined to explicitly return an error condition.
await self.assert_query_result(
r | test_edgeql_calls_obj_01 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_calls_obj_02(self):
# Similar to test_edgeql_calls_obj_01, but
# the functions are set-returning.
await self.con.execute("""
CREATE TYPE Shape;
CREATE TYPE FlatShape;
CREATE TYPE Rectangle EXTENDING FlatShape {
CREATE PROPERTY w -> float64;
CREATE PROPERTY h -> float64;
};
CREATE TYPE Circle EXTENDING FlatShape {
CREATE PROPERTY r -> float64;
};
# Use -1 as the error indicator, as we don't have the means
# to raise errors directly yet.
CREATE FUNCTION dimensions(s: FlatShape) -> SET OF float64
USING (-1);
CREATE FUNCTION dimensions(s: Rectangle) -> SET OF float64
USING ({s.w, s.h});
CREATE FUNCTION dimensions(s: Circle) -> SET OF float64
USING (s.r);
INSERT Rectangle { w := 10, h := 20 };
INSERT Circle { r := 5 };
""")
# Check for "manual" abstract function dispatch, where the top
# function is defined to explicitly return an error condition.
await self.assert_query_result(
r"""
SELECT FlatShape {
tn := .__type__.name,
dimensions := dimensions(FlatShape),
}
ORDER BY .tn
""",
[{
"tn": "default::Circle",
"dimensions": [5],
}, {
"tn": "default::Rectangle",
"dimensions": [10, 20],
}]
)
# Non-polymorphic calls should work also.
await self.assert_query_result(
r"""
SELECT dimensions(Circle);
""",
[5],
)
await self.assert_query_result(
r"""
SELECT dimensions(Rectangle);
""",
[10, 20],
) | )
# Check for "manual" abstract function dispatch, where the top
# function is defined to explicitly return an error condition.
await self.assert_query_result(
r | test_edgeql_calls_obj_02 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_calls_obj_03(self):
await self.con.execute("""
CREATE TYPE Person {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE FUNCTION fight(one: Person, two: Person) -> str
USING (one.name ++ " fights " ++ two.name);
CREATE FUNCTION fight(one: str, two: str) -> str
USING (one ++ " fights " ++ two);
CREATE FUNCTION fight(one: Person, two: str) -> str
USING (one.name ++ " fights " ++ two);
CREATE FUNCTION fight(one: str, two: Person) -> str
USING (one ++ " fights " ++ two.name);
CREATE FUNCTION fight(names: array<str>) -> str
USING (array_join(names, " fights "));
INSERT Person { name := "Sub-Zero" };
INSERT Person { name := "Scorpion" };
""")
await self.assert_query_result(
r"""
WITH
Scorpion := (SELECT Person FILTER .name = "Scorpion"),
SubZero := (SELECT Person FILTER .name = "Sub-Zero"),
SELECT
fight(Scorpion, SubZero);
""",
["Scorpion fights Sub-Zero"],
)
await self.assert_query_result(
r"""
WITH
Scorpion := (SELECT Person FILTER .name = "Scorpion"),
SubZero := (SELECT Person FILTER .name = "Sub-Zero"),
SELECT
fight(Scorpion.name, SubZero.name);
""",
["Scorpion fights Sub-Zero"],
)
await self.assert_query_result(
r"""
WITH
Scorpion := (SELECT Person FILTER .name = "Scorpion"),
SubZero := (SELECT Person FILTER .name = "Sub-Zero"),
SELECT
fight(Scorpion.name, SubZero);
""",
["Scorpion fights Sub-Zero"],
)
await self.assert_query_result(
r"""
WITH
Scorpion := (SELECT Person FILTER .name = "Scorpion"),
SubZero := (SELECT Person FILTER .name = "Sub-Zero"),
SELECT
fight(Scorpion, SubZero.name);
""",
["Scorpion fights Sub-Zero"],
)
await self.assert_query_result(
r"""
WITH
Scorpion := (SELECT Person FILTER .name = "Scorpion"),
SubZero := (SELECT Person FILTER .name = "Sub-Zero"),
SELECT
fight([Scorpion.name, SubZero.name]);
""",
["Scorpion fights Sub-Zero"],
)
await self.con.execute("DROP FUNCTION fight(one: Person, two: Person)")
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r'function "fight\(.*default::Person.*\)" does not exist',
):
await self.con.execute(
r"""
WITH
Scorpion := (SELECT Person FILTER .name = "Scorpion"),
SubZero := (SELECT Person FILTER .name = "Sub-Zero"),
SELECT
fight(Scorpion, SubZero);SELECT area(Shape)
""",
) | )
await self.assert_query_result(
r | test_edgeql_calls_obj_03 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_calls_obj_05(self):
await self.con.execute("""
CREATE TYPE Ghost {
CREATE PROPERTY name -> str;
};
CREATE FUNCTION boo(s: Ghost) -> set of str
USING ("oh my, " ++ s.name ++ " scared me!");
INSERT Ghost { name := 'Casper' };
""")
await self.assert_query_result(
"SELECT boo((SELECT Ghost))",
["oh my, Casper scared me!"],
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r'newly created or updated objects cannot be passed to functions',
):
await self.con.execute(
r"SELECT boo((UPDATE Ghost SET { name := 'Tom' }))",
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r'newly created or updated objects cannot be passed to functions',
):
await self.con.execute(
r"SELECT boo((INSERT Ghost { name := 'Jack' }));",
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r'newly created or updated objects cannot be passed to functions',
):
await self.con.execute(
r"""
WITH friendly := (INSERT Ghost { name := 'Jack' })
SELECT boo(friendly);
""",
) | )
await self.assert_query_result(
"SELECT boo((SELECT Ghost))",
["oh my, Casper scared me!"],
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r'newly created or updated objects cannot be passed to functions',
):
await self.con.execute(
r"SELECT boo((UPDATE Ghost SET { name := 'Tom' }))",
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r'newly created or updated objects cannot be passed to functions',
):
await self.con.execute(
r"SELECT boo((INSERT Ghost { name := 'Jack' }));",
)
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r'newly created or updated objects cannot be passed to functions',
):
await self.con.execute(
r | test_edgeql_calls_obj_05 | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_edgeql_call_builtin_obj(self):
await self.con.execute(
r"""
CREATE FUNCTION get_obj(name: str) ->
SET OF schema::Object USING (
SELECT schema::Object FILTER .name = name);
""",
)
res = await self.con._fetchall("""
SELECT get_obj('std::BaseObject')
""", __typenames__=True)
self.assertEqual(len(res), 1)
self.assertEqual(res[0].__tname__, "schema::ObjectType") | ,
)
res = await self.con._fetchall( | test_edgeql_call_builtin_obj | python | geldata/gel | tests/test_edgeql_calls.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_calls.py | Apache-2.0 |
async def test_dump_fuzz_01(self):
if not self.has_create_database:
self.skipTest('create database is not supported by the backend')
# This test creates a simple `DBSIZE` DB filled with semi-random
# byte strings. While the DB is populated a hash of all byte
# strings is computed. The DB is then dumped and restored.
# A new hash computed of all byte strings in the new DB.
# The former and latter hashes must be the same.
#
# This test is not designed to test how well the schema is
# preserved or compatibility between different edgedb or
# dump versions. Its only purpose is to make sure that
# the basic dump I/O and network protocol functions correctly.
hasher = hashlib.sha1()
idx = 0
total_len = 0
while total_len < self.DBSIZE:
data = self.some_bytes(random.randint(100_000, 10_000_000))
hasher.update(data)
total_len += len(data)
await self.con.query_single('''
INSERT test::Tmp {
idx := <int64>$idx,
data := <bytes>$data,
}
''', idx=idx, data=data)
idx += 1
expected_hash = hasher.digest()
nrows = idx
dbname = self.get_database_name()
restored_dbname = f'{dbname}_restored'
try:
await self.con.execute(f'CREATE DATABASE {restored_dbname}')
with tempfile.TemporaryDirectory() as f:
fname = os.path.join(f, 'dump')
self.run_cli('-d', f"{dbname}", 'dump', fname)
self.run_cli('-d', restored_dbname, 'restore', fname)
con2 = await self.connect(database=restored_dbname)
except Exception:
await tb.drop_db(self.con, restored_dbname)
raise
try:
hasher = hashlib.sha1()
for idx in range(nrows):
# We don't have cursors yet and we also don't want to fetch
# a huge data set in one hop; so we fetch row by row.
# Not ideal, but isn't too bad either.
r = await con2.query_single('''
WITH
MODULE test,
A := (SELECT Tmp FILTER Tmp.idx = <int64>$idx)
SELECT A.data
LIMIT 1
''', idx=idx)
hasher.update(r)
self.assertEqual(hasher.digest(), expected_hash)
finally:
await con2.aclose()
await tb.drop_db(self.con, restored_dbname) | , idx=idx, data=data)
idx += 1
expected_hash = hasher.digest()
nrows = idx
dbname = self.get_database_name()
restored_dbname = f'{dbname}_restored'
try:
await self.con.execute(f'CREATE DATABASE {restored_dbname}')
with tempfile.TemporaryDirectory() as f:
fname = os.path.join(f, 'dump')
self.run_cli('-d', f"{dbname}", 'dump', fname)
self.run_cli('-d', restored_dbname, 'restore', fname)
con2 = await self.connect(database=restored_dbname)
except Exception:
await tb.drop_db(self.con, restored_dbname)
raise
try:
hasher = hashlib.sha1()
for idx in range(nrows):
# We don't have cursors yet and we also don't want to fetch
# a huge data set in one hop; so we fetch row by row.
# Not ideal, but isn't too bad either.
r = await con2.query_single( | test_dump_fuzz_01 | python | geldata/gel | tests/test_dump_basic.py | https://github.com/geldata/gel/blob/master/tests/test_dump_basic.py | Apache-2.0 |
async def _ensure_schema_data_integrity(self, include_secrets):
await self.assert_query_result(
r'''
select count(L2)
''',
[
999
]
)
await self.assert_query_result(
r'''
with x := range_unpack(range(1, 1000))
select all(
L2.vec in <v3>[x % 10, std::math::ln(x), x / 7 % 13]
)
''',
[
True
]
)
# We put pgvector dump tests in v4 dump even though they
# shipped in 3.0-rc3 (shipping pgvector was a wild ride). It
# doesn't seem worth adding a second v4 dump test for (both
# ergonomically and because it would be slower), so just quit
# early in that case.
if (
self._testMethodName
== 'test_dumpv4_restore_compatibility_3_0'
):
return
if include_secrets:
secrets = [
dict(name='4', value='spam', extra=None,
tname='ext::_conf::SecretObj')
]
else:
secrets = []
await self.assert_query_result(
'''
select cfg::Config {
conf := assert_single(.extensions[is ext::_conf::Config] {
config_name,
objs: { name, value, [is ext::_conf::SubObj].extra,
tname := .__type__.name }
order by .name,
})
};
''',
[dict(conf=dict(
config_name='ready',
objs=[
dict(name='1', value='foo', tname='ext::_conf::Obj'),
dict(name='2', value='bar', tname='ext::_conf::Obj'),
dict(name='3', value='baz', extra=42,
tname='ext::_conf::SubObj'),
*secrets,
],
))]
)
await self.assert_query_result(
'''
select ext::_conf::get_top_secret()
''',
['secret'] if include_secrets else [],
)
# __fts_document__ should be repopulated
await self.assert_query_result(
r'''
SELECT fts::search(L3, 'satisfying').object { x }
''',
[
{
'x': 'satisfied customer',
},
],
)
if include_secrets:
await self.assert_query_result(
'''
select cfg::Config.extensions[is ext::auth::AuthConfig] {
providers: { name } order by .name
};
''',
[{
'providers': [
{'name': 'builtin::local_emailpassword'},
{'name': 'builtin::oauth_apple'},
{'name': 'builtin::oauth_azure'},
{'name': 'builtin::oauth_github'},
{'name': 'builtin::oauth_google'},
]
}]
)
# We didn't specify include_secrets in the dumps we made for
# 4.0, but the way that smtp config was done then, it got
# dumped anyway. (The secret wasn't specified.)
has_smtp = (
include_secrets
or self._testMethodName == 'test_dumpv4_restore_compatibility_4_0'
)
# N.B: This is not what it looked like in the original
# dumps. We patched it up during restore starting with 6.0.
if has_smtp:
await self.assert_query_result(
'''
select cfg::Config {
email_providers[is cfg::SMTPProviderConfig]: {
name, sender
},
current_email_provider_name,
};
''',
[
{
"email_providers": [
{
"name": "_default",
"sender": "[email protected]",
}
],
"current_email_provider_name": "_default"
}
],
) | ,
[
999
]
)
await self.assert_query_result(
r | _ensure_schema_data_integrity | python | geldata/gel | tests/test_dump_v4.py | https://github.com/geldata/gel/blob/master/tests/test_dump_v4.py | Apache-2.0 |
def test_schema_on_target_delete_03(self):
"""
type A {
link foo -> Object {
on target delete restrict
}
};
type B {
link foo -> Object {
on target delete allow
}
};
type C extending A, B;
""" | type A {
link foo -> Object {
on target delete restrict
}
};
type B {
link foo -> Object {
on target delete allow
}
};
type C extending A, B; | test_schema_on_target_delete_03 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_restrict_01(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source1 {
name := 'Source1.1',
tgt1_restrict := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""") | )
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute( | test_link_on_target_delete_restrict_01 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_restrict_02(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1Child {
name := 'Target1Child.1'
};
INSERT Source1 {
name := 'Source1.1',
tgt1_restrict := (
SELECT Target1
FILTER .name = 'Target1Child.1'
)
};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute("""
DELETE (SELECT Target1Child
FILTER .name = 'Target1Child.1');
""") | )
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute( | test_link_on_target_delete_restrict_02 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_restrict_03(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source3 {
name := 'Source3.1',
tgt1_restrict := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1 .* is prohibited by link'):
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""") | )
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1 .* is prohibited by link'):
await self.con.execute( | test_link_on_target_delete_restrict_03 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_restrict_04(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1Child {
name := 'Target1Child.1'
};
INSERT Source3 {
name := 'Source3.1',
tgt1_restrict := (
SELECT Target1
FILTER .name = 'Target1Child.1'
)
};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute("""
DELETE (SELECT Target1Child
FILTER .name = 'Target1Child.1');
""") | )
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute( | test_link_on_target_delete_restrict_04 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_restrict_08(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source1 {
name := 'Source1.1',
tgt_union_restrict := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""") | )
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1.* is prohibited by link'):
await self.con.execute( | test_link_on_target_delete_restrict_08 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_deferred_restrict_01(self):
exception_is_deferred = False
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1 .* is prohibited by link'):
async with self.con.transaction():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source1 {
name := 'Source1.1',
tgt1_deferred_restrict := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
await self.con.execute("""
DELETE (SELECT Target1
FILTER .name = 'Target1.1');
""")
exception_is_deferred = True
self.assertTrue(exception_is_deferred) | )
await self.con.execute( | test_link_on_target_delete_deferred_restrict_01 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_deferred_restrict_02(self):
exception_is_deferred = False
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1 .* is prohibited by link'):
async with self.con.transaction():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source3 {
name := 'Source3.1',
tgt1_deferred_restrict := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
await self.con.execute("""
DELETE (SELECT Target1
FILTER .name = 'Target1.1');
""")
exception_is_deferred = True
self.assertTrue(exception_is_deferred) | )
await self.con.execute( | test_link_on_target_delete_deferred_restrict_02 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_deferred_restrict_04(self):
try:
async with self.con.transaction():
await self.con.execute(r"""
INSERT Target1 {
name := 'Target4.1'
};
INSERT Source1 {
name := 'Source4.1',
tgt1_deferred_restrict := (
SELECT Target1
FILTER .name = 'Target4.1'
)
};
# delete the target with deferred trigger
DELETE (SELECT Target1
FILTER .name = 'Target4.1');
# assign a new target to the `tgt1_deferred_restrict`
INSERT Target1 {
name := 'Target4.2'
};
UPDATE Source1
FILTER Source1.name = 'Source4.1'
SET {
tgt1_deferred_restrict := (
SELECT Target1
FILTER .name = 'Target4.2'
)
};
""")
await self.assert_query_result(
r'''
SELECT Target1 { name }
FILTER .name = 'Target4.2';
''',
[{'name': 'Target4.2'}]
)
finally:
# cleanup
await self.con.execute("""
DELETE (SELECT Source1
FILTER .name = 'Source4.1');
DELETE (SELECT Target1
FILTER .name = 'Target4.2');
""") | )
await self.assert_query_result(
r | test_link_on_target_delete_deferred_restrict_04 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_allow_01(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source1 {
name := 'Source1.1',
tgt1_allow := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
await self.assert_query_result(
r'''
SELECT
Source1 {
tgt1_allow: {
name
}
};
''',
[{
'tgt1_allow': {'name': 'Target1.1'},
}]
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source1 {
tgt1_allow: {
name
}
}
FILTER
.name = 'Source1.1';
''',
[{
'tgt1_allow': None,
}]
) | )
await self.assert_query_result(
r | test_link_on_target_delete_allow_01 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_allow_02(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source3 {
name := 'Source3.1',
tgt1_allow := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
await self.assert_query_result(
r'''
SELECT
Source3 {
tgt1_allow: {
name
}
};
''',
[{
'tgt1_allow': {'name': 'Target1.1'},
}]
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source3 {
tgt1_allow: {
name
}
}
FILTER
.name = 'Source3.1';
''',
[{
'tgt1_allow': None,
}]
) | )
await self.assert_query_result(
r | test_link_on_target_delete_allow_02 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_allow_03(self):
async with self._run_and_rollback():
await self.con.execute("""
FOR name IN {'Target1.1', 'Target1.2', 'Target1.3'}
UNION (
INSERT Target1 {
name := name
});
INSERT Source1 {
name := 'Source1.1',
tgt1_m2m_allow := (
SELECT Target1
FILTER
.name IN {'Target1.1', 'Target1.2', 'Target1.3'}
)
};
""")
await self.assert_query_result(
r'''
SELECT
Source1 {
name,
tgt1_m2m_allow: {
name
} ORDER BY .name
}
FILTER
.name = 'Source1.1';
''',
[{
'name': 'Source1.1',
'tgt1_m2m_allow': [
{'name': 'Target1.1'},
{'name': 'Target1.2'},
{'name': 'Target1.3'},
],
}]
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source1 {
name,
tgt1_m2m_allow: {
name
} ORDER BY .name
}
FILTER
.name = 'Source1.1';
''',
[{
'name': 'Source1.1',
'tgt1_m2m_allow': [
{'name': 'Target1.2'},
{'name': 'Target1.3'},
],
}]
)
await self.assert_query_result(
r'''
SELECT
Target1 {
name
}
FILTER
.name LIKE 'Target1%'
ORDER BY
.name;
''',
[
{'name': 'Target1.2'},
{'name': 'Target1.3'},
]
) | )
await self.assert_query_result(
r | test_link_on_target_delete_allow_03 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_delete_source_01(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Target1 {
name := 'Target1.2'
};
INSERT Source1 {
name := 'Source1.1',
tgt1_del_source := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
INSERT Source2 {
name := 'Source2.1',
src1_del_source := (
SELECT Source1
FILTER .name = 'Source1.1'
),
tgt_m2m := (
SELECT Target1
FILTER .name = 'Target1.2'
)
};
""")
await self.assert_query_result(
r'''
SELECT
Source2 {
src1_del_source: {
name,
tgt1_del_source: {
name
}
}
}
FILTER
.name = 'Source2.1';
''',
[{
'src1_del_source': {
'name': 'Source1.1',
'tgt1_del_source': {'name': 'Target1.1'},
}
}]
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source2
FILTER
.name = 'Source2.1';
''',
[]
)
await self.assert_query_result(
r'''
SELECT
Source1
FILTER
.name = 'Source1.1';
''',
[],
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.2');
""") | )
await self.assert_query_result(
r | test_link_on_target_delete_delete_source_01 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_delete_source_02(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source1 {
name := 'Source1.1',
tgt1_del_source := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
INSERT Source1 {
name := 'Source1.2',
tgt1_del_source := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
INSERT Source2 {
name := 'Source2.1',
src1_del_source := (
SELECT Source1
FILTER .name = 'Source1.1'
)
};
""")
await self.assert_query_result(
r'''
SELECT
Source2 {
src1_del_source: {
name,
tgt1_del_source: {
name
}
}
}
FILTER
.name = 'Source2.1';
''',
[{
'src1_del_source': {
'name': 'Source1.1',
'tgt1_del_source': {'name': 'Target1.1'},
}
}]
)
await self.assert_query_result(
r'''
SELECT
Source1 {
name,
tgt1_del_source: {
name
}
}
FILTER
.name LIKE 'Source1%';
''',
[
{
'name': 'Source1.1',
'tgt1_del_source': {'name': 'Target1.1'},
},
{
'name': 'Source1.2',
'tgt1_del_source': {'name': 'Target1.1'},
}
]
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source2
FILTER
.name = 'Source2.1';
''',
[],
)
await self.assert_query_result(
r'''
SELECT
Source1
FILTER
.name LIKE 'Source1%';
''',
[],
) | )
await self.assert_query_result(
r | test_link_on_target_delete_delete_source_02 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_delete_source_03(self):
async with self._run_and_rollback():
await self.con.execute("""
FOR name IN {'Target1.1', 'Target1.2', 'Target1.3'}
UNION (
INSERT Target1 {
name := name
});
INSERT Source1 {
name := 'Source1.1',
tgt1_m2m_del_source := (
SELECT Target1
FILTER
.name IN {'Target1.1', 'Target1.2', 'Target1.3'}
)
};
""")
await self.assert_query_result(
r'''
SELECT
Source1 {
name,
tgt1_m2m_del_source: {
name
} ORDER BY .name
}
FILTER
.name = 'Source1.1';
''',
[{
'name': 'Source1.1',
'tgt1_m2m_del_source': [
{'name': 'Target1.1'},
{'name': 'Target1.2'},
{'name': 'Target1.3'},
],
}]
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source1 {
name,
tgt1_m2m_del_source: {
name
} ORDER BY .name
}
FILTER
.name = 'Source1.1';
''',
[]
)
await self.assert_query_result(
r'''
SELECT
Target1 {
name
}
FILTER
.name LIKE 'Target1%'
ORDER BY
.name;
''',
[
{'name': 'Target1.2'},
{'name': 'Target1.3'},
]
) | )
await self.assert_query_result(
r | test_link_on_target_delete_delete_source_03 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_delete_source_04(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source3 {
name := 'Source3.1',
tgt1_del_source := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
INSERT Source3 {
name := 'Source3.2',
tgt1_del_source := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
INSERT Source2 {
name := 'Source2.1',
src1_del_source := (
SELECT Source3
FILTER .name = 'Source3.1'
)
};
""")
await self.assert_query_result(
r'''
SELECT
Source2 {
src1_del_source: {
name,
tgt1_del_source: {
name
}
}
}
FILTER
.name = 'Source2.1';
''',
[{
'src1_del_source': {
'name': 'Source3.1',
'tgt1_del_source': {'name': 'Target1.1'},
}
}]
)
await self.assert_query_result(
r'''
SELECT
Source3 {
name,
tgt1_del_source: {
name
}
}
FILTER
.name LIKE 'Source3%';
''',
[
{
'name': 'Source3.1',
'tgt1_del_source': {'name': 'Target1.1'},
},
{
'name': 'Source3.2',
'tgt1_del_source': {'name': 'Target1.1'},
}
]
)
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source3
FILTER
.name LIKE 'Source3%';
''',
[],
)
await self.assert_query_result(
r'''
SELECT
Source2
FILTER
.name = 'Source2.1';
''',
[],
) | )
await self.assert_query_result(
r | test_link_on_target_delete_delete_source_04 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_delete_source_05(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT ChildSource1 {
name := 'Source1.1',
tgt1_del_source := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
ChildSource1
FILTER
.name = 'Source1.1';
''',
[]
) | )
await self.con.execute( | test_link_on_target_delete_delete_source_05 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_delete_source_06(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Target1 {
name := 'Target1.1'
};
INSERT Source1 {
name := 'Source1.1',
tgt_union_m2m_del_source := (
SELECT Target1
FILTER .name = 'Target1.1'
)
};
""")
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.1');
""")
await self.assert_query_result(
r'''
SELECT
Source1
FILTER
.name = 'Source1.1';
''',
[]
) | )
await self.con.execute( | test_link_on_target_delete_delete_source_06 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_loop_01(self):
async with self._run_and_rollback():
await self.con.execute("""
insert Source1 {
name := 'Source1.1',
self_del_source := detached (
insert Source1 {
name := 'Source1.2',
self_del_source := detached (
insert Source1 { name := 'Source1.3' }
)
}
)
};
update Source1 filter .name = 'Source1.3' set {
self_del_source := detached (
select Source1 filter .name = 'Source1.1'
)
};
""")
await self.con.execute("""
delete Source1 filter .name = 'Source1.1'
""")
await self.assert_query_result(
r'''
select Source1
''',
[]
) | )
await self.con.execute( | test_link_on_target_delete_loop_01 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_source_delete_01(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Source1 {
name := 'Source1.1',
tgt1_del_target := (
INSERT Target1 {
name := 'Target1.1',
extra_tgt := (detached (
INSERT Target1 { name := "t2" })),
}
)
};
""")
await self.con.execute("""
DELETE Source1 filter .name = 'Source1.1'
""")
await self.assert_query_result(
r'''
SELECT Target1
FILTER .name = 'Target1.1';
''',
[]
)
# Make sure that the link tables get cleared when a policy
# deletes an object
await self.con.execute("""
DELETE Target1 filter .name = 't2'
""") | )
await self.con.execute( | test_link_on_source_delete_01 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_source_delete_02(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Source1 {
name := 'Source1.1',
tgt1_m2m_del_target := {
(INSERT Target1 {name := 'Target1.1'}),
(INSERT Target1 {name := 'Target1.2'}),
}
};
""")
await self.con.execute("""
DELETE Source1 filter .name = 'Source1.1'
""")
await self.assert_query_result(
r'''
SELECT Target1
''',
[]
) | )
await self.con.execute( | test_link_on_source_delete_02 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_source_delete_03(self):
async with self._run_and_rollback():
await self.con.execute("""
INSERT Source1 {
name := 'Source1.1',
self_del_target := detached (
insert Source1 {
name := 'Source1.2',
self_del_target := detached (
insert Source1 { name := 'Source1.3' }
)
}
)
};
""")
await self.con.execute("""
DELETE Source1 filter .name = 'Source1.1'
""")
await self.assert_query_result(
r'''
SELECT Source1
''',
[]
) | )
await self.con.execute( | test_link_on_source_delete_03 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_source_delete_orphan_01(self):
# Try all the permutations of parent and child classes
for src1, src2, tgt in itertools.product(
('Source1', 'Source3'),
('Source1', 'Source3'),
('Target1', 'Target1Child'),
):
async with self._run_and_rollback():
q = f"""
INSERT {src1} {{
name := 'Source1.1',
tgt1_del_target_orphan := (
INSERT {tgt} {{
name := 'Target1.1'
}}
)
}};
INSERT {src2} {{
name := 'Source1.2',
tgt1_del_target_orphan := (
SELECT Target1 FILTER .name = 'Target1.1'
)
}};
"""
await self.con.execute(q)
await self.con.execute("""
DELETE Source1 filter .name = 'Source1.1'
""")
await self.assert_query_result(
r'''
SELECT Target1
FILTER .name = 'Target1.1';
''',
[{}]
)
await self.con.execute("""
DELETE Source1 filter .name = 'Source1.2'
""")
await self.assert_query_result(
r'''
SELECT Target1
FILTER .name = 'Target1.1';
''',
[]
) | await self.con.execute(q)
await self.con.execute( | test_link_on_source_delete_orphan_01 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_source_delete_orphan_02(self):
# Try all the permutations of parent and child classes
for src1, src2, tgt1, tgt2 in itertools.product(
('Source1', 'Source3'),
('Source1', 'Source3'),
('Target1', 'Target1Child'),
('Target1', 'Target1Child'),
):
async with self._run_and_rollback():
q = f"""
INSERT {src1} {{
name := 'Source1.1',
tgt1_m2m_del_target_orphan := {{
(INSERT {tgt1} {{ name := 'Target1.1'}}),
(INSERT {tgt2} {{ name := 'Target1.2'}}),
}}
}};
INSERT {src2} {{
name := 'Source1.2',
tgt1_m2m_del_target_orphan := (
SELECT Target1 FILTER .name = 'Target1.1'
)
}};
"""
await self.con.execute(q)
await self.con.execute("""
DELETE Source1 filter .name = 'Source1.1'
""")
await self.assert_query_result(
r'''
SELECT Target1 { name }
FILTER .name LIKE 'Target1.%';
''',
[{'name': "Target1.1"}]
)
await self.con.execute("""
DELETE Source1 filter .name = 'Source1.2'
""")
await self.assert_query_result(
r'''
SELECT Target1
FILTER .name = 'Target1.1';
''',
[]
) | await self.con.execute(q)
await self.con.execute( | test_link_on_source_delete_orphan_02 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def _cycle_test(self):
await self.con.execute("""
insert Source1 {
name := 'Source1.1',
self_del_target := detached (
insert Source1 {
name := 'Source1.2',
self_del_target := detached (
insert Source1 { name := 'Source1.3' }
)
}
)
};
update Source1 filter .name = 'Source1.3' set {
self_del_target := detached (
select Source1 filter .name = 'Source1.1'
)
};
""")
await self.con.execute("""
delete Source1 filter .name = 'Source1.1'
""")
await self.assert_query_result(
r'''
select Source1
''',
[]
) | )
await self.con.execute( | _cycle_test | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def test_link_on_target_delete_migration_02(self):
async with self._run_and_rollback():
schema_f = (pathlib.Path(__file__).parent / 'schemas' /
'link_tgt_del_migrated.esdl')
with open(schema_f) as f:
schema = f.read()
await self.migrate(schema)
await self.con.execute("""
INSERT Target1 {
name := 'Target1.m02'
};
INSERT Source1 {
name := 'Source1.m02',
tgt1_deferred_restrict := (
SELECT Target1
FILTER .name = 'Target1.m02'
)
};
""")
# Post-migration the deletion trigger must fire immediately,
# since the policy is no longer "DEFERRED"
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1 .* is prohibited by link'):
await self.con.execute("""
DELETE (SELECT Target1 FILTER .name = 'Target1.m02');
""") | )
# Post-migration the deletion trigger must fire immediately,
# since the policy is no longer "DEFERRED"
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
'deletion of default::Target1 .* is prohibited by link'):
await self.con.execute( | test_link_on_target_delete_migration_02 | python | geldata/gel | tests/test_link_target_delete.py | https://github.com/geldata/gel/blob/master/tests/test_link_target_delete.py | Apache-2.0 |
async def _ensure_schema_integrity(self):
# Validate access policies
await self.assert_query_result(
r'''
SELECT schema::ObjectType {access_policies: {name}}
FILTER .name = 'default::Test2';
''',
[
{'access_policies': [{'name': 'test'}]},
],
)
# Validate globals
await self.assert_query_result(
r'''
SELECT schema::Global {
name, tgt := .target.name, required, default
}
ORDER BY .name
''',
[
{
'name': 'default::bar',
'tgt': 'std::int64',
'required': True,
'default': '-1',
},
{
'name': 'default::baz',
'tgt': 'default::baz',
'required': False,
'default': None,
},
{
'name': 'default::foo',
'tgt': 'std::str',
'required': False,
'default': None,
},
],
) | ,
[
{'access_policies': [{'name': 'test'}]},
],
)
# Validate globals
await self.assert_query_result(
r | _ensure_schema_integrity | python | geldata/gel | tests/test_dump_v2.py | https://github.com/geldata/gel/blob/master/tests/test_dump_v2.py | Apache-2.0 |
async def _ensure_data_integrity(self):
# Test that on source delete all work correctly still
await self.con.execute(r'DELETE SourceA FILTER .name = "s0"')
await self.assert_query_result(
r'''
SELECT TargetA {name}
FILTER .name = 't0';
''',
[],
)
# Should trigger a cascade that then causes a link policy error
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'prohibited by link target policy'):
async with self.con.transaction():
await self.con.execute(r'DELETE SourceA FILTER .name = "s1"')
# Shouldn't delete anything
await self.con.execute(r'DELETE SourceA FILTER .name = "s3"')
await self.assert_query_result(
r'''
SELECT TargetA {name}
FILTER .name = 't2';
''',
[{'name': 't2'}],
)
# But deleting the last reamining one should
await self.con.execute(r'DELETE SourceA FILTER .name = "s4"')
await self.assert_query_result(
r'''
SELECT TargetA {name}
FILTER .name = 't2';
''',
[],
) | ,
[],
)
# Should trigger a cascade that then causes a link policy error
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'prohibited by link target policy'):
async with self.con.transaction():
await self.con.execute(r'DELETE SourceA FILTER .name = "s1"')
# Shouldn't delete anything
await self.con.execute(r'DELETE SourceA FILTER .name = "s3"')
await self.assert_query_result(
r | _ensure_data_integrity | python | geldata/gel | tests/test_dump_v2.py | https://github.com/geldata/gel/blob/master/tests/test_dump_v2.py | Apache-2.0 |
async def test_server_auth_01(self):
if not self.has_create_role:
self.skipTest('create role is not supported by the backend')
await self.con.query('''
CREATE EXTENSION edgeql_http;
''')
await self.con.query('''
CREATE SUPERUSER ROLE foo {
SET password := 'foo-pass';
}
''')
# bad password
with self.assertRaisesRegex(
edgedb.AuthenticationError,
'authentication failed'):
await self.connect(
user='foo',
password='wrong',
)
# Test wrong password on http basic auth
body, code = await self._basic_http_request(None, 'foo', 'wrong')
self.assertEqual(code, 401, f"Wrong result: {body}")
# good password
conn = await self.connect(
user='foo',
password='foo-pass',
)
await conn.aclose()
body, code = await self._basic_http_request(None, 'foo', 'foo-pass')
self.assertEqual(code, 200, f"Wrong result: {body}")
# Force foo to use a JWT so auth fails
await self.con.query('''
CONFIGURE INSTANCE INSERT Auth {
comment := 'foo-jwt',
priority := -1,
user := 'foo',
method := (INSERT JWT {
transports := "SIMPLE_HTTP",
}),
}
''')
# Should fail now
body, code = await self._basic_http_request(None, 'foo', 'foo-pass')
self.assertEqual(code, 401, f"Wrong result: {body}")
# But *edgedb* should still work
body, code = await self._basic_http_request(None, 'edgedb', None)
self.assertEqual(code, 200, f"Wrong result: {body}")
await self.con.query('''
CONFIGURE INSTANCE RESET Auth
filter .comment = 'foo-jwt'
''')
await self.con.query('''
CONFIGURE INSTANCE INSERT Auth {
comment := 'test',
priority := 0,
method := (INSERT Trust),
}
''')
try:
# bad password, but the trust method doesn't care
conn = await self.connect(
user='foo',
password='wrong',
)
await conn.aclose()
# insert password auth with a higher priority
await self.con.query('''
CONFIGURE INSTANCE INSERT Auth {
comment := 'test-2',
priority := -1,
method := (INSERT SCRAM),
}
''')
with self.assertRaisesRegex(
edgedb.AuthenticationError,
'authentication failed',
):
# bad password is bad again
await self.connect(
user='foo',
password='wrong',
)
finally:
await self.con.query('''
CONFIGURE INSTANCE RESET Auth FILTER .comment = 'test'
''')
await self.con.query('''
CONFIGURE INSTANCE RESET Auth FILTER .comment = 'test-2'
''')
await self.con.query('''
DROP ROLE foo;
''')
# Basically the second test, but we can't run it concurrently
# because disabling Auth above conflicts with the following test
await self.con.query('''
CREATE SUPERUSER ROLE bar {
SET password_hash := 'SCRAM-SHA-256$4096:SHzNmIppMwXnPSWgY2yMvg==$5zmnXMm9+mn2nseKPF1NTKvuoBPVSWgxHrnptxpQgcU=:/c1vJV+MmS7v9vv6CDVo56OyOJkNd3F+m3JIBB1U7ho=';
}
''') # noqa
try:
conn = await self.connect(
user='bar',
password='bar-pass',
)
await conn.aclose()
await self.con.query('''
ALTER ROLE bar {
SET password_hash := 'SCRAM-SHA-256$4096:mWDBY53yzQ4aDet5erBmbg==$ZboQEMuUhC6+1SChp2bx1qSRBZGAnyV4I8T/iK+qeEs=:B7yF2k10tTH2RHayOg3rw4Q6wqf+Fj5CuXR/9CyZ8n8=';
}
''') # noqa
conn = await self.connect(
user='bar',
password='bar-pass-2',
)
await conn.aclose()
# bad (old) password
with self.assertRaisesRegex(
edgedb.AuthenticationError,
'authentication failed'):
await self.connect(
user='bar',
password='bar-pass',
)
with self.assertRaisesRegex(
edgedb.EdgeQLSyntaxError,
'cannot specify both `password` and `password_hash`'
' in the same statement'):
await self.con.query('''
CREATE SUPERUSER ROLE bar1 {
SET password := 'hello';
SET password_hash := 'SCRAM-SHA-256$4096:SHzNmIppMwXnPSWgY2yMvg==$5zmnXMm9+mn2nseKPF1NTKvuoBPVSWgxHrnptxpQgcU=:/c1vJV+MmS7v9vv6CDVo56OyOJkNd3F+m3JIBB1U7ho=';
}
''') # noqa
with self.assertRaisesRegex(
edgedb.InvalidValueError,
'invalid SCRAM verifier'):
await self.con.query('''
CREATE SUPERUSER ROLE bar2 {
SET password_hash := 'SCRAM-BLAKE2B$4096:SHzNmIppMwXnPSWgY2yMvg==$5zmnXMm9+mn2nseKPF1NTKvuoBPVSWgxHrnptxpQgcU=:/c1vJV+MmS7v9vv6CDVo56OyOJkNd3F+m3JIBB1U7ho=';
}
''') # noqa
finally:
await self.con.query("DROP ROLE bar") | )
await self.con.query( | test_server_auth_01 | python | geldata/gel | tests/test_server_auth.py | https://github.com/geldata/gel/blob/master/tests/test_server_auth.py | Apache-2.0 |
async def test_server_auth_02(self):
if not self.has_create_role:
self.skipTest('create role is not supported by the backend')
try:
await self.con.query('''
CREATE SUPERUSER ROLE foo {
SET password := 'foo-pass';
}
''')
await self.con.query('''
CREATE SUPERUSER ROLE bar {
SET password := 'bar-pass';
}
''')
await self.con.query('''
CONFIGURE INSTANCE INSERT Auth {
comment := 'test-02',
priority := 0,
method := (INSERT SCRAM),
user := 'foo',
}
''')
# good password with configured Auth
conn = await self.connect(
user='foo',
password='foo-pass',
)
await conn.aclose()
# good password but Auth is not configured
# (should default to SCRAM and succeed)
conn2 = await self.connect(
user='bar',
password='bar-pass'
)
await conn2.aclose()
finally:
await self.con.query('''
CONFIGURE INSTANCE RESET Auth FILTER .comment = 'test-02'
''')
await self.con.query('''
DROP ROLE foo;
''')
await self.con.query('''
DROP ROLE bar;
''') | )
await self.con.query( | test_server_auth_02 | python | geldata/gel | tests/test_server_auth.py | https://github.com/geldata/gel/blob/master/tests/test_server_auth.py | Apache-2.0 |
async def test_server_auth_jwt_1(self):
jwk_fd, jwk_file = tempfile.mkstemp()
jws = JWKSet()
jws.generate(kid=None, kty="ES256")
with open(jwk_fd, "wb") as f:
f.write(jws.export_pem())
async with tb.start_edgedb_server(
jws_key_file=pathlib.Path(jwk_file),
default_auth_method=args.ServerAuthMethod.JWT,
) as sd:
base_sk = generate_gel_token(jws)
conn = await sd.connect(secret_key=base_sk)
await conn.execute('''
CREATE SUPERUSER ROLE foo {
SET password := 'foo-pass';
}
''')
# Force foo to use passwords for simple auth so auth fails
await conn.query('''
CONFIGURE INSTANCE INSERT Auth {
comment := 'foo-jwt',
priority := -1,
user := 'foo',
method := (INSERT Password {
transports := "SIMPLE_HTTP",
}),
}
''')
await conn.execute('''
CREATE EXTENSION edgeql_http;
CREATE EXTENSION graphql;
''')
await conn.aclose()
with self.assertRaisesRegex(
edgedb.AuthenticationError,
'authentication failed: no authorization data provided',
):
await sd.connect()
# bad secret keys
with self.assertRaisesRegex(
edgedb.AuthenticationError,
'authentication failed: malformed JWT',
):
await sd.connect(secret_key='wrong')
sk = generate_gel_token(jws)
corrupt_sk = sk[:50] + "0" + sk[51:]
with self.assertRaisesRegex(
edgedb.AuthenticationError,
'authentication failed: Verification failed',
):
await sd.connect(secret_key=corrupt_sk)
body, _, code = await self._jwt_http_request(sd, sk=corrupt_sk)
self.assertEqual(code, 401, f"Wrong result: {body}")
body, _, code = await self._jwt_gql_request(sd, sk=corrupt_sk)
self.assertEqual(code, 401, f"Wrong result: {body}")
# Try to mess up the *signature* part of it
wrong_sk = sk[:-20] + ("1" if sk[-20] == "0" else "0") + sk[-20:]
with self.assertRaisesRegex(
edgedb.AuthenticationError,
'authentication failed: Verification failed',
):
await sd.connect(secret_key=wrong_sk)
body, _, code = await self._jwt_http_request(
sd, sk=corrupt_sk, db='non_existant')
self.assertEqual(code, 401, f"Wrong result: {body}")
# Good key (control check, mostly)
body, _, code = await self._jwt_http_request(sd, sk=base_sk)
self.assertEqual(code, 200, f"Wrong result: {body}")
# Good key but nonexistant user
body, _, code = await self._jwt_http_request(
sd, sk=base_sk, username='elonmusk')
self.assertEqual(code, 401, f"Wrong result: {body}")
# Good key but user needs password auth
body, _, code = await self._jwt_http_request(
sd, sk=base_sk, username='foo')
self.assertEqual(code, 401, f"Wrong result: {body}")
good_keys = [
[],
[("roles", ["admin"])],
[("databases", ["main"])],
[("instances", ["localtest"])],
]
for params in good_keys:
params_dict = dict(params)
with self.subTest(**params_dict):
sk = generate_gel_token(jws, **params_dict)
conn = await sd.connect(secret_key=sk)
await conn.aclose()
body, _, code = await self._jwt_http_request(sd, sk=sk)
self.assertEqual(code, 200, f"Wrong result: {body}")
body, _, code = await self._jwt_gql_request(sd, sk=sk)
self.assertEqual(code, 200, f"Wrong result: {body}")
bad_keys = {
(("roles", ("bad-role",)),):
'secret key does not authorize access '
+ 'in role "admin"',
(("databases", ("bad-database",)),):
'secret key does not authorize access '
+ 'to database "main"',
(("instances", ("bad-instance",)),):
'secret key does not authorize access '
+ 'to this instance',
}
for params, msg in bad_keys.items():
params_dict = dict(params)
with self.subTest(**params_dict):
sk = generate_gel_token(jws, **params_dict)
with self.assertRaisesRegex(
edgedb.AuthenticationError,
"authentication failed: " + msg,
):
await sd.connect(secret_key=sk)
body, _, code = await self._jwt_http_request(sd, sk=sk)
self.assertEqual(code, 401, f"Wrong result: {body}")
body, _, code = await self._jwt_gql_request(sd, sk=sk)
self.assertEqual(code, 401, f"Wrong result: {body}") | )
# Force foo to use passwords for simple auth so auth fails
await conn.query( | test_server_auth_jwt_1 | python | geldata/gel | tests/test_server_auth.py | https://github.com/geldata/gel/blob/master/tests/test_server_auth.py | Apache-2.0 |
async def test_server_auth_in_transaction(self):
if not self.has_create_role:
self.skipTest('create role is not supported by the backend')
async with self.con.transaction():
await self.con.query('''
CREATE SUPERUSER ROLE foo {
SET password := 'foo-pass';
};
''')
try:
conn = await self.connect(
user='foo',
password='foo-pass',
)
await conn.aclose()
finally:
await self.con.query('''
DROP ROLE foo;
''') | )
try:
conn = await self.connect(
user='foo',
password='foo-pass',
)
await conn.aclose()
finally:
await self.con.query( | test_server_auth_in_transaction | python | geldata/gel | tests/test_server_auth.py | https://github.com/geldata/gel/blob/master/tests/test_server_auth.py | Apache-2.0 |
def test_edgeql_ir_type_inference_00(self):
"""
SELECT Card { name }
% OK %
default::Card
""" | SELECT Card { name }
% OK %
default::Card | test_edgeql_ir_type_inference_00 | python | geldata/gel | tests/test_edgeql_ir_type_inference.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_type_inference.py | Apache-2.0 |
def test_edgeql_ir_type_inference_01(self):
"""
SELECT Card { name }
% OK %
name: std::str
""" | SELECT Card { name }
% OK %
name: std::str | test_edgeql_ir_type_inference_01 | python | geldata/gel | tests/test_edgeql_ir_type_inference.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_type_inference.py | Apache-2.0 |
def test_edgeql_ir_type_inference_02(self):
"""
SELECT Card UNION User
% OK %
__derived__::(default:Card | default:User)
""" | SELECT Card UNION User
% OK %
__derived__::(default:Card | default:User) | test_edgeql_ir_type_inference_02 | python | geldata/gel | tests/test_edgeql_ir_type_inference.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ir_type_inference.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.