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_graphql_mutation_insert_range_02(self):
# This tests range and multirange values in insertion.
data = {
"name": "New RangeTest02",
"rval": {
"lower": -1.2,
"upper": 3.4,
"inc_lower": True,
"inc_upper": False
},
"mval": [
{
"lower": None,
"upper": -10,
"inc_lower": False,
"inc_upper": False
},
{
"lower": -3,
"upper": 12,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
{
"lower": "2026-10-20",
"upper": None,
"inc_lower": True,
"inc_upper": False
}
]
}
validation_query = r"""
query {
RangeTest(filter: {name: {eq: "New RangeTest02"}}) {
name
rval
mval
rdate
mdate
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_RangeTest(
$name: String!,
$rval: RangeOfFloat,
$mval: [RangeOfFloat!],
$rdate: RangeOfString,
$mdate: [RangeOfString!]
) {
insert_RangeTest(
data: [{
name: $name,
rval: $rval,
mval: $mval,
rdate: $rdate,
mdate: $mdate
}]
) {
name
rval
mval
rdate
mdate
}
}
""", {
"insert_RangeTest": [data]
}, variables=data)
self.assert_graphql_query_result(validation_query, {
"RangeTest": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_RangeTest {
delete_RangeTest(
filter: {name: {eq: "New RangeTest02"}}
) {
name
rval
mval
rdate
mdate
}
}
""", {
"delete_RangeTest": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"RangeTest": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_range_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_01(self):
# Test nested insert.
data = {
'name': 'New UserGroup01',
'settings': [{
'name': 'setting01',
'value': 'aardvark01',
}],
}
validation_query = r"""
query {
UserGroup(filter: {name: {eq: "New UserGroup01"}}) {
name
settings {
name
value
}
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_UserGroup {
insert_UserGroup(
data: [{
name: "New UserGroup01",
settings: [{
data: {
name: "setting01",
value: "aardvark01"
}
}],
}]
) {
name
settings {
name
value
}
}
}
""", {
"insert_UserGroup": [data]
})
self.assert_graphql_query_result(validation_query, {
"UserGroup": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_UserGroup {
delete_UserGroup(filter: {name: {eq: "New UserGroup01"}}) {
name
settings {
name
value
}
}
}
""", {
"delete_UserGroup": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"UserGroup": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_nested_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_02(self):
# Test insert with nested existing object.
data = {
'name': 'New UserGroup02',
'settings': [{
'name': 'setting02',
'value': 'aardvark02'
}],
}
validation_query = r"""
query {
UserGroup(filter: {name: {eq: "New UserGroup02"}}) {
name
settings {
name
value
}
}
}
"""
setting = self.graphql_query(r"""
mutation insert_Setting {
insert_Setting(data: [{
name: "setting02",
value: "aardvark02"
}]) {
id
name
value
}
}
""")['insert_Setting'][0]
self.assert_graphql_query_result(rf"""
mutation insert_UserGroup {{
insert_UserGroup(
data: [{{
name: "New UserGroup02",
settings: [{{
filter: {{
id: {{eq: "{setting['id']}"}}
}}
}}],
}}]
) {{
name
settings {{
name
value
}}
}}
}}
""", {
"insert_UserGroup": [data]
})
self.assert_graphql_query_result(validation_query, {
"UserGroup": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_UserGroup {
delete_UserGroup(filter: {name: {eq: "New UserGroup02"}}) {
name
settings {
name
value
}
}
}
""", {
"delete_UserGroup": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"UserGroup": []
}) | setting = self.graphql_query(r | test_graphql_mutation_insert_nested_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_03(self):
# Test insert with nested existing object.
data = {
'name': 'New UserGroup03',
'settings': [{
'name': 'setting031',
'value': 'aardvark03',
}, {
'name': 'setting032',
'value': 'other03',
}, {
'name': 'setting033',
'value': 'special03',
}],
}
validation_query = r"""
query {
UserGroup(filter: {name: {eq: "New UserGroup03"}}) {
name
settings(order: {name: {dir: ASC}}) {
name
value
}
}
}
"""
settings = self.graphql_query(r"""
mutation insert_Setting {
insert_Setting(data: [{
name: "setting031",
value: "aardvark03"
}, {
name: "setting032",
value: "other03"
}]) {
id
name
value
}
}
""")['insert_Setting']
# nested results aren't fetching correctly
self.assert_graphql_query_result(rf"""
mutation insert_UserGroup {{
insert_UserGroup(
data: [{{
name: "New UserGroup03",
settings: [{{
filter: {{
id: {{eq: "{settings[0]['id']}"}}
}}
}}, {{
data: {{
name: "setting033",
value: "special03",
}}
}}, {{
filter: {{
name: {{eq: "{settings[1]['name']}"}}
}}
}}],
}}]
) {{
name
settings(order: {{name: {{dir: ASC}}}}) {{
name
value
}}
}}
}}
""", {
"insert_UserGroup": [data]
})
self.assert_graphql_query_result(validation_query, {
"UserGroup": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_UserGroup {
delete_UserGroup(filter: {name: {eq: "New UserGroup03"}}) {
name
settings(order: {name: {dir: ASC}}) {
name
value
}
}
}
""", {
"delete_UserGroup": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"UserGroup": []
}) | settings = self.graphql_query(r | test_graphql_mutation_insert_nested_03 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_04(self):
# Test nested insert for a singular link.
data = {
"name": "New User04",
"age": 99,
"score": 99.99,
"profile": {
"name": "Alice profile",
"value": "special"
}
}
validation_query = r"""
query {
User(filter: {name: {eq: "New User04"}}) {
name
age
score
profile {
name
value
}
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_User {
insert_User(
data: [{
name: "New User04",
active: false,
age: 99,
score: 99.99,
profile: {
filter: {
name: {eq: "Alice profile"}
},
first: 1
},
}]
) {
name
age
score
profile {
name
value
}
}
}
""", {
"insert_User": [data]
})
self.assert_graphql_query_result(validation_query, {
"User": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_User {
delete_User(filter: {name: {eq: "New User04"}}) {
name
age
score
profile {
name
value
}
}
}
""", {
"delete_User": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"User": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_nested_04 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_05(self):
# Test nested insert for a singular link.
profile = self.graphql_query(r"""
query {
Profile(filter: {
name: {eq: "Alice profile"}
}) {
id
name
value
}
}
""")['Profile'][0]
data = {
"name": "New User05",
"age": 99,
"score": 99.99,
"profile": profile
}
validation_query = r"""
query {
User(filter: {name: {eq: "New User05"}}) {
name
age
score
profile {
id
name
value
}
}
}
"""
self.assert_graphql_query_result(rf"""
mutation insert_User {{
insert_User(
data: [{{
name: "New User05",
active: false,
age: 99,
score: 99.99,
profile: {{
filter: {{
id: {{eq: "{profile['id']}"}}
}},
first: 1
}},
}}]
) {{
name
age
score
profile {{
id
name
value
}}
}}
}}
""", {
"insert_User": [data]
})
self.assert_graphql_query_result(validation_query, {
"User": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_User {
delete_User(filter: {name: {eq: "New User05"}}) {
name
age
score
profile {
id
name
value
}
}
}
""", {
"delete_User": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"User": []
}) | )['Profile'][0]
data = {
"name": "New User05",
"age": 99,
"score": 99.99,
"profile": profile
}
validation_query = r | test_graphql_mutation_insert_nested_05 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_06(self):
# Test delete based on nested field.
data = {
'name': 'New UserGroup06',
'settings': [{
'name': 'setting06',
'value': 'aardvark06',
}],
}
validation_query = r"""
query {
UserGroup(
filter: {settings: {name: {eq: "setting06"}}}
) {
name
settings {
name
value
}
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_UserGroup {
insert_UserGroup(
data: [{
name: "New UserGroup06",
settings: [{
data: {
name: "setting06",
value: "aardvark06"
}
}],
}]
) {
name
settings {
name
value
}
}
}
""", {
"insert_UserGroup": [data]
})
self.assert_graphql_query_result(validation_query, {
"UserGroup": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_UserGroup {
delete_UserGroup(
filter: {settings: {name: {eq: "setting06"}}}
) {
name
settings {
name
value
}
}
}
""", {
"delete_UserGroup": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"UserGroup": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_nested_06 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_07(self):
# Test insert with nested object filter.
data = {
"name": "New User07",
"age": 33,
"score": 33.33,
"groups": [{
'name': 'New UserGroup07',
'settings': [{
'name': 'setting07',
'value': 'aardvark07',
}],
}]
}
validation_query = r"""
query {
User(
filter: {groups: {settings: {name: {eq: "setting07"}}}}
) {
name
age
score
groups {
name
settings {
name
value
}
}
}
}
"""
# insert the user groups first
self.assert_graphql_query_result(r"""
mutation insert_UserGroup {
insert_UserGroup(
data: [{
name: "New UserGroup07",
settings: [{
data: {
name: "setting07",
value: "aardvark07"
}
}],
}]
) {
name
settings {
name
value
}
}
}
""", {
"insert_UserGroup": [data['groups'][0]]
})
# insert the User
self.assert_graphql_query_result(r"""
mutation insert_User {
insert_User(
data: [{
name: "New User07",
active: true,
age: 33,
score: 33.33,
groups: {
filter: {
settings: {name: {eq: "setting07"}}
},
first: 1
},
}]
) {
name
age
score
groups {
name
settings {
name
value
}
}
}
}
""", {
"insert_User": [data]
})
self.assert_graphql_query_result(validation_query, {
"User": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_User {
delete_User(
filter: {groups: {settings: {name: {eq: "setting07"}}}}
) {
name
age
score
groups {
name
settings {
name
value
}
}
}
}
""", {
"delete_User": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"User": []
})
# cleanup
self.assert_graphql_query_result(r"""
mutation delete_UserGroup {
delete_UserGroup(
filter: {settings: {name: {eq: "setting07"}}}
) {
name
settings {
name
value
}
}
}
""", {
"delete_UserGroup": data['groups']
}) | # insert the user groups first
self.assert_graphql_query_result(r | test_graphql_mutation_insert_nested_07 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_08(self):
# Issue #1243
# Test nested insert.
data = {
'name': 'Strategy01',
'games': [{
'name': 'SomeGame01',
'players': [{
'name': 'Alice'
}]
}],
}
validation_query = r"""
query {
Genre(filter: {name: {eq: "Strategy01"}}) {
name
games {
name
players {
name
}
}
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_genre {
insert_Genre(data: [
{
name: "Strategy01",
games: [{
data: {
name: "SomeGame01",
players: [{
filter: {name: {eq: "Alice"}}
}]
}
}]
}
]) {
name
games {
name
players {
name
}
}
}
}
""", {
"insert_Genre": [data]
})
self.assert_graphql_query_result(validation_query, {
"Genre": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_Genre {
delete_Genre(filter: {name: {eq: "Strategy01"}}) {
name
games {
name
players {
name
}
}
}
}
""", {
"delete_Genre": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"Genre": []
})
self.assert_graphql_query_result(r"""
mutation delete_Game {
delete_Game(filter: {name: {eq: "SomeGame01"}}) {
name
players {
name
}
}
}
""", {
"delete_Game": data['games']
})
# validate that the deletion worked
self.assert_graphql_query_result(r'''
query {
Game(filter: {name: {eq: "SomeGame01"}}) {
name
players {
name
}
}
}
''', {
"Game": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_nested_08 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_09(self):
# Issue #3470
# Test nested insert of the same type.
data = {
'after': 'BaseFoo09',
'color': 'GREEN',
'foos': [{
'after': 'NestedFoo090',
'color': 'RED',
}, {
'after': 'NestedFoo091',
'color': 'BLUE',
}],
}
validation_query = r"""
query {
other__Foo(filter: {after: {eq: "BaseFoo09"}}) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
after: "BaseFoo09",
color: GREEN,
foos: [{
data: {
after: "NestedFoo090",
color: RED,
}
}, {
data: {
after: "NestedFoo091",
color: BLUE,
}
}]
}]
) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
""", {
"insert_other__Foo": [data]
})
self.assert_graphql_query_result(validation_query, {
"other__Foo": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {after: {like: "%Foo09%"}},
order: {color: {dir: ASC}}
) {
after
color
}
}
""", {
"delete_other__Foo": [{
'after': 'NestedFoo090',
'color': 'RED',
}, {
'after': 'BaseFoo09',
'color': 'GREEN',
}, {
'after': 'NestedFoo091',
'color': 'BLUE',
}]
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_nested_09 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_nested_10(self):
# Issue #3470
# Test nested insert of the same type.
data = {
'after': 'BaseFoo10',
'color': 'GREEN',
'foos': [{
'after': 'NestedFoo100',
'color': 'RED',
}, {
'after': 'NestedFoo101',
'color': 'BLUE',
}],
}
validation_query = r"""
query {
other__Foo(filter: {after: {eq: "BaseFoo10"}}) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
after: "NestedFoo100",
color: RED,
}]
) {
after
color
}
}
""", {
"insert_other__Foo": [data['foos'][0]]
})
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
after: "BaseFoo10",
color: GREEN,
foos: [{
filter: {
after: {eq: "NestedFoo100"},
}
}, {
data: {
after: "NestedFoo101",
color: BLUE,
}
}]
}]
) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
""", {
"insert_other__Foo": [data]
})
self.assert_graphql_query_result(validation_query, {
"other__Foo": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {after: {like: "%Foo10%"}},
order: {color: {dir: ASC}}
) {
after
color
}
}
""", {
"delete_other__Foo": [{
'after': 'NestedFoo100',
'color': 'RED',
}, {
'after': 'BaseFoo10',
'color': 'GREEN',
}, {
'after': 'NestedFoo101',
'color': 'BLUE',
}]
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_nested_10 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_multiple_01(self):
# Issue #1566
# Test multiple mutations.
data_s = {
'name': 'multisetting01',
'value': 'yellow',
}
data_p = {
'name': 'multiprofile01',
'value': 'multirofile',
}
validation_query = r"""
query {
Setting(filter: {name: {eq: "multisetting01"}}) {
name
value
}
Profile(filter: {name: {eq: "multiprofile01"}}) {
name
value
}
}
"""
self.assert_graphql_query_result(r"""
mutation multi_insert {
insert_Setting(
data: [{
name: "multisetting01",
value: "yellow"
}]
) {
name
value
}
insert_Profile(
data: [{
name: "multiprofile01",
value: "multirofile"
}]
) {
name
value
}
}
""", {
"insert_Setting": [data_s],
"insert_Profile": [data_p]
})
self.assert_graphql_query_result(validation_query, {
"Setting": [data_s],
"Profile": [data_p],
})
self.assert_graphql_query_result(r"""
mutation multi_delete {
delete_Setting(
filter: {
name: {eq: "multisetting01"}
}
) {
name
value
}
delete_Profile(
filter: {
name: {eq: "multiprofile01"}
}
) {
name
value
}
}
""", {
"delete_Setting": [data_s],
"delete_Profile": [data_p]
})
self.assert_graphql_query_result(validation_query, {
"Setting": [],
"Profile": [],
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_multiple_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_default_01(self):
# Test insert object with a required property with a default.
data = {
'name': 'New InactiveUser01',
'age': 99,
'active': False,
'score': 0,
}
validation_query = r"""
query {
User(filter: {name: {eq: "New InactiveUser01"}}) {
name
age
active
score
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_User {
insert_User(
data: [{
name: "New InactiveUser01",
age: 99
}]
) {
name
age
active
score
}
}
""", {
"insert_User": [data]
})
self.assert_graphql_query_result(validation_query, {
"User": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_User {
delete_User(filter: {name: {eq: "New InactiveUser01"}}) {
name
age
active
score
}
}
""", {
"delete_User": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"User": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_default_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_readonly_01(self):
# Test insert object with a readonly property
data = {
'__typename': 'NotEditable_Type',
'once': 'New NotEditable01',
'computed': 'a computed value',
}
validation_query = r"""
query {
NotEditable(filter: {once: {eq: "New NotEditable01"}}) {
__typename
once
computed
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_NotEditable {
insert_NotEditable(
data: [{
once: "New NotEditable01",
}]
) {
__typename
once
computed
}
}
""", {
"insert_NotEditable": [data]
})
self.assert_graphql_query_result(validation_query, {
"NotEditable": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_NotEditable {
delete_NotEditable(filter: {once: {eq: "New NotEditable01"}}) {
__typename
once
computed
}
}
""", {
"delete_NotEditable": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"NotEditable": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_readonly_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_readonly_02(self):
# Test insert object without any properties that can be set
data = {
'__typename': 'Fixed_Type',
'computed': 123,
}
validation_query = r"""
query {
Fixed {
__typename
computed
}
}
"""
self.assert_graphql_query_result(validation_query, {
"Fixed": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_Fixed {
delete_Fixed {
__typename
computed
}
}
""", {
"delete_Fixed": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"Fixed": []
})
self.assert_graphql_query_result(r"""
mutation insert_Fixed {
insert_Fixed {
__typename
computed
}
}
""", {
"insert_Fixed": [data]
})
self.assert_graphql_query_result(validation_query, {
"Fixed": [data]
}) | self.assert_graphql_query_result(validation_query, {
"Fixed": [data]
})
self.assert_graphql_query_result(r | test_graphql_mutation_insert_readonly_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_insert_typename_01(self):
# This tests the typename funcitonality after insertion.
# Issue #5985
data = {
'__typename': 'other__Foo_Type',
'select': 'New TypenameTest01',
'color': 'GREEN',
}
validation_query = r"""
query {
__typename
other__Foo(filter: {select: {eq: "New TypenameTest01"}}) {
__typename
select
color
}
}
"""
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
__typename
insert_other__Foo(
data: [{
select: "New TypenameTest01",
color: GREEN,
}]
) {
__typename
select
color
}
}
""", {
"__typename": 'Mutation',
"insert_other__Foo": [data]
})
self.assert_graphql_query_result(validation_query, {
"__typename": 'Query',
"other__Foo": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
__typename
delete_other__Foo(
filter: {select: {eq: "New TypenameTest01"}}
) {
__typename
select
color
}
}
""", {
"__typename": 'Mutation',
"delete_other__Foo": [data]
})
# validate that the deletion worked
self.assert_graphql_query_result(validation_query, {
"other__Foo": []
}) | self.assert_graphql_query_result(r | test_graphql_mutation_insert_typename_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_scalars_01(self):
orig_data = {
'p_bool': True,
'p_str': 'Hello world',
'p_datetime': '2018-05-07T20:01:22.306916+00:00',
'p_local_datetime': '2018-05-07T20:01:22.306916',
'p_local_date': '2018-05-07',
'p_local_time': '20:01:22.306916',
'p_duration': 'PT20H',
'p_int16': 12345,
'p_int32': 1234567890,
'p_int64': 1234567890123,
'p_bigint': 123456789123456789123456789,
'p_float32': 2.5,
'p_float64': 2.5,
'p_decimal':
123456789123456789123456789.123456789123456789123456789,
}
data = {
'p_bool': False,
'p_str': 'Update ScalarTest01',
'p_datetime': '2019-05-01T01:02:35.196811+00:00',
'p_local_datetime': '2019-05-01T01:02:35.196811',
'p_local_date': '2019-05-01',
'p_local_time': '01:02:35.196811',
'p_duration': 'PT21H30M',
'p_int16': 4321,
'p_int32': 876543210,
# Some GraphQL implementations seem to have a limitation
# of not being able to handle 64-bit integer literals
# (GraphiQL is among them).
'p_int64': 876543210,
'p_bigint': 333333333333333333333333333,
'p_float32': 4.5,
'p_float64': 4.5,
'p_decimal':
444444444444444444444444444.222222222222222222222222222,
}
validation_query = rf"""
query {{
ScalarTest(
filter: {{
or: [{{
p_str: {{eq: "{orig_data['p_str']}"}}
}}, {{
p_str: {{eq: "{data['p_str']}"}}
}}]
}}
) {{
p_bool
p_str
p_datetime
p_local_datetime
p_local_date
p_local_time
p_duration
p_int16
p_int32
p_int64
p_bigint
p_float32
p_float64
p_decimal
}}
}}
"""
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
data: {
p_bool: {set: false},
p_str: {set: "Update ScalarTest01"},
p_datetime: {set: "2019-05-01T01:02:35.196811+00:00"},
p_local_datetime: {set: "2019-05-01T01:02:35.196811"},
p_local_date: {set: "2019-05-01"},
p_local_time: {set: "01:02:35.196811"},
p_duration: {set: "PT21H30M"},
p_int16: {set: 4321},
p_int32: {set: 876543210},
# Some GraphQL implementations seem to have a
# limitation of not being able to handle 64-bit
# integer literals (GraphiQL is among them).
p_int64: {set: 876543210},
p_bigint: {set: 333333333333333333333333333},
p_float32: {set: 4.5},
p_float64: {set: 4.5},
p_decimal: {set:
444444444444444444444444444.222222222222222222222222222},
}
) {
p_bool
p_str
p_datetime
p_local_datetime
p_local_date
p_local_time
p_duration
p_int16
p_int32
p_int64
p_bigint
p_float32
p_float64
p_decimal
}
}
""", {
"update_ScalarTest": [data]
})
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [data]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest(
$p_bool: Boolean,
$p_str: String,
$p_datetime: String,
$p_local_datetime: String,
$p_local_date: String,
$p_local_time: String,
$p_duration: String,
$p_int16: Int,
$p_int32: Int,
$p_int64: Int64,
$p_bigint: Bigint,
$p_float32: Float,
$p_float64: Float,
$p_decimal: Decimal,
) {
update_ScalarTest(
data: {
p_bool: {set: $p_bool},
p_str: {set: $p_str},
p_datetime: {set: $p_datetime},
p_local_datetime: {set: $p_local_datetime},
p_local_date: {set: $p_local_date},
p_local_time: {set: $p_local_time},
p_duration: {set: $p_duration},
p_int16: {set: $p_int16},
p_int32: {set: $p_int32},
p_int64: {set: $p_int64},
p_bigint: {set: $p_bigint},
p_float32: {set: $p_float32},
p_float64: {set: $p_float64},
p_decimal: {set: $p_decimal},
}
) {
p_bool
p_str
p_datetime
p_local_datetime
p_local_date
p_local_time
p_duration
p_int16
p_int32
p_int64
p_bigint
p_float32
p_float64
p_decimal
}
}
""", {
"update_ScalarTest": [orig_data]
}, variables=orig_data)
# validate that the final update worked
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
}) | self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_scalars_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_scalars_02(self):
orig_data = {
'p_str': 'Hello world',
'p_posint': 42,
'p_short_str': 'hello',
}
data = {
'p_str': 'Update ScalarTest02',
'p_posint': 9999,
'p_short_str': 'hi',
}
validation_query = rf"""
query {{
ScalarTest(
filter: {{
or: [{{
p_str: {{eq: "{orig_data['p_str']}"}}
}}, {{
p_str: {{eq: "{data['p_str']}"}}
}}]
}}
) {{
p_str
p_posint
p_short_str
}}
}}
"""
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
data: {
p_str: {set: "Update ScalarTest02"},
p_posint: {set: 9999},
p_short_str: {set: "hi"},
}
) {
p_str
p_posint
p_short_str
}
}
""", {
"update_ScalarTest": [data]
})
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [data]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest(
$p_str: String,
$p_posint: Int64,
$p_short_str: String,
) {
update_ScalarTest(
data: {
p_str: {set: $p_str},
p_posint: {set: $p_posint},
p_short_str: {set: $p_short_str},
}
) {
p_str
p_posint
p_short_str
}
}
""", {
"update_ScalarTest": [orig_data]
}, variables=orig_data)
# validate that the final update worked
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
}) | self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_scalars_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_scalars_03(self):
orig_data = {
'p_str': 'Hello world',
'p_json': {"foo": [1, None, "bar"]},
}
data = {
'p_str': 'Update ScalarTest03',
'p_json': {"bar": [None, 2, "aardvark"]},
}
validation_query = rf"""
query {{
ScalarTest(
filter: {{
or: [{{
p_str: {{eq: "{orig_data['p_str']}"}}
}}, {{
p_str: {{eq: "{data['p_str']}"}}
}}]
}}
) {{
p_str
p_json
}}
}}
"""
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
})
# Test that basic and complex JSON values can be updated
for json_val in [data['p_json'], data['p_json']['bar'],
True, 123, "hello world", None]:
data['p_json'] = json_val
self.assert_graphql_query_result(
r"""
mutation update_ScalarTest(
$p_str: String!,
$p_json: JSON
) {
update_ScalarTest(
data: {
p_str: {set: $p_str},
p_json: {set: $p_json},
}
) {
p_str
p_json
}
}
""", {
"update_ScalarTest": [data]
},
variables=data
)
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [data]
})
self.assert_graphql_query_result(
r"""
mutation update_ScalarTest(
$p_str: String,
$p_json: JSON,
) {
update_ScalarTest(
data: {
p_str: {set: $p_str},
p_json: {set: $p_json},
}
) {
p_str
p_json
}
}
""", {
"update_ScalarTest": [orig_data]
},
variables=orig_data
)
# validate that the final update worked
self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
}) | self.assert_graphql_query_result(validation_query, {
"ScalarTest": [orig_data]
})
# Test that basic and complex JSON values can be updated
for json_val in [data['p_json'], data['p_json']['bar'],
True, 123, "hello world", None]:
data['p_json'] = json_val
self.assert_graphql_query_result(
r | test_graphql_mutation_update_scalars_03 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_scalars_04(self):
# This tests update ops for various numerical types.
self.assert_graphql_query_result(r"""
mutation insert_ScalarTest {
insert_ScalarTest(
data: [{
p_str: "Update ScalarTest04",
p_int16: 0,
p_int32: 0,
p_int64: 0,
p_bigint: 0,
p_float32: 0,
p_float64: 0,
p_decimal: 0,
}]
) {
p_str
p_int16
p_int32
p_int64
p_bigint
p_float32
p_float64
p_decimal
}
}
""", {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest04',
'p_int16': 0,
'p_int32': 0,
'p_int64': 0,
'p_bigint': 0,
'p_float32': 0,
'p_float64': 0,
'p_decimal': 0,
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest04"}}
data: {
p_int16: {increment: 2},
p_int32: {increment: 2},
p_int64: {increment: 2},
p_bigint: {increment: 2},
p_float32: {increment: 1.5},
p_float64: {increment: 1.5},
p_decimal: {increment: 1.5},
}
) {
p_str
p_int16
p_int32
p_int64
p_bigint
p_float32
p_float64
p_decimal
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest04',
'p_int16': 2,
'p_int32': 2,
'p_int64': 2,
'p_bigint': 2,
'p_float32': 1.5,
'p_float64': 1.5,
'p_decimal': 1.5,
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest04"}}
data: {
p_int16: {decrement: 1},
p_int32: {decrement: 1},
p_int64: {decrement: 1},
p_bigint: {decrement: 1},
p_float32: {decrement: 0.4},
p_float64: {decrement: 0.4},
p_decimal: {decrement: 0.4},
}
) {
p_str
p_int16
p_int32
p_int64
p_bigint
p_float32
p_float64
p_decimal
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest04',
'p_int16': 1,
'p_int32': 1,
'p_int64': 1,
'p_bigint': 1,
'p_float32': 1.1,
'p_float64': 1.1,
'p_decimal': 1.1,
}]
})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_ScalarTest {
delete_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest04"}}
) {
p_str
p_int16
p_int32
p_int64
p_bigint
p_float32
p_float64
p_decimal
}
}
""", {
"delete_ScalarTest": [{
'p_str': 'Update ScalarTest04',
'p_int16': 1,
'p_int32': 1,
'p_int64': 1,
'p_bigint': 1,
'p_float32': 1.1,
'p_float64': 1.1,
'p_decimal': 1.1,
}]
}) | , {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest04',
'p_int16': 0,
'p_int32': 0,
'p_int64': 0,
'p_bigint': 0,
'p_float32': 0,
'p_float64': 0,
'p_decimal': 0,
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_scalars_04 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_scalars_05(self):
# This tests update ops for various numerical types.
self.assert_graphql_query_result(r"""
mutation insert_ScalarTest {
insert_ScalarTest(
data: [{
p_str: "Update ScalarTest05",
}]
) {
p_str
}
}
""", {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest05',
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {like: "%Update ScalarTest05%"}}
data: {
p_str: {prepend: "--"},
}
) {
p_str
}
}
""", {
"update_ScalarTest": [{
'p_str': '--Update ScalarTest05',
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {like: "%Update ScalarTest05%"}}
data: {
p_str: {append: "!!!"},
}
) {
p_str
}
}
""", {
"update_ScalarTest": [{
'p_str': '--Update ScalarTest05!!!',
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {like: "%Update ScalarTest05%"}}
data: {
p_str: {slice: [1]},
}
) {
p_str
}
}
""", {
"update_ScalarTest": [{
'p_str': '-Update ScalarTest05!!!',
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {like: "%Update ScalarTest05%"}}
data: {
p_str: {slice: [0, -1]},
}
) {
p_str
}
}
""", {
"update_ScalarTest": [{
'p_str': '-Update ScalarTest05!!',
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {like: "%Update ScalarTest05%"}}
data: {
p_str: {slice: [1, -2]},
}
) {
p_str
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest05',
}]
})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_ScalarTest {
delete_ScalarTest(
filter: {p_str: {like: "%Update ScalarTest05%"}}
) {
p_str
}
}
""", {
"delete_ScalarTest": [{
'p_str': 'Update ScalarTest05',
}]
}) | , {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest05',
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_scalars_05 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_scalars_06(self):
# This tests update ops for various numerical types.
self.assert_graphql_query_result(r"""
mutation insert_ScalarTest {
insert_ScalarTest(
data: [{
p_str: "Update ScalarTest06",
p_array_str: ["world"],
p_array_int64: [0],
}]
) {
p_str
p_array_str
p_array_int64
}
}
""", {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest06',
'p_array_str': ['world'],
'p_array_int64': [0],
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest06"}}
data: {
p_array_str: {prepend: ["Hello"]},
p_array_int64: {prepend: [1, 2]},
}
) {
p_str
p_array_str
p_array_int64
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest06',
'p_array_str': ['Hello', 'world'],
'p_array_int64': [1, 2, 0],
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest06"}}
data: {
p_array_str: {append: ["!"]},
p_array_int64: {append: [3, 4]},
}
) {
p_str
p_array_str
p_array_int64
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest06',
'p_array_str': ['Hello', 'world', '!'],
'p_array_int64': [1, 2, 0, 3, 4],
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest06"}}
data: {
p_array_str: {slice: [1]},
p_array_int64: {slice: [1]},
}
) {
p_str
p_array_str
p_array_int64
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest06',
'p_array_str': ['world', '!'],
'p_array_int64': [2, 0, 3, 4],
}]
})
self.assert_graphql_query_result(r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest06"}}
data: {
p_array_str: {slice: [1, -2]},
p_array_int64: {slice: [1, -2]},
}
) {
p_str
p_array_str
p_array_int64
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest06',
'p_array_str': [],
'p_array_int64': [0],
}]
})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_ScalarTest {
delete_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest06"}}
) {
p_str
p_array_str
p_array_int64
}
}
""", {
"delete_ScalarTest": [{
'p_str': 'Update ScalarTest06',
'p_array_str': [],
'p_array_int64': [0],
}]
}) | , {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest06',
'p_array_str': ['world'],
'p_array_int64': [0],
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_scalars_06 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_scalars_07(self):
# This tests array of JSON mutations. JSON can only be
# mutated via a variable.
data = {
'el0': {"foo": [1, None, "aardvark"]},
'el1': False,
}
self.assert_graphql_query_result(
r"""
mutation insert_ScalarTest($el0: JSON!, $el1: JSON!) {
insert_ScalarTest(
data: [{
p_str: "Update ScalarTest07",
p_array_json: [$el0, $el1],
}]
) {
p_str
p_array_json
}
}
""", {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest07',
'p_array_json': [data['el0'], data['el1']],
}]
},
variables=data,
)
self.assert_graphql_query_result(
r"""
mutation update_ScalarTest($el: JSON!) {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest07"}}
data: {
p_array_json: {prepend: [$el]},
}
) {
p_str
p_array_json
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest07',
'p_array_json': ["first", data['el0'], data['el1']],
}]
},
variables={"el": "first"}
)
self.assert_graphql_query_result(
r"""
mutation update_ScalarTest($el: JSON!) {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest07"}}
data: {
p_array_json: {append: [$el]},
}
) {
p_str
p_array_json
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest07',
'p_array_json': ["first", data['el0'], data['el1'], 9999],
}]
},
variables={"el": 9999}
)
self.assert_graphql_query_result(
r"""
mutation update_ScalarTest {
update_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest07"}}
data: {
p_array_json: {slice: [1, 3]},
}
) {
p_str
p_array_json
}
}
""", {
"update_ScalarTest": [{
'p_str': 'Update ScalarTest07',
'p_array_json': [data['el0'], data['el1']],
}]
}
)
# clean up
self.assert_graphql_query_result(
r"""
mutation delete_ScalarTest {
delete_ScalarTest(
filter: {p_str: {eq: "Update ScalarTest07"}}
) {
p_str
p_array_json
}
}
""", {
"delete_ScalarTest": [{
'p_str': 'Update ScalarTest07',
'p_array_json': [data['el0'], data['el1']],
}]
}
) | , {
"insert_ScalarTest": [{
'p_str': 'Update ScalarTest07',
'p_array_json': [data['el0'], data['el1']],
}]
},
variables=data,
)
self.assert_graphql_query_result(
r | test_graphql_mutation_update_scalars_07 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_enum_01(self):
# This tests enum values in updates.
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
select: "Update EnumTest01",
color: BLUE
}]
) {
select
color
}
}
""", {
"insert_other__Foo": [{
'select': 'Update EnumTest01',
'color': 'BLUE',
}]
})
self.assert_graphql_query_result(r"""
mutation update_other__Foo {
update_other__Foo(
filter: {select: {eq: "Update EnumTest01"}}
data: {
color: {set: RED}
}
) {
select
color
}
}
""", {
"update_other__Foo": [{
'select': 'Update EnumTest01',
'color': 'RED',
}]
})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {select: {eq: "Update EnumTest01"}}
) {
select
color
}
}
""", {
"delete_other__Foo": [{
'select': 'Update EnumTest01',
'color': 'RED',
}]
}) | , {
"insert_other__Foo": [{
'select': 'Update EnumTest01',
'color': 'BLUE',
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_enum_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_enum_02(self):
# This tests enum values in updates using variables.
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
select: "Update EnumTest02",
color: BLUE
}]
) {
select
color
}
}
""", {
"insert_other__Foo": [{
'select': 'Update EnumTest02',
'color': 'BLUE',
}]
})
self.assert_graphql_query_result(r"""
mutation update_other__Foo (
$color: other__ColorEnum!
) {
update_other__Foo(
filter: {select: {eq: "Update EnumTest02"}}
data: {
color: {set: $color}
}
) {
select
color
}
}
""", {
"update_other__Foo": [{
'select': 'Update EnumTest02',
'color': 'RED',
}]
}, variables={"color": "RED"})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {select: {eq: "Update EnumTest02"}}
) {
select
color
}
}
""", {
"delete_other__Foo": [{
'select': 'Update EnumTest02',
'color': 'RED',
}]
}) | , {
"insert_other__Foo": [{
'select': 'Update EnumTest02',
'color': 'BLUE',
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_enum_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_enum_03(self):
# This tests enum values in updates.
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
select: "Update EnumTest03",
color: BLUE,
color_array: [RED, BLUE, BLUE]
}]
) {
select
color
color_array
}
}
""", {
"insert_other__Foo": [{
'select': 'Update EnumTest03',
'color': 'BLUE',
'color_array': ['RED', 'BLUE', 'BLUE'],
}]
})
self.assert_graphql_query_result(r"""
mutation update_other__Foo {
update_other__Foo(
filter: {select: {eq: "Update EnumTest03"}}
data: {
color_array: {append: [GREEN]}
}
) {
select
color_array
}
}
""", {
"update_other__Foo": [{
'select': 'Update EnumTest03',
'color_array': ['RED', 'BLUE', 'BLUE', 'GREEN'],
}]
})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {select: {eq: "Update EnumTest03"}}
) {
select
color_array
}
}
""", {
"delete_other__Foo": [{
'select': 'Update EnumTest03',
'color_array': ['RED', 'BLUE', 'BLUE', 'GREEN'],
}]
}) | , {
"insert_other__Foo": [{
'select': 'Update EnumTest03',
'color': 'BLUE',
'color_array': ['RED', 'BLUE', 'BLUE'],
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_enum_03 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_enum_04(self):
# This tests enum values in updates.
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
select: "Update EnumTest04",
color: BLUE,
multi_color: [RED, BLUE]
}]
) {
select
color
multi_color
}
}
""", {
"insert_other__Foo": [{
'select': 'Update EnumTest04',
'color': 'BLUE',
'multi_color': ['RED', 'BLUE'],
}]
})
self.assert_graphql_query_result(r"""
mutation update_other__Foo {
update_other__Foo(
filter: {select: {eq: "Update EnumTest04"}}
data: {
multi_color: {add: GREEN}
}
) {
select
multi_color
}
}
""", {
"update_other__Foo": [{
'select': 'Update EnumTest04',
'multi_color': {'RED', 'BLUE', 'GREEN'},
}]
})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {select: {eq: "Update EnumTest04"}}
) {
select
multi_color
}
}
""", {
"delete_other__Foo": [{
'select': 'Update EnumTest04',
'multi_color': {'RED', 'BLUE', 'GREEN'},
}]
}) | , {
"insert_other__Foo": [{
'select': 'Update EnumTest04',
'color': 'BLUE',
'multi_color': ['RED', 'BLUE'],
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_enum_04 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_range_01(self):
# This tests range and multirange values in updates.
self.assert_graphql_query_result(r"""
mutation insert_RangeTest {
insert_RangeTest(
data: [{
name: "Update RangeTest01",
rval: {
lower: -1.2,
upper: 3.4,
inc_lower: true,
inc_upper: false
},
mval: [
{
lower: null,
upper: -10,
inc_lower: false,
inc_upper: false
},
{
lower: -3,
upper: 12,
inc_lower: true,
inc_upper: false
},
],
rdate: {
lower: "2019-02-13",
upper: "2023-08-29",
inc_lower: true,
inc_upper: false
},
mdate: [
{
lower: "2019-02-13",
upper: "2023-08-29",
inc_lower: true,
inc_upper: false
},
{
lower: "2026-10-20",
upper: null,
inc_lower: true,
inc_upper: false
}
]
}]
) {
name
rval
mval
rdate
mdate
}
}
""", {
"insert_RangeTest": [{
"name": "Update RangeTest01",
"rval": {
"lower": -1.2,
"upper": 3.4,
"inc_lower": True,
"inc_upper": False
},
"mval": [
{
"lower": None,
"upper": -10,
"inc_lower": False,
"inc_upper": False
},
{
"lower": -3,
"upper": 12,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
{
"lower": "2026-10-20",
"upper": None,
"inc_lower": True,
"inc_upper": False
}
]
}]
})
self.assert_graphql_query_result(r"""
mutation update_RangeTest {
update_RangeTest(
filter: {name: {eq: "Update RangeTest01"}},
data: {
rval: {
set: {
lower: 5.6,
upper: 7.8,
inc_lower: true,
inc_upper: true
}
},
mval: {
set: [
{
lower: 0,
upper: 1.2,
inc_lower: true,
inc_upper: false
},
]
},
rdate: {
set: {
lower: "2018-12-10",
upper: "2022-10-20",
inc_lower: true,
inc_upper: false
}
},
mdate: {
set: [
{
lower: null,
upper: "2019-02-13",
inc_lower: true,
inc_upper: false
},
{
lower: "2023-08-29",
upper: "2026-10-20",
inc_lower: true,
inc_upper: false
}
]
}
}
) {
name
rval
mval
rdate
mdate
}
}
""", {
"update_RangeTest": [{
"name": "Update RangeTest01",
"rval": {
"lower": 5.6,
"upper": 7.8,
"inc_lower": True,
"inc_upper": True
},
"mval": [
{
"lower": 0,
"upper": 1.2,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2018-12-10",
"upper": "2022-10-20",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": None,
"upper": "2019-02-13",
"inc_lower": False,
"inc_upper": False
},
{
"lower": "2023-08-29",
"upper": "2026-10-20",
"inc_lower": True,
"inc_upper": False
}
]
}]
})
# Cleanup
self.assert_graphql_query_result(r"""
mutation delete_RangeTest {
delete_RangeTest(
filter: {name: {eq: "Update RangeTest01"}}
) {
name
}
}
""", {
"delete_RangeTest": [{"name": "Update RangeTest01"}]
}) | , {
"insert_RangeTest": [{
"name": "Update RangeTest01",
"rval": {
"lower": -1.2,
"upper": 3.4,
"inc_lower": True,
"inc_upper": False
},
"mval": [
{
"lower": None,
"upper": -10,
"inc_lower": False,
"inc_upper": False
},
{
"lower": -3,
"upper": 12,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
{
"lower": "2026-10-20",
"upper": None,
"inc_lower": True,
"inc_upper": False
}
]
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_range_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_range_02(self):
# This tests range and multirange values in insertion.
self.assert_graphql_query_result(r"""
mutation insert_RangeTest {
insert_RangeTest(
data: [{
name: "Update RangeTest02",
rval: {
lower: -1.2,
upper: 3.4,
inc_lower: true,
inc_upper: false
},
mval: [
{
lower: null,
upper: -10,
inc_lower: false,
inc_upper: false
},
{
lower: -3,
upper: 12,
inc_lower: true,
inc_upper: false
},
],
rdate: {
lower: "2019-02-13",
upper: "2023-08-29",
inc_lower: true,
inc_upper: false
},
mdate: [
{
lower: "2019-02-13",
upper: "2023-08-29",
inc_lower: true,
inc_upper: false
},
{
lower: "2026-10-20",
upper: null,
inc_lower: true,
inc_upper: false
}
]
}]
) {
name
rval
mval
rdate
mdate
}
}
""", {
"insert_RangeTest": [{
"name": "Update RangeTest02",
"rval": {
"lower": -1.2,
"upper": 3.4,
"inc_lower": True,
"inc_upper": False
},
"mval": [
{
"lower": None,
"upper": -10,
"inc_lower": False,
"inc_upper": False
},
{
"lower": -3,
"upper": 12,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
{
"lower": "2026-10-20",
"upper": None,
"inc_lower": True,
"inc_upper": False
}
]
}]
})
self.assert_graphql_query_result(r"""
mutation update_RangeTest(
$rval: RangeOfFloat,
$mval: [RangeOfFloat!],
$rdate: RangeOfString,
$mdate: [RangeOfString!]
) {
update_RangeTest(
filter: {name: {eq: "Update RangeTest02"}},
data: {
rval: {set: $rval},
mval: {set: $mval},
rdate: {set: $rdate},
mdate: {set: $mdate}
}
) {
name
rval
mval
rdate
mdate
}
}
""", {
"update_RangeTest": [{
"name": "Update RangeTest02",
"rval": {
"lower": 5.6,
"upper": 7.8,
"inc_lower": True,
"inc_upper": True
},
"mval": [
{
"lower": 0,
"upper": 1.2,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2018-12-10",
"upper": "2022-10-20",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": None,
"upper": "2019-02-13",
"inc_lower": False,
"inc_upper": False
},
{
"lower": "2023-08-29",
"upper": "2026-10-20",
"inc_lower": True,
"inc_upper": False
}
]
}]
}, variables={
"rval": {
"lower": 5.6,
"upper": 7.8,
"inc_lower": True,
"inc_upper": True
},
"mval": [
{
"lower": 0,
"upper": 1.2,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2018-12-10",
"upper": "2022-10-20",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": None,
"upper": "2019-02-13",
"inc_lower": True,
"inc_upper": False
},
{
"lower": "2023-08-29",
"upper": "2026-10-20",
"inc_lower": True,
"inc_upper": False
}
]
})
# Cleanup
self.assert_graphql_query_result(r"""
mutation delete_RangeTest {
delete_RangeTest(
filter: {name: {eq: "Update RangeTest02"}}
) {
name
}
}
""", {
"delete_RangeTest": [{"name": "Update RangeTest02"}]
}) | , {
"insert_RangeTest": [{
"name": "Update RangeTest02",
"rval": {
"lower": -1.2,
"upper": 3.4,
"inc_lower": True,
"inc_upper": False
},
"mval": [
{
"lower": None,
"upper": -10,
"inc_lower": False,
"inc_upper": False
},
{
"lower": -3,
"upper": 12,
"inc_lower": True,
"inc_upper": False
},
],
"rdate": {
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
"mdate": [
{
"lower": "2019-02-13",
"upper": "2023-08-29",
"inc_lower": True,
"inc_upper": False
},
{
"lower": "2026-10-20",
"upper": None,
"inc_lower": True,
"inc_upper": False
}
]
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_range_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_link_01(self):
orig_data = {
'name': 'John',
'groups': [{
'name': 'basic'
}],
}
data1 = {
'name': 'John',
'groups': [],
}
data2 = {
'name': 'John',
'groups': [{
'name': 'basic'
}, {
'name': 'unused'
}, {
'name': 'upgraded'
}],
}
validation_query = r"""
query {
User(
filter: {
name: {eq: "John"}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
"""
self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
data: {
groups: {
clear: true
}
},
filter: {
name: {eq: "John"}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [data1]
})
self.assert_graphql_query_result(validation_query, {
"User": [data1]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
data: {
groups: {
set: [{
filter: {
name: {like: "%"}
}
}]
}
},
filter: {
name: {eq: "John"}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [data2]
})
self.assert_graphql_query_result(validation_query, {
"User": [data2]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
data: {
groups: {
set: [{
filter: {
name: {eq: "basic"}
}
}]
}
},
filter: {
name: {eq: "John"}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [orig_data]
})
self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
}) | self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_link_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_link_02(self):
# test fancy filters for updates
orig_data = {
'name': 'John',
'groups': [{
'name': 'basic'
}],
}
data2 = {
'name': 'John',
'groups': [{
'name': 'basic'
}, {
'name': 'unused'
}, {
'name': 'upgraded'
}],
}
validation_query = r"""
query {
User(
filter: {
name: {eq: "John"}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
"""
self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
data: {
groups: {
set: [{
filter: {
settings: {name: {eq: "template"}}
}
}, {
filter: {
name: {eq: "basic"}
}
}]
}
},
filter: {
name: {eq: "John"}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [data2]
})
self.assert_graphql_query_result(validation_query, {
"User": [data2]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
data: {
groups: {
set: [{
filter: {
name: {eq: "basic"}
}
}]
}
},
filter: {
name: {eq: "John"}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [orig_data]
})
self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
}) | self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_link_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_link_03(self):
# test set ops for update of multi link
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
filter: {
name: {eq: "Jane"}
},
data: {
groups: {
add: [{
filter: {
name: {eq: "basic"}
}
}]
}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'basic'
}, {
'name': 'upgraded'
}],
}]
})
# add an existing group
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
filter: {
name: {eq: "Jane"}
},
data: {
groups: {
add: [{
filter: {
name: {eq: "basic"}
}
}]
}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'basic'
}, {
'name': 'upgraded'
}],
}]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
filter: {
name: {eq: "Jane"}
},
data: {
groups: {
remove: [{
filter: {
name: {eq: "basic"}
}
}]
}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'upgraded'
}],
}]
}) | , {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'basic'
}, {
'name': 'upgraded'
}],
}]
})
# add an existing group
self.assert_graphql_query_result(r | test_graphql_mutation_update_link_03 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_link_04(self):
# test set ops for update of multi link with singleton values
# (omitting the wrapping [...])
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
filter: {
name: {eq: "Jane"}
},
data: {
groups: {
add: {
filter: {
name: {eq: "basic"}
}
}
}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'basic'
}, {
'name': 'upgraded'
}],
}]
})
# add an existing group
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
filter: {
name: {eq: "Jane"}
},
data: {
groups: {
add: {
filter: {
name: {eq: "basic"}
}
}
}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'basic'
}, {
'name': 'upgraded'
}],
}]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
filter: {
name: {eq: "Jane"}
},
data: {
groups: {
remove: {
filter: {
name: {eq: "basic"}
}
}
}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'upgraded'
}],
}]
})
# set a specific group
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
filter: {
name: {eq: "Jane"}
},
data: {
groups: {
set: {
filter: {
name: {eq: "unused"}
}
}
}
}
) {
name
groups(order: {name: {dir: ASC}}) {
name
}
}
}
""", {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'unused'
}],
}]
}) | , {
"update_User": [{
'name': 'Jane',
'groups': [{
'name': 'basic'
}, {
'name': 'upgraded'
}],
}]
})
# add an existing group
self.assert_graphql_query_result(r | test_graphql_mutation_update_link_04 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_link_05(self):
# updating a single link
orig_data = {
'name': 'Alice',
'profile': {
'name': 'Alice profile'
},
}
data1 = {
'name': 'Alice',
'profile': None,
}
validation_query = r"""
query {
User(
filter: {
name: {eq: "Alice"}
}
) {
name
profile {
name
}
}
}
"""
self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
data: {
profile: {
clear: true
}
},
filter: {
name: {eq: "Alice"}
}
) {
name
profile {
name
}
}
}
""", {
"update_User": [data1]
})
self.assert_graphql_query_result(validation_query, {
"User": [data1]
})
self.assert_graphql_query_result(r"""
mutation update_User {
update_User(
data: {
profile: {
set: {
filter: {
name: {eq: "Alice profile"}
}
}
}
},
filter: {
name: {eq: "Alice"}
}
) {
name
profile {
name
}
}
}
""", {
"update_User": [orig_data]
})
self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
}) | self.assert_graphql_query_result(validation_query, {
"User": [orig_data]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_link_05 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_link_06(self):
# updating a single link targeting a type union
orig_data = {
'name': 'combo 0',
'data': None,
}
data1 = {
'name': 'combo 0',
'data': {
"__typename": "Setting_Type",
"name": "perks",
},
}
data2 = {
'name': 'combo 0',
'data': {
"__typename": "Profile_Type",
"name": "Bob profile",
},
}
validation_query = r"""
query {
Combo(
filter: {name: {eq: "combo 0"}}
) {
name
data {
__typename
name
}
}
}
"""
self.assert_graphql_query_result(validation_query, {
"Combo": [orig_data]
})
self.assert_graphql_query_result(r"""
mutation update_Combo {
update_Combo(
data: {
data: {
set: {
filter: {name: {eq: "perks"}}
}
}
},
filter: {
name: {eq: "combo 0"}
}
) {
name
data {
__typename
name
}
}
}
""", {
"update_Combo": [data1]
})
self.assert_graphql_query_result(validation_query, {
"Combo": [data1]
})
self.assert_graphql_query_result(r"""
mutation update_Combo {
update_Combo(
data: {
data: {
set: {
filter: {name: {eq: "Bob profile"}}
}
}
},
filter: {
name: {eq: "combo 0"}
}
) {
name
data {
__typename
name
}
}
}
""", {
"update_Combo": [data2]
})
self.assert_graphql_query_result(validation_query, {
"Combo": [data2]
})
self.assert_graphql_query_result(r"""
mutation update_Combo {
update_Combo(
data: {
data: {
clear: true
}
},
filter: {
name: {eq: "combo 0"}
}
) {
name
data {
__typename
name
}
}
}
""", {
"update_Combo": [orig_data]
})
self.assert_graphql_query_result(validation_query, {
"Combo": [orig_data]
}) | self.assert_graphql_query_result(validation_query, {
"Combo": [orig_data]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_link_06 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_multiple_01(self):
# Issue #1566
# Test multiple mutations.
validation_query = r"""
query {
Setting(filter: {name: {eq: "perks"}}) {
name
value
}
Profile(filter: {name: {eq: "Alice profile"}}) {
name
value
}
}
"""
self.assert_graphql_query_result(r"""
mutation multi_update {
update_Setting(
filter: {name: {eq: "perks"}},
data: {
value: {set: "min"}
}
) {
name
value
}
update_Profile(
filter: {name: {eq: "Alice profile"}},
data: {
value: {set: "updated"}
}
) {
name
value
}
}
""", {
"update_Setting": [{
'name': 'perks',
'value': 'min',
}],
"update_Profile": [{
'name': 'Alice profile',
'value': 'updated',
}]
})
self.assert_graphql_query_result(validation_query, {
"Setting": [{
'name': 'perks',
'value': 'min',
}],
"Profile": [{
'name': 'Alice profile',
'value': 'updated',
}]
})
self.assert_graphql_query_result(r"""
mutation multi_update {
update_Setting(
filter: {name: {eq: "perks"}},
data: {
value: {set: "full"}
}
) {
name
value
}
update_Profile(
filter: {name: {eq: "Alice profile"}},
data: {
value: {set: "special"}
}
) {
name
value
}
}
""", {
"update_Setting": [{
'name': 'perks',
'value': 'full',
}],
"update_Profile": [{
'name': 'Alice profile',
'value': 'special',
}]
}) | self.assert_graphql_query_result(r | test_graphql_mutation_update_multiple_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_multiple_02(self):
# Issue #3470
# Test nested update of the same type.
data = {
'after': 'BaseFoo02',
'color': 'GREEN',
'foos': [{
'after': 'NestedFoo020',
'color': 'RED',
}, {
'after': 'NestedFoo021',
'color': 'BLUE',
}],
}
validation_query = r"""
query {
other__Foo(filter: {after: {eq: "BaseFoo02"}}) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
"""
self.graphql_query(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
after: "NestedFoo020",
color: RED
}, {
after: "BaseFoo02",
color: GREEN
}, {
after: "NestedFoo021",
color: BLUE
}]
) {
color
}
}
""")
self.assert_graphql_query_result(r"""
mutation update_other__Foo {
update_other__Foo(
filter: {after: {eq: "BaseFoo02"}},
data: {
foos: {
set: [{
filter: {
after: {like: "NestedFoo02%"},
}
}]
}
}
) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
""", {
"update_other__Foo": [data]
})
self.assert_graphql_query_result(validation_query, {
"other__Foo": [data]
})
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {after: {like: "%Foo02%"}},
order: {color: {dir: ASC}}
) {
after
color
}
}
""", {
"delete_other__Foo": [{
'after': 'NestedFoo020',
'color': 'RED',
}, {
'after': 'BaseFoo02',
'color': 'GREEN',
}, {
'after': 'NestedFoo021',
'color': 'BLUE',
}]
}) | self.graphql_query(r | test_graphql_mutation_update_multiple_02 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_multiple_03(self):
# Issue #3470
# Test nested update of the same type.
self.graphql_query(r"""
mutation insert_other__Foo {
insert_other__Foo(
data: [{
after: "NestedFoo030",
color: RED
}, {
after: "BaseFoo03",
color: GREEN
}, {
after: "NestedFoo031",
color: BLUE
}]
) {
color
}
}
""")
self.assert_graphql_query_result(r"""
mutation update_other__Foo {
update_other__Foo(
filter: {after: {eq: "BaseFoo03"}},
data: {
foos: {
add: [{
filter: {
after: {like: "NestedFoo03%"},
}
}]
}
}
) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
""", {
"update_other__Foo": [{
'after': 'BaseFoo03',
'color': 'GREEN',
'foos': [{
'after': 'NestedFoo030',
'color': 'RED',
}, {
'after': 'NestedFoo031',
'color': 'BLUE',
}],
}]
})
self.assert_graphql_query_result(r"""
mutation update_other__Foo {
update_other__Foo(
filter: {after: {eq: "BaseFoo03"}},
data: {
foos: {
remove: [{
filter: {
after: {eq: "NestedFoo031"},
}
}]
}
}
) {
after
color
foos(order: {color: {dir: ASC}}) {
after
color
}
}
}
""", {
"update_other__Foo": [{
'after': 'BaseFoo03',
'color': 'GREEN',
'foos': [{
'after': 'NestedFoo030',
'color': 'RED',
}],
}]
})
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
delete_other__Foo(
filter: {after: {like: "%Foo03%"}},
order: {color: {dir: ASC}}
) {
after
color
}
}
""", {
"delete_other__Foo": [{
'after': 'NestedFoo030',
'color': 'RED',
}, {
'after': 'BaseFoo03',
'color': 'GREEN',
}, {
'after': 'NestedFoo031',
'color': 'BLUE',
}]
}) | )
self.assert_graphql_query_result(r | test_graphql_mutation_update_multiple_03 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_update_typename_01(self):
# This tests the typename funcitonality after insertion.
# Issue #5985
self.assert_graphql_query_result(r"""
mutation insert_other__Foo {
__typename
insert_other__Foo(
data: [{
select: "Update TypenameTest01",
color: BLUE
}]
) {
__typename
select
color
}
}
""", {
"__typename": 'Mutation',
"insert_other__Foo": [{
'__typename': 'other__Foo_Type',
'select': 'Update TypenameTest01',
'color': 'BLUE',
}]
})
self.assert_graphql_query_result(r"""
mutation update_other__Foo {
__typename
update_other__Foo(
filter: {select: {eq: "Update TypenameTest01"}}
data: {
color: {set: RED}
}
) {
__typename
select
color
}
}
""", {
"__typename": 'Mutation',
"update_other__Foo": [{
'__typename': 'other__Foo_Type',
'select': 'Update TypenameTest01',
'color': 'RED',
}]
})
# clean up
self.assert_graphql_query_result(r"""
mutation delete_other__Foo {
__typename
delete_other__Foo(
filter: {select: {eq: "Update TypenameTest01"}}
) {
__typename
select
color
}
}
""", {
"__typename": 'Mutation',
"delete_other__Foo": [{
'__typename': 'other__Foo_Type',
'select': 'Update TypenameTest01',
'color': 'RED',
}]
}) | , {
"__typename": 'Mutation',
"insert_other__Foo": [{
'__typename': 'other__Foo_Type',
'select': 'Update TypenameTest01',
'color': 'BLUE',
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_update_typename_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_mutation_delete_alias_01(self):
self.assert_graphql_query_result(r"""
mutation insert_Setting {
insert_Setting(
data: [{
name: "delsetting01",
value: "red"
}]
) {
name
value
}
}
""", {
"insert_Setting": [{
'name': 'delsetting01',
'value': 'red',
}]
})
self.assert_graphql_query_result(r"""
mutation delete_SettingAlias {
delete_SettingAlias(
filter: {
name: {eq: "delsetting01"}
}
) {
name
value
}
}
""", {
"delete_SettingAlias": [{
'name': 'delsetting01',
'value': 'red',
}]
})
self.assert_graphql_query_result(r"""
query get_SettingAlias {
SettingAlias(
filter: {
name: {eq: "delsetting01"}
}
) {
name
value
}
}
""", {
"SettingAlias": []
}) | , {
"insert_Setting": [{
'name': 'delsetting01',
'value': 'red',
}]
})
self.assert_graphql_query_result(r | test_graphql_mutation_delete_alias_01 | python | geldata/gel | tests/test_http_graphql_mutation.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_mutation.py | Apache-2.0 |
def test_graphql_http_keepalive_01(self):
with self.http_con() as con:
for _ in range(3):
req1_data = {
'query': '''
{
Setting(order: {value: {dir: ASC}}) {
value
}
}
'''
}
data, headers, status = self.http_con_request(
con, req1_data,
headers={
'Authorization': self.make_auth_header(),
},
)
self.assertEqual(status, 200)
self.assertNotIn('connection', headers)
self.assertEqual(
headers.get('content-type'),
'application/json')
self.assertEqual(
json.loads(data)['data'],
{'Setting': [{'value': 'blue'}, {'value': 'full'},
{'value': 'none'}]})
req2_data = {
'query': '''
{
NON_EXISTING_TYPE {
name
}
}
'''
}
data, headers, status = self.http_con_request(
con, req2_data,
headers={
'Authorization': self.make_auth_header(),
},
)
self.assertEqual(status, 200)
self.assertNotIn('connection', headers)
self.assertEqual(
headers.get('content-type'),
'application/json')
self.assertIn(
'QueryError:',
json.loads(data)['errors'][0]['message']) | }
data, headers, status = self.http_con_request(
con, req1_data,
headers={
'Authorization': self.make_auth_header(),
},
)
self.assertEqual(status, 200)
self.assertNotIn('connection', headers)
self.assertEqual(
headers.get('content-type'),
'application/json')
self.assertEqual(
json.loads(data)['data'],
{'Setting': [{'value': 'blue'}, {'value': 'full'},
{'value': 'none'}]})
req2_data = {
'query': | test_graphql_http_keepalive_01 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_query_08(self):
self.assert_graphql_query_result(
r"""
query names {
Setting {
name
}
}
query values {
Setting {
value
}
}
""",
{
'Setting': [{
'name': 'perks',
}, {
'name': 'template',
}, {
'name': 'template',
}],
},
sort=lambda x: x['name'],
operation_name='names'
)
self.assert_graphql_query_result(
r"""
query names {
Setting {
name
}
}
query values {
Setting {
value
}
}
""",
{
'Setting': [{
'value': 'blue',
}, {
'value': 'full',
}, {
'value': 'none',
}],
},
sort=lambda x: x['value'],
operation_name='values',
use_http_post=False
) | ,
{
'Setting': [{
'name': 'perks',
}, {
'name': 'template',
}, {
'name': 'template',
}],
},
sort=lambda x: x['name'],
operation_name='names'
)
self.assert_graphql_query_result(
r | test_graphql_functional_query_08 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_query_17(self):
# Test unused & null variables
self.assert_graphql_query_result(
r"""
query Person {
Person
{
name
}
}
""",
{
'Person': [{
'name': 'Bob',
}],
},
variables={'name': None},
)
self.assert_graphql_query_result(
r"""
query Person($name: String) {
Person(filter: {name: {eq: $name}})
{
name
}
}
""",
{
'Person': [],
},
variables={'name': None},
) | ,
{
'Person': [{
'name': 'Bob',
}],
},
variables={'name': None},
)
self.assert_graphql_query_result(
r | test_graphql_functional_query_17 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_alias_04(self):
self.assert_graphql_query_result(
r"""
{
ProfileAlias {
__typename
name
value
owner {
__typename
id
}
}
}
""",
{
"ProfileAlias": [
{
"__typename": "ProfileAlias",
"name": "Alice profile",
"value": "special",
"owner": [
{
"__typename": "User_Type",
"id": uuid.UUID,
}
]
},
{
"__typename": "ProfileAlias",
"name": "Bob profile",
"value": "special",
"owner": [
{
"__typename": "Person_Type",
"id": uuid.UUID,
}
]
}
]
},
)
result = self.graphql_query(r"""
query {
ProfileAlias {
owner {
id
}
}
}
""")
user_id = result['ProfileAlias'][0]['owner'][0]['id']
self.assert_graphql_query_result(f"""
query {{
User(filter: {{id: {{eq: "{user_id}"}}}}) {{
name
}}
}}
""", {
'User': [{'name': 'Alice'}]
}) | ,
{
"ProfileAlias": [
{
"__typename": "ProfileAlias",
"name": "Alice profile",
"value": "special",
"owner": [
{
"__typename": "User_Type",
"id": uuid.UUID,
}
]
},
{
"__typename": "ProfileAlias",
"name": "Bob profile",
"value": "special",
"owner": [
{
"__typename": "Person_Type",
"id": uuid.UUID,
}
]
}
]
},
)
result = self.graphql_query(r | test_graphql_functional_alias_04 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_arguments_01(self):
result = self.graphql_query(r"""
query {
User {
id
name
age
}
}
""")
alice = [res for res in result['User']
if res['name'] == 'Alice'][0]
self.assert_graphql_query_result(f"""
query {{
User(filter: {{id: {{eq: "{alice['id']}"}}}}) {{
id
name
age
}}
}}
""", {
'User': [alice]
}) | )
alice = [res for res in result['User']
if res['name'] == 'Alice'][0]
self.assert_graphql_query_result(f | test_graphql_functional_arguments_01 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_fragment_20(self):
# ISSUE #1800
#
# After using a typed inline fragment the nested fields or
# fields following after the fragment are erroneously using
# the type intersection.
self.assert_graphql_query_result(r"""
query {
NamedObject(filter: {name: {eq: "Alice"}}) {
... on User {
active
profile(filter: {name: {eq: "Alice profile"}}) {
value
}
}
name
}
}
""", {
'NamedObject': [{
'name': 'Alice',
'active': True,
'profile': {
'value': 'special',
}
}],
})
self.assert_graphql_query_result(r"""
query {
NamedObject(filter: {name: {eq: "Alice"}}) {
... on User {
active
profile(filter: {name: {eq: "no such profile"}}) {
value
}
}
name
}
}
""", {
'NamedObject': [{
'name': 'Alice',
'active': True,
'profile': None,
}],
}) | , {
'NamedObject': [{
'name': 'Alice',
'active': True,
'profile': {
'value': 'special',
}
}],
})
self.assert_graphql_query_result(r | test_graphql_functional_fragment_20 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_fragment_21(self):
# ISSUE #1800
#
# After using a typed inline fragment the nested fields or
# fields following after the fragment are erroneously using
# the type intersection.
self.assert_graphql_query_result(r"""
fragment userFrag on User {
active
profile(filter: {name: {eq: "Alice profile"}}) {
value
}
}
query {
NamedObject(filter: {name: {eq: "Alice"}}) {
... userFrag
name
}
}
""", {
'NamedObject': [{
'name': 'Alice',
'active': True,
'profile': {
'value': 'special',
}
}],
})
self.assert_graphql_query_result(r"""
fragment userFrag on User {
active
profile(filter: {name: {eq: "no such profile"}}) {
value
}
}
query {
NamedObject(filter: {name: {eq: "Alice"}}) {
... userFrag
name
}
}
""", {
'NamedObject': [{
'name': 'Alice',
'active': True,
'profile': None,
}],
}) | , {
'NamedObject': [{
'name': 'Alice',
'active': True,
'profile': {
'value': 'special',
}
}],
})
self.assert_graphql_query_result(r | test_graphql_functional_fragment_21 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_fragment_24(self):
# ISSUE #5985
#
# Types from non-default module should be recognized in fragments.
self.assert_graphql_query_result(r"""
fragment myFrag on other__Foo {
id,
color,
}
query {
other__Foo(filter: {color: {eq: RED}}) {
... myFrag
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})
self.assert_graphql_query_result(r"""
fragment myFrag on other__Foo_Type {
id,
color,
}
query {
other__Foo(filter: {color: {eq: RED}}) {
... myFrag
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
}) | , {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})
self.assert_graphql_query_result(r | test_graphql_functional_fragment_24 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_fragment_25(self):
# ISSUE #5985
#
# Types from non-default module should be recognized in fragments.
self.assert_graphql_query_result(r"""
query {
other__Foo(filter: {color: {eq: RED}}) {
... on other__Foo {
id,
color,
}
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})
self.assert_graphql_query_result(r"""
query {
other__Foo(filter: {color: {eq: RED}}) {
... on other__Foo_Type {
id,
color,
}
}
}
""", {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
}) | , {
'other__Foo': [{
'id': uuid.UUID,
'color': 'RED',
}],
})
self.assert_graphql_query_result(r | test_graphql_functional_fragment_25 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
def test_graphql_functional_variables_34(self):
# Test multiple requests to make sure that caching works correctly
for _ in range(2):
for _ in range(2):
self.assert_graphql_query_result(
r"""
query($val: Boolean!, $min_age: Int64!) {
User(filter: {age: {gt: $min_age}}) {
name @include(if: $val),
age
}
}
""",
{'User': [{'age': 27, 'name': 'Alice'}]},
variables={'val': True, 'min_age': 26}
)
self.assert_graphql_query_result(
r"""
query($val: Boolean!, $min_age: Int64!) {
User(filter: {age: {gt: $min_age}}) {
name @include(if: $val),
age
}
}
""",
{'User': [{'age': 27}]},
variables={'val': False, 'min_age': 26}
) | ,
{'User': [{'age': 27, 'name': 'Alice'}]},
variables={'val': True, 'min_age': 26}
)
self.assert_graphql_query_result(
r | test_graphql_functional_variables_34 | python | geldata/gel | tests/test_http_graphql_query.py | https://github.com/geldata/gel/blob/master/tests/test_http_graphql_query.py | Apache-2.0 |
async def test_edgeql_casts_bytes_04(self):
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'expected JSON string or null',
):
await self.con.query_single("SELECT <bytes>to_json('1');")
self.assertEqual(
await self.con.query_single(r'''
SELECT <bytes>to_json('"aGVsbG8="');
'''),
b'hello',
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError, r'invalid symbol'):
await self.con.query_single("""
SELECT <bytes>to_json('"not base64!"');
""")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError, r'invalid base64 end sequence'):
await self.con.query_single("""
SELECT <bytes>to_json('"a"');
""") | ),
b'hello',
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError, r'invalid symbol'):
await self.con.query_single( | test_edgeql_casts_bytes_04 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_idempotence_01(self):
await self.assert_query_result(
r'''SELECT <bool><bool>True IS bool;''',
[True],
)
await self.assert_query_result(
r'''SELECT <bytes><bytes>b'Hello' IS bytes;''',
[True],
)
await self.assert_query_result(
r'''SELECT <str><str>'Hello' IS str;''',
[True],
)
await self.assert_query_result(
r'''SELECT <json><json>to_json('1') IS json;''',
[True],
)
await self.assert_query_result(
r'''SELECT <uuid><uuid>uuid_generate_v1mc() IS uuid;''',
[True],
)
await self.assert_query_result(
r'''SELECT <datetime><datetime>datetime_current() IS datetime;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_datetime><cal::local_datetime>
cal::to_local_datetime(
'2018-05-07T20:01:22.306916') IS cal::local_datetime;
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_date><cal::local_date>cal::to_local_date(
'2018-05-07') IS cal::local_date;
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_time><cal::local_time>cal::to_local_time(
'20:01:22.306916') IS cal::local_time;
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <duration><duration>to_duration(
hours:=20) IS duration;
''',
[True],
)
await self.assert_query_result(
r'''SELECT <int16><int16>to_int16('12345') IS int16;''',
[True],
)
await self.assert_query_result(
r'''SELECT <int32><int32>to_int32('1234567890') IS int32;''',
[True],
)
await self.assert_query_result(
r'''SELECT <int64><int64>to_int64('1234567890123') IS int64;''',
[True],
)
await self.assert_query_result(
r'''SELECT <float32><float32>to_float32('2.5') IS float32;''',
[True],
)
await self.assert_query_result(
r'''SELECT <float64><float64>to_float64('2.5') IS float64;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <bigint><bigint>to_bigint(
'123456789123456789123456789')
IS bigint;
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <decimal><decimal>to_decimal(
'123456789123456789123456789.123456789123456789123456789')
IS decimal;
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_idempotence_01 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_idempotence_02(self):
await self.assert_query_result(
r'''SELECT <bool><bool>True = True;''',
[True],
)
await self.assert_query_result(
r'''SELECT <bytes><bytes>b'Hello' = b'Hello';''',
[True],
)
await self.assert_query_result(
r'''SELECT <str><str>'Hello' = 'Hello';''',
[True],
)
await self.assert_query_result(
r'''SELECT <json><json>to_json('1') = to_json('1');''',
[True],
)
await self.assert_query_result(
r'''
WITH U := uuid_generate_v4()
SELECT <uuid><uuid>U = U;
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <datetime><datetime>datetime_of_statement() =
datetime_of_statement();
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_datetime><cal::local_datetime>
cal::to_local_datetime('2018-05-07T20:01:22.306916') =
cal::to_local_datetime('2018-05-07T20:01:22.306916');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_date><cal::local_date>
cal::to_local_date('2018-05-07') =
cal::to_local_date('2018-05-07');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_time><cal::local_time>cal::to_local_time(
'20:01:22.306916') = cal::to_local_time('20:01:22.306916');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <duration><duration>to_duration(hours:=20) =
to_duration(hours:=20);
''',
[True],
)
await self.assert_query_result(
r'''SELECT <int16><int16>to_int16('12345') = 12345;''',
[True],
)
await self.assert_query_result(
r'''SELECT <int32><int32>to_int32('1234567890') = 1234567890;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <int64><int64>to_int64('1234567890123') =
1234567890123;
''',
[True],
)
await self.assert_query_result(
r'''SELECT <float32><float32>to_float32('2.5') = 2.5;''',
[True],
)
await self.assert_query_result(
r'''SELECT <float64><float64>to_float64('2.5') = 2.5;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <bigint><bigint>to_bigint(
'123456789123456789123456789')
= to_bigint(
'123456789123456789123456789');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <decimal><decimal>to_decimal(
'123456789123456789123456789.123456789123456789123456789')
= to_decimal(
'123456789123456789123456789.123456789123456789123456789');
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_idempotence_02 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_01(self):
# Casting to str and back is lossless for every scalar (if
# legal). It's still not legal to cast bytes into str or some
# of the json values.
await self.assert_query_result(
r'''SELECT <bool><str>True = True;''',
[True],
)
await self.assert_query_result(
r'''SELECT <bool><str>False = False;''',
[True],
# only JSON strings can be cast into EdgeQL str
)
await self.assert_query_result(
r'''SELECT <json><str>to_json('"Hello"') = to_json('"Hello"');''',
[True],
)
await self.assert_query_result(
r'''
WITH U := uuid_generate_v1mc()
SELECT <uuid><str>U = U;
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <datetime><str>datetime_of_statement() =
datetime_of_statement();
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_datetime><str>cal::to_local_datetime(
'2018-05-07T20:01:22.306916') =
cal::to_local_datetime('2018-05-07T20:01:22.306916');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_date><str>cal::to_local_date('2018-05-07') =
cal::to_local_date('2018-05-07');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_time><str>
cal::to_local_time('20:01:22.306916') =
cal::to_local_time('20:01:22.306916');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <duration><str>to_duration(hours:=20) =
to_duration(hours:=20);
''',
[True],
)
await self.assert_query_result(
r'''SELECT <int16><str>to_int16('12345') = 12345;''',
[True],
)
await self.assert_query_result(
r'''SELECT <int32><str>to_int32('1234567890') = 1234567890;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <int64><str>to_int64(
'1234567890123') = 1234567890123;
''',
[True],
)
await self.assert_query_result(
r'''SELECT <float32><str>to_float32('2.5') = 2.5;''',
[True],
)
await self.assert_query_result(
r'''SELECT <float64><str>to_float64('2.5') = 2.5;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <bigint><str>to_bigint(
'123456789123456789123456789')
= to_bigint(
'123456789123456789123456789');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <decimal><str>to_decimal(
'123456789123456789123456789.123456789123456789123456789')
= to_decimal(
'123456789123456789123456789.123456789123456789123456789');
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_str_01 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_02(self):
# Certain strings can be cast into other types losslessly,
# making them "canonical" string representations of those
# values.
await self.assert_query_result(
r'''
FOR x in {'true', 'false'}
SELECT <str><bool>x = x;
''',
[True, True],
)
await self.assert_query_result(
r'''
FOR x in {'True', 'False', 'TRUE', 'FALSE', ' TrUe '}
SELECT <str><bool>x = x;
''',
[False, False, False, False, False],
)
await self.assert_query_result(
r'''
FOR x in {'True', 'False', 'TRUE', 'FALSE', 'TrUe'}
SELECT <str><bool>x = str_lower(x);
''',
[True, True, True, True, True],
)
for variant in {'😈', 'yes', '1', 'no', 'on', 'OFF',
't', 'f', 'tr', 'fa'}:
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
fr"invalid input syntax for type std::bool: '{variant}'"):
await self.con.query_single(f'SELECT <bool>"{variant}"')
self.assertTrue(
await self.con.query_single('SELECT <bool>" TruE "'))
self.assertFalse(
await self.con.query_single('SELECT <bool>" FalsE "')) | ,
[True, True],
)
await self.assert_query_result(
r | test_edgeql_casts_str_02 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_04(self):
# canonical uuid representation as a string is using lowercase
await self.assert_query_result(
r'''
FOR x in 'd4288330-eea3-11e8-bc5f-7faf132b1d84'
SELECT <str><uuid>x = x;
''',
[True],
)
await self.assert_query_result(
# non-canonical
r'''
FOR x in {
'D4288330-EEA3-11E8-BC5F-7FAF132B1D84',
'D4288330-Eea3-11E8-Bc5F-7Faf132B1D84',
'D4288330-eea3-11e8-bc5f-7faf132b1d84',
}
SELECT <str><uuid>x = x;
''',
[False, False, False],
)
await self.assert_query_result(
r'''
FOR x in {
'D4288330-EEA3-11E8-BC5F-7FAF132B1D84',
'D4288330-Eea3-11E8-Bc5F-7Faf132B1D84',
'D4288330-eea3-11e8-bc5f-7faf132b1d84',
}
SELECT <str><uuid>x = str_lower(x);
''',
[True, True, True],
) | ,
[True],
)
await self.assert_query_result(
# non-canonical
r | test_edgeql_casts_str_04 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_05(self):
# Canonical date and time str representations must follow ISO
# 8601. This test assumes that the server is configured to be
# in UTC time zone.
await self.assert_query_result(
r'''
FOR x in '2018-05-07T20:01:22.306916+00:00'
SELECT <str><datetime>x = x;
''',
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r'''
FOR x in {
'2018-05-07T15:01:22.306916-05:00',
'2018-05-07T15:01:22.306916-05',
'2018-05-07T20:01:22.306916Z',
'2018-05-07T20:01:22.306916+0000',
'2018-05-07T20:01:22.306916+00',
# the '-' and ':' separators may be omitted
'20180507T200122.306916+00',
# acceptable RFC 3339
'2018-05-07 20:01:22.306916+00:00',
'2018-05-07t20:01:22.306916z',
}
SELECT <datetime>x =
<datetime>'2018-05-07T20:01:22.306916+00:00';
''',
[True, True, True, True, True, True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime>"2018-05-07;20:01:22.306916+00:00"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime>"2018-05-07T20:01:22.306916"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime>"2018-05-07T20:01:22.306916 1000"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime>"2018-05-07T20:01:22.306916 US/Central"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime>"2018-05-07T20:01:22.306916 +GMT1"') | ,
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r | test_edgeql_casts_str_05 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_06(self):
# Canonical date and time str representations must follow ISO
# 8601. This test assumes that the server is configured to be
# in UTC time zone.
await self.assert_query_result(
r'''
FOR x in '2018-05-07T20:01:22.306916'
SELECT <str><cal::local_datetime>x = x;
''',
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r'''
FOR x in {
# the '-' and ':' separators may be omitted
'20180507T200122.306916',
# acceptable RFC 3339
'2018-05-07 20:01:22.306916',
'2018-05-07t20:01:22.306916',
}
SELECT <cal::local_datetime>x =
<cal::local_datetime>'2018-05-07T20:01:22.306916';
''',
[True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_datetime>"2018-05-07;20:01:22.306916"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''
SELECT
<cal::local_datetime>"2018-05-07T20:01:22.306916+01:00"
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_datetime>"2018-05-07T20:01:22.306916 GMT"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''
SELECT
<cal::local_datetime>"2018-05-07T20:01:22.306916 GMT0"
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''SELECT <cal::local_datetime>
"2018-05-07T20:01:22.306916 US/Central"
''') | ,
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r | test_edgeql_casts_str_06 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_07(self):
# Canonical date and time str representations must follow ISO
# 8601.
await self.assert_query_result(
r'''
FOR x in '2018-05-07'
SELECT <str><cal::local_date>x = x;
''',
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same date
r'''
FOR x in {
# the '-' separators may be omitted
'20180507',
}
SELECT <cal::local_date>x = <cal::local_date>'2018-05-07';
''',
[True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date>"2018-05-07T20:01:22.306916"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date>"2018/05/07"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date>"2018.05.07"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date>"2018-05-07+01:00"') | ,
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same date
r | test_edgeql_casts_str_07 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_08(self):
# Canonical date and time str representations must follow ISO
# 8601.
await self.assert_query_result(
r'''
FOR x in '20:01:22.306916'
SELECT <str><cal::local_time>x = x;
''',
[True],
)
await self.assert_query_result(
r'''
FOR x in {
'20:01',
'20:01:00',
# the ':' separators may be omitted
'2001',
'200100',
}
SELECT <cal::local_time>x = <cal::local_time>'20:01:00';
''',
[True, True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
'invalid input syntax for type std::cal::local_time'):
await self.con.query_single(
"SELECT <cal::local_time>'2018-05-07 20:01:22'")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_time>"20:01:22.306916+01:00"') | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_str_08 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_09(self):
# Canonical duration
await self.assert_query_result(
r'''
FOR x in 'PT20H1M22.306916S'
SELECT <str><duration>x = x;
''',
[True],
)
await self.assert_query_result(
# non-canonical
r'''
FOR x in {
'20:01:22.306916',
'20h 1m 22.306916s',
'20 hours 1 minute 22.306916 seconds',
'72082.306916', # the duration in seconds
'0.834285959675926 days',
}
SELECT <str><duration>x = x;
''',
[False, False, False, False, False],
)
await self.assert_query_result(
# validating that these are all in fact the same duration
r'''
FOR x in {
'20:01:22.306916',
'20h 1m 22.306916s',
'20 hours 1 minute 22.306916 seconds',
'72082.306916', # the duration in seconds
'0.834285959675926 days',
}
SELECT <duration>x = <duration>'PT20H1M22.306916S';
''',
[True, True, True, True, True],
) | ,
[True],
)
await self.assert_query_result(
# non-canonical
r | test_edgeql_casts_str_09 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_10(self):
# valid casts from str to any integer is lossless, as long as
# there's no whitespace, which is trimmed
await self.assert_query_result(
r'''
FOR x in {'-20', '0', '7', '12345'}
SELECT <str><int16>x = x;
''',
[True, True, True, True],
)
await self.assert_query_result(
r'''
FOR x in {'-20', '0', '7', '12345'}
SELECT <str><int32>x = x;
''',
[True, True, True, True],
)
await self.assert_query_result(
r'''
FOR x in {'-20', '0', '7', '12345'}
SELECT <str><int64>x = x;
''',
[True, True, True, True],
)
await self.assert_query_result(
# with whitespace
r'''
FOR x in {
' 42',
'42 ',
' 42 ',
}
SELECT <str><int16>x = x;
''',
[False, False, False],
)
await self.assert_query_result(
# validating that these are all in fact the same value
r'''
FOR x in {
' 42',
'42 ',
' 42 ',
}
SELECT <int16>x = 42;
''',
[True, True, True],
) | ,
[True, True, True, True],
)
await self.assert_query_result(
r | test_edgeql_casts_str_10 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_11(self):
# There's too many ways of representing floats. Outside of
# trivial 1-2 digit cases, relying on any str being
# "canonical" is not safe, making most casts from str to float
# lossy.
await self.assert_query_result(
r'''
FOR x in {'-20', '0', '7.2'}
SELECT <str><float32>x = x;
''',
[True, True, True],
)
await self.assert_query_result(
r'''
FOR x in {'-20', '0', '7.2'}
SELECT <str><float64>x = x;
''',
[True, True, True],
)
await self.assert_query_result(
# non-canonical
r'''
FOR x in {
'0.0000000001234',
'1234E-13',
'0.1234e-9',
}
SELECT <str><float32>x = x;
''',
[False, False, False],
)
await self.assert_query_result(
r'''
FOR x in {
'0.0000000001234',
'1234E-13',
'0.1234e-9',
}
SELECT <str><float64>x = x;
''',
[False, False, False],
)
await self.assert_query_result(
# validating that these are all in fact the same value
r'''
FOR x in {
'0.0000000001234',
'1234E-13',
'0.1234e-9',
}
SELECT <float64>x = 1234e-13;
''',
[True, True, True],
) | ,
[True, True, True],
)
await self.assert_query_result(
r | test_edgeql_casts_str_11 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_12(self):
# The canonical string representation of decimals is without
# use of scientific notation.
await self.assert_query_result(
r'''
FOR x in {
'-20', '0', '7.2', '0.0000000001234', '1234.00000001234'
}
SELECT <str><decimal>x = x;
''',
[True, True, True, True, True],
)
await self.assert_query_result(
# non-canonical
r'''
FOR x in {
'1234E-13',
'0.1234e-9',
}
SELECT <str><decimal>x = x;
''',
[False, False],
)
await self.assert_query_result(
# validating that these are all in fact the same date
r'''
FOR x in {
'1234E-13',
'0.1234e-9',
}
SELECT <decimal>x = <decimal>'0.0000000001234';
''',
[True, True],
) | ,
[True, True, True, True, True],
)
await self.assert_query_result(
# non-canonical
r | test_edgeql_casts_str_12 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_str_13(self):
# Casting to str and back is lossless for every scalar (if
# legal). It's still not legal to cast bytes into str or some
# of the json values.
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <uuid><str>T.id = T.id;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <bool><str>T.p_bool = T.p_bool;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <str><str>T.p_str = T.p_str;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <datetime><str>T.p_datetime = T.p_datetime;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <cal::local_datetime><str>T.p_local_datetime =
T.p_local_datetime;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <cal::local_date><str>T.p_local_date = T.p_local_date;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <cal::local_time><str>T.p_local_time = T.p_local_time;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <duration><str>T.p_duration = T.p_duration;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <int16><str>T.p_int16 = T.p_int16;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <int32><str>T.p_int32 = T.p_int32;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <int64><str>T.p_int64 = T.p_int64;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <float32><str>T.p_float32 = T.p_float32;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <float64><str>T.p_float64 = T.p_float64;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <bigint><str>T.p_bigint = T.p_bigint;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <decimal><str>T.p_decimal = T.p_decimal;
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_str_13 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_numeric_01(self):
# Casting to decimal and back should be lossless for any other
# integer type.
for numtype in {'bigint', 'decimal'}:
await self.assert_query_result(
# technically we're already casting a literal int64
# to int16 first
f'''
FOR x in <int16>{{-32768, -32767, -100,
0, 13, 32766, 32767}}
SELECT <int16><{numtype}>x = x;
''',
[True, True, True, True, True, True, True],
)
await self.assert_query_result(
# technically we're already casting a literal int64
# to int32 first
f'''
FOR x in <int32>{{-2147483648, -2147483647, -65536, -100,
0, 13, 32768, 2147483646, 2147483647}}
SELECT <int32><{numtype}>x = x;
''',
[True, True, True, True, True, True, True, True, True],
)
await self.assert_query_result(
f'''
FOR x in <int64>{{
-9223372036854775808,
-9223372036854775807,
-4294967296,
-65536,
-100,
0,
13,
65536,
4294967296,
9223372036854775806,
9223372036854775807
}}
SELECT <int64><{numtype}>x = x;
''',
[True, True, True, True, True, True,
True, True, True, True, True],
) | ,
[True, True, True, True, True, True, True],
)
await self.assert_query_result(
# technically we're already casting a literal int64
# to int32 first
f | test_edgeql_casts_numeric_01 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_numeric_02(self):
# Casting to decimal and back should be lossless for any other
# float type of low precision (a couple of digits less than
# the maximum possible float precision).
await self.assert_query_result(
# technically we're already casting a literal int64 or
# float64 to float32 first
r'''
FOR x in <float32>{-3.31234e+38, -1.234e+12, -1.234e-12,
-100, 0, 13, 1.234e-12, 1.234e+12, 3.4e+38}
SELECT <float32><decimal>x = x;
''',
[True, True, True, True, True, True, True, True, True],
)
await self.assert_query_result(
r'''
FOR x in <float64>{-1.61234e+308, -1.234e+42, -1.234e-42,
-100, 0, 13, 1.234e-42, 1.234e+42,
1.7e+308}
SELECT <float64><decimal>x = x;
''',
[True, True, True, True, True, True, True, True, True],
) | ,
[True, True, True, True, True, True, True, True, True],
)
await self.assert_query_result(
r | test_edgeql_casts_numeric_02 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_numeric_03(self):
# It is especially dangerous to cast an int32 into float32 and
# back because float32 cannot losslessly represent the entire
# range of int32, but it can represent some of it, so no
# obvious errors would be raised (as any int32 value is
# technically withing valid range of float32), but the value
# could be mangled.
await self.assert_query_result(
# ints <= 2^24 can be represented exactly in a float32
r'''
FOR x in <int32>{16777216, 16777215, 16777214,
1677721, 167772, 16777}
SELECT <int32><float32>x = x;
''',
[True, True, True, True, True, True],
)
await self.assert_query_result(
# max int32 -100, -1000
r'''
FOR x in <int32>{2147483548, 2147482648}
SELECT <int32><float32>x = x;
''',
[False, False],
)
await self.assert_query_result(
r'''
FOR x in <int32>{2147483548, 2147482648}
SELECT <int32><float32>x;
''',
[2147483520, 2147482624],
) | ,
[True, True, True, True, True, True],
)
await self.assert_query_result(
# max int32 -100, -1000
r | test_edgeql_casts_numeric_03 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_numeric_04(self):
await self.assert_query_result(
# ints <= 2^24 can be represented exactly in a float32
r'''
FOR x in <int32>{16777216, 16777215, 16777214,
1677721, 167772, 16777}
SELECT <int32><float64>x = x;
''',
[True, True, True, True, True, True],
)
await self.assert_query_result(
# max int32 -1, -2, -3, -10, -100, -1000
r'''
FOR x in <int32>{2147483647, 2147483646, 2147483645,
2147483638, 2147483548, 2147482648}
SELECT <int32><float64>x = x;
''',
[True, True, True, True, True, True],
) | ,
[True, True, True, True, True, True],
)
await self.assert_query_result(
# max int32 -1, -2, -3, -10, -100, -1000
r | test_edgeql_casts_numeric_04 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_numeric_05(self):
# Due to the sparseness of float values large integers may not
# be representable exactly if they require better precision
# than float provides.
await self.assert_query_result(
r'''
# 2^31 -1, -2, -3, -10
FOR x in <int32>{2147483647, 2147483646, 2147483645,
2147483638}
# 2147483647 is the max int32
SELECT x <= <int32>2147483647;
''',
[True, True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.NumericOutOfRangeError, r"std::int32 out of range"):
async with self.con.transaction():
await self.con.execute("""
SELECT <int32><float32><int32>2147483647;
""")
async with self.assertRaisesRegexTx(
edgedb.NumericOutOfRangeError, r"std::int32 out of range"):
async with self.con.transaction():
await self.con.execute("""
SELECT <int32><float32><int32>2147483646;
""")
async with self.assertRaisesRegexTx(
edgedb.NumericOutOfRangeError, r"std::int32 out of range"):
async with self.con.transaction():
await self.con.execute("""
SELECT <int32><float32><int32>2147483645;
""")
async with self.assertRaisesRegexTx(
edgedb.NumericOutOfRangeError, r"std::int32 out of range"):
async with self.con.transaction():
await self.con.execute("""
SELECT <int32><float32><int32>2147483638;
""") | ,
[True, True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.NumericOutOfRangeError, r"std::int32 out of range"):
async with self.con.transaction():
await self.con.execute( | test_edgeql_casts_numeric_05 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_collections_02(self):
await self.assert_query_result(
R'''
WITH
std AS MODULE math,
foo := (SELECT [1, 2, 3])
SELECT <array<str>>foo;
''',
[['1', '2', '3']],
)
await self.assert_query_result(
R'''
WITH
std AS MODULE math,
foo := (SELECT [<int32>1, <int32>2, <int32>3])
SELECT <array<str>>foo;
''',
[['1', '2', '3']],
)
await self.assert_query_result(
R'''
WITH
std AS MODULE math,
foo := (SELECT [(1,), (2,), (3,)])
SELECT <array<tuple<str>>>foo;
''',
[[['1'], ['2'], ['3']]],
) | ,
[['1', '2', '3']],
)
await self.assert_query_result(
R | test_edgeql_casts_collections_02 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_01(self):
await self.assert_query_result(
r'''SELECT <bool><json>True = True;''',
[True],
)
await self.assert_query_result(
r'''SELECT <bool><json>False = False;''',
[True],
)
await self.assert_query_result(
r'''SELECT <str><json>"Hello" = 'Hello';''',
[True],
)
await self.assert_query_result(
r'''
WITH U := uuid_generate_v1mc()
SELECT <uuid><json>U = U;
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <datetime><json>datetime_of_statement() =
datetime_of_statement();
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_datetime><json>cal::to_local_datetime(
'2018-05-07T20:01:22.306916') =
cal::to_local_datetime('2018-05-07T20:01:22.306916');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_date><json>cal::to_local_date('2018-05-07')
= cal::to_local_date('2018-05-07');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <cal::local_time><json>
cal::to_local_time('20:01:22.306916') =
cal::to_local_time('20:01:22.306916');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <duration><json>to_duration(hours:=20) =
to_duration(hours:=20);
''',
[True],
)
await self.assert_query_result(
r'''SELECT <int16><json>to_int16('12345') = 12345;''',
[True],
)
await self.assert_query_result(
r'''SELECT <int32><json>to_int32('1234567890') = 1234567890;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <int64><json>to_int64(
'1234567890123') = 1234567890123;
''',
[True],
)
await self.assert_query_result(
r'''SELECT <float32><json>to_float32('2.5') = 2.5;''',
[True],
)
await self.assert_query_result(
r'''SELECT <float64><json>to_float64('2.5') = 2.5;''',
[True],
)
await self.assert_query_result(
r'''
SELECT <bigint><json>to_bigint(
'123456789123456789123456789')
= to_bigint(
'123456789123456789123456789');
''',
[True],
)
await self.assert_query_result(
r'''
SELECT <decimal><json>to_decimal(
'123456789123456789123456789.123456789123456789123456789')
= to_decimal(
'123456789123456789123456789.123456789123456789123456789');
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_json_01 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_02(self):
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <bool><json>T.p_bool = T.p_bool;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <str><json>T.p_str = T.p_str;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <datetime><json>T.p_datetime = T.p_datetime;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <cal::local_datetime><json>T.p_local_datetime =
T.p_local_datetime;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <cal::local_date><json>T.p_local_date = T.p_local_date;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <cal::local_time><json>T.p_local_time = T.p_local_time;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <duration><json>T.p_duration = T.p_duration;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <int16><json>T.p_int16 = T.p_int16;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <int32><json>T.p_int32 = T.p_int32;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <int64><json>T.p_int64 = T.p_int64;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <float32><json>T.p_float32 = T.p_float32;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <float64><json>T.p_float64 = T.p_float64;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <bigint><json>T.p_bigint = T.p_bigint;
''',
[True],
)
await self.assert_query_result(
r'''
WITH T := (SELECT Test FILTER .p_str = 'Hello')
SELECT <decimal><json>T.p_decimal = T.p_decimal;
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_json_02 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_03(self):
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <bool>J.j_bool = T.p_bool;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <str>J.j_str = T.p_str;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <datetime>J.j_datetime = T.p_datetime;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <cal::local_datetime>J.j_local_datetime =
T.p_local_datetime;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <cal::local_date>J.j_local_date = T.p_local_date;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <cal::local_time>J.j_local_time = T.p_local_time;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <duration>J.j_duration = T.p_duration;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <int16>J.j_int16 = T.p_int16;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <int32>J.j_int32 = T.p_int32;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <int64>J.j_int64 = T.p_int64;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <float32>J.j_float32 = T.p_float32;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <float64>J.j_float64 = T.p_float64;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <bigint>J.j_bigint = T.p_bigint;
''',
[True],
)
await self.assert_query_result(
r'''
WITH
T := (SELECT Test FILTER .p_str = 'Hello'),
J := (SELECT JSONTest FILTER .j_str = <json>'Hello')
SELECT <decimal>J.j_decimal = T.p_decimal;
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_json_03 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_07(self):
# This is the same suite of tests as for str. The point is
# that when it comes to casting into various date and time
# types JSON strings and regular strings should behave
# identically.
#
# Canonical date and time str representations must follow ISO
# 8601. This test assumes that the server is configured to be
# in UTC time zone.
await self.assert_query_result(
r'''
FOR x in <json>'2018-05-07T20:01:22.306916+00:00'
SELECT <json><datetime>x = x;
''',
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r'''
FOR x in <json>{
'2018-05-07T15:01:22.306916-05:00',
'2018-05-07T15:01:22.306916-05',
'2018-05-07T20:01:22.306916Z',
'2018-05-07T20:01:22.306916+0000',
'2018-05-07T20:01:22.306916+00',
# the '-' and ':' separators may be omitted
'20180507T200122.306916+00',
# acceptable RFC 3339
'2018-05-07 20:01:22.306916+00:00',
'2018-05-07t20:01:22.306916z',
}
SELECT <datetime>x =
<datetime><json>'2018-05-07T20:01:22.306916+00:00';
''',
[True, True, True, True, True, True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime><json>"2018-05-07;20:01:22.306916+00:00"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime><json>"2018-05-07T20:01:22.306916"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime><json>"2018-05-07T20:01:22.306916 1000"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'''SELECT <datetime><json>
"2018-05-07T20:01:22.306916 US/Central"
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax'):
await self.con.query_single(
'SELECT <datetime><json>"2018-05-07T20:01:22.306916 +GMT1"') | ,
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r | test_edgeql_casts_json_07 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_08(self):
# This is the same suite of tests as for str. The point is
# that when it comes to casting into various date and time
# types JSON strings and regular strings should behave
# identically.
#
# Canonical date and time str representations must follow ISO
# 8601. This test assumes that the server is configured to be
# in UTC time zone.
await self.assert_query_result(
r'''
FOR x in <json>'2018-05-07T20:01:22.306916'
SELECT <json><cal::local_datetime>x = x;
''',
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r'''
FOR x in <json>{
# the '-' and ':' separators may be omitted
'20180507T200122.306916',
# acceptable RFC 3339
'2018-05-07 20:01:22.306916',
'2018-05-07t20:01:22.306916',
}
SELECT <cal::local_datetime>x =
<cal::local_datetime><json>'2018-05-07T20:01:22.306916';
''',
[True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''SELECT
<cal::local_datetime><json>"2018-05-07;20:01:22.306916"
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''SELECT <cal::local_datetime><json>
"2018-05-07T20:01:22.306916+01:00"
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''SELECT <cal::local_datetime><json>
"2018-05-07T20:01:22.306916 GMT"''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''SELECT <cal::local_datetime><json>
"2018-05-07T20:01:22.306916 GMT0"''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'''SELECT <cal::local_datetime><json>
"2018-05-07T20:01:22.306916 US/Central"
''') | ,
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same datetime
r | test_edgeql_casts_json_08 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_09(self):
# This is the same suite of tests as for str. The point is
# that when it comes to casting into various date and time
# types JSON strings and regular strings should behave
# identically.
#
# Canonical date and time str representations must follow ISO
# 8601.
await self.assert_query_result(
r'''
FOR x in <json>'2018-05-07'
SELECT <json><cal::local_date>x = x;
''',
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same date
r'''
# the '-' separators may be omitted
FOR x in <json>'20180507'
SELECT
<cal::local_date>x = <cal::local_date><json>'2018-05-07';
''',
[True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date><json>"2018-05-07T20:01:22.306916"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date><json>"2018/05/07"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date><json>"2018.05.07"')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_date><json>"2018-05-07+01:00"') | ,
[True],
)
await self.assert_query_result(
# validating that these are all in fact the same date
r | test_edgeql_casts_json_09 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_10(self):
# This is the same suite of tests as for str. The point is
# that when it comes to casting into various date and time
# types JSON strings and regular strings should behave
# identically.
#
# Canonical date and time str representations must follow ISO
# 8601.
await self.assert_query_result(
r'''
FOR x in <json>'20:01:22.306916'
SELECT <json><cal::local_time>x = x;
''',
[True],
)
await self.assert_query_result(
r'''
FOR x in <json>{
'20:01',
'20:01:00',
# the ':' separators may be omitted
'2001',
'200100',
}
SELECT <cal::local_time>x = <cal::local_time>'20:01:00';
''',
[True, True, True, True],
)
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
'invalid input syntax for type std::cal::local_time'):
await self.con.query_single(
"SELECT <cal::local_time><json>'2018-05-07 20:01:22'")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'invalid input syntax for type'):
await self.con.query_single(
'SELECT <cal::local_time><json>"20:01:22.306916+01:00"') | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_casts_json_10 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_11(self):
await self.assert_query_result(
r"SELECT <array<int64>><json>[1, 1, 2, 3, 5]",
[[1, 1, 2, 3, 5]]
)
# string to array
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'expected JSON array; got JSON string'):
await self.con.query_single(
r"SELECT <array<int64>><json>'asdf'")
# array of string to array of int
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'array<std::int64>', "
r"in array elements, "
r"expected JSON number or null; got JSON string"):
await self.con.query_single(
r"SELECT <array<int64>><json>['asdf']")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'array<std::int64>', "
r"in array elements, "
r"expected JSON number or null; got JSON string"):
await self.con.query_single(
r"SELECT <array<int64>>to_json('[1, 2, \"asdf\"]')")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'array<std::int64>', "
r"in array elements, "
r"expected JSON number or null; got JSON string"):
await self.con.execute("""
SELECT <array<int64>>to_json('["a"]');
""")
# array with null to array
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'array<std::json>' "
r"to 'array<std::int64>', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"SELECT <array<int64>>[to_json('1'), to_json('null')]")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"array<std::int64>', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"SELECT <array<int64>>to_json('[1, 2, null]')")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'array<std::json>' "
r"to 'array<std::int64>', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"SELECT <array<int64>><array<json>>to_json('[1, 2, null]')")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<array<std::str>>', "
r"at tuple element '0', "
r"invalid null value in cast"):
await self.con.query_single(
r"select <tuple<array<str>>>to_json('[null]')")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<array<std::str>>', "
r"at tuple element '0', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"select <tuple<array<str>>>to_json('[[null]]')")
# object to array
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON array; got JSON object"):
await self.con.execute("""
SELECT <array<int64>>to_json('{"a": 1}');
""")
# array of object to array of scalar
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'array<std::int64>', "
r"in array elements, "
r"expected JSON number or null; got JSON object"):
await self.con.execute("""
SELECT <array<int64>>to_json('[{"a": 1}]');
""")
# nested array
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'array<tuple<array<std::str>>>', "
r"in array elements, "
r"at tuple element '0', "
r"in array elements, "
r"expected JSON string or null; got JSON number"):
await self.con.execute("""
SELECT <array<tuple<array<str>>>>to_json('[[[1]]]');
""") | )
# array with null to array
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'array<std::json>' "
r"to 'array<std::int64>', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"SELECT <array<int64>>[to_json('1'), to_json('null')]")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"array<std::int64>', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"SELECT <array<int64>>to_json('[1, 2, null]')")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'array<std::json>' "
r"to 'array<std::int64>', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"SELECT <array<int64>><array<json>>to_json('[1, 2, null]')")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<array<std::str>>', "
r"at tuple element '0', "
r"invalid null value in cast"):
await self.con.query_single(
r"select <tuple<array<str>>>to_json('[null]')")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<array<std::str>>', "
r"at tuple element '0', "
r"in array elements, "
r"invalid null value in cast"):
await self.con.query_single(
r"select <tuple<array<str>>>to_json('[[null]]')")
# object to array
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON array; got JSON object"):
await self.con.execute( | test_edgeql_casts_json_11 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_12(self):
self.assertEqual(
await self.con.query(
r"""
SELECT <tuple<a: int64, b: int64>>
to_json('{"a": 1, "b": 2}')
"""
),
[edgedb.NamedTuple(a=1, b=2)],
)
await self.assert_query_result(
r"""
SELECT <tuple<a: int64, b: int64>>
to_json({'{"a": 3000, "b": -1}', '{"a": 1, "b": 12}'});
""",
[{"a": 3000, "b": -1}, {"a": 1, "b": 12}],
)
await self.assert_query_result(
r"""
SELECT <tuple<int64, int64>>
to_json({'[3000, -1]', '[1, 12]'})
""",
[[3000, -1], [1, 12]],
)
self.assertEqual(
await self.con.query(
r"""
SELECT <tuple<int64, int64>>
to_json({'[3000, -1]', '[1, 12]'})
"""
),
[(3000, -1), (1, 12)],
)
self.assertEqual(
await self.con.query(
r"""
SELECT <tuple<json, json>>
to_json({'[3000, -1]', '[1, 12]'})
"""
),
[('3000', '-1'), ('1', '12')],
)
self.assertEqual(
await self.con.query(
r"""
SELECT <tuple<json, json>>
to_json({'[3000, -1]', '[1, null]'})
"""
),
[('3000', '-1'), ('1', 'null')],
)
self.assertEqual(
await self.con.query_single(
r"""
SELECT <tuple<int64, tuple<a: int64, b: int64>>>
to_json('[3000, {"a": 1, "b": 2}]')
"""
),
(3000, edgedb.NamedTuple(a=1, b=2))
)
self.assertEqual(
await self.con.query_single(
r"""
SELECT <tuple<int64, array<tuple<a: int64, b: str>>>>
to_json('[3000, [{"a": 1, "b": "foo"},
{"a": 12, "b": "bar"}]]')
"""
),
(3000,
[edgedb.NamedTuple(a=1, b="foo"),
edgedb.NamedTuple(a=12, b="bar")])
)
# object with wrong element type to tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: std::int64, b: std::int64>', "
r"at tuple element 'b', "
r"expected JSON number or null; got JSON string"):
await self.con.query(
r"""
SELECT <tuple<a: int64, b: int64>>
to_json('{"a": 1, "b": "2"}')
"""
)
# object with null value to tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: std::int64>', "
r"at tuple element 'a', "
r"invalid null value in cast"):
await self.con.query(
r"""SELECT <tuple<a: int64>>to_json('{"a": null}')"""
)
# object with missing element to tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: std::int64, b: std::int64>', "
r"at tuple element 'b', "
r"missing value in JSON object"):
await self.con.query(
r"""SELECT <tuple<a: int64, b: int64>>to_json('{"a": 1}')"""
)
# short array to unnamed tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<std::int64, std::int64>', "
r"at tuple element '1', "
r"missing value in JSON object"):
await self.con.query(
r"""SELECT <tuple<int64, int64>>to_json('[3000]')"""
)
# array to named tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: std::int64, b: std::int64>', "
r"at tuple element 'a', "
r"missing value in JSON object"):
await self.con.query(
r"""
SELECT <tuple<a: int64, b: int64>>
to_json('[3000, 1000]')
"""
)
# string to tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r'expected JSON array or object or null; got JSON string'):
await self.con.query(
r"""SELECT <tuple<a: int64, b: int64>> to_json('"test"')"""
)
# short array to unnamed tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<std::json, std::json>', "
r"at tuple element '1', "
r"missing value in JSON object"):
await self.con.query(
r"""SELECT <tuple<json, json>> to_json('[3000]')"""
)
# object to unnamed tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' to "
r"'tuple<std::int64>', "
r"at tuple element '0', "
r"missing value in JSON object"):
await self.con.execute("""
SELECT <tuple<int64>>to_json('{"a": 1}');
""")
# nested tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: tuple<b: std::str>>', "
r"at tuple element 'a', "
r"at tuple element 'b', "
r"expected JSON string or null; got JSON number"):
await self.con.execute("""
SELECT <tuple<a: tuple<b: str>>>to_json('{"a": {"b": 1}}');
""")
# array with null to tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<std::int64, std::int64>', "
r"at tuple element '1', "
r"invalid null value in cast"):
await self.con.execute("""
SELECT <tuple<int64, int64>>to_json('[1, null]');
""")
# object with null to tuple
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: std::int64>', "
r"at tuple element 'a', "
r"invalid null value in cast"):
await self.con.execute("""
SELECT <tuple<a: int64>>to_json('{"a": null}');
""")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: array<std::int64>>', "
r"at tuple element 'a', "
r"invalid null value in cast"):
await self.con.execute("""
SELECT <tuple<a: array<int64>>>to_json('{"a": null}');
""")
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'tuple<a: tuple<b: std::str>>', "
r"at tuple element 'a', "
r"invalid null value in cast"):
await self.con.execute("""
SELECT <tuple<a: tuple<b: str>>>to_json('{"a": null}');
""") | ),
[edgedb.NamedTuple(a=1, b=2)],
)
await self.assert_query_result(
r | test_edgeql_casts_json_12 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_13(self):
await self.assert_query_result(
r'''
select <array<json>>to_json('null')
''',
[],
)
await self.assert_query_result(
r'''
select <array<str>>to_json('null')
''',
[],
)
await self.assert_query_result(
r'''
select <array<int64>>json_get(to_json('{}'), 'foo')
''',
[],
)
await self.assert_query_result(
r'''
select <tuple<str>>to_json('null')
''',
[],
)
await self.assert_query_result(
r'''
select <tuple<json>>to_json('null')
''',
[],
)
await self.assert_query_result(
r'''
select <bigint>to_json('null')
''',
[],
)
await self.assert_query_result(
r'''
select <decimal>to_json('null')
''',
[],
)
await self.assert_query_result(
r'''
select <bigint><str>to_json('null')
''',
[],
)
await self.assert_query_result(
r'''
select <decimal><str>to_json('null')
''',
[],
) | ,
[],
)
await self.assert_query_result(
r | test_edgeql_casts_json_13 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_14(self):
await self.assert_query_result(
r'''
select <array<json>>to_json('[]')
''',
[[]],
)
await self.assert_query_result(
r'''
select <array<str>>to_json('[]')
''',
[[]],
) | ,
[[]],
)
await self.assert_query_result(
r | test_edgeql_casts_json_14 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_15(self):
# At one point, a cast from an object inside a binary
# operation triggered an infinite loop in staeval if the
# object had a self link.
await self.con.execute('''
create type Z { create link z -> Z; };
''')
await self.con.query('''
select <json>Z union <json>Z;
''') | )
await self.con.query( | test_edgeql_casts_json_15 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_16(self):
# number to range
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON object or null; got JSON number"):
await self.con.execute("""
SELECT <range<int64>>to_json('1');
""")
# array to range
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON object or null; got JSON array"):
await self.con.execute("""
SELECT <range<int64>>to_json('[1]');
""")
# object to range, bad empty
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'range<std::int64>', "
r"in range parameter 'empty', "
r"expected JSON boolean or null; got JSON number"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"empty": 1
}');
""")
# object to range, empty with distinct lower and upper
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"conflicting arguments in range constructor: 'empty' is "
r"`true` while the specified bounds suggest otherwise"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"empty": true,
"lower": 1,
"upper": 2
}');
""")
# object to range, empty with same lower and upper
# and inc_lower and inc_upper
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"conflicting arguments in range constructor: 'empty' is "
r"`true` while the specified bounds suggest otherwise"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"empty": true,
"lower": 1,
"upper": 2,
"inc_lower": true,
"inc_upper": true
}');
""")
# object to range, missing inc_lower
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"JSON object representing a range must include an "
r"'inc_lower'"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"inc_upper": false
}');
""")
# object to range, missing inc_upper
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"JSON object representing a range must include an "
r"'inc_upper'"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"inc_lower": false
}');
""")
# object to range, bad inc_lower
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'range<std::int64>', "
r"in range parameter 'inc_lower', "
r"expected JSON boolean or null; got JSON number"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"inc_lower": 1,
"inc_upper": false
}');
""")
# object to range, bad inc_upper
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"while casting 'std::json' "
r"to 'range<std::int64>', "
r"in range parameter 'inc_upper', "
r"expected JSON boolean or null; got JSON number"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"inc_lower": false,
"inc_upper": 1
}');
""")
# object to range, extra parameters
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"JSON object representing a range contains unexpected keys: "
r"bar, foo"):
await self.con.execute("""
SELECT <range<int64>>to_json('{
"lower": 1,
"upper": 2,
"inc_lower": true,
"inc_upper": true,
"foo": "foo",
"bar": "bar"
}');
""") | )
# array to range
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON object or null; got JSON array"):
await self.con.execute( | test_edgeql_casts_json_16 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_json_17(self):
# number to multirange
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON array; got JSON number"):
await self.con.execute("""
SELECT <multirange<int64>>to_json('1');
""")
# object to multirange
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON array; got JSON object"):
await self.con.execute("""
SELECT <multirange<int64>>to_json('{"a": 1}');
""") | )
# object to multirange
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"expected JSON array; got JSON object"):
await self.con.execute( | test_edgeql_casts_json_17 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_assignment_01(self):
async with self._run_and_rollback():
await self.con.execute(r"""
# int64 is assignment castable or implicitly castable
# into any other numeric type
INSERT ScalarTest {
p_int16 := 1,
p_int32 := 1,
p_int64 := 1,
p_float32 := 1,
p_float64 := 1,
p_bigint := 1,
p_decimal := 1,
};
""")
await self.assert_query_result(
r"""
SELECT ScalarTest {
p_int16,
p_int32,
p_int64,
p_float32,
p_float64,
p_bigint,
p_decimal,
};
""",
[{
'p_int16': 1,
'p_int32': 1,
'p_int64': 1,
'p_float32': 1,
'p_float64': 1,
'p_bigint': 1,
'p_decimal': 1,
}],
) | )
await self.assert_query_result(
r | test_edgeql_casts_assignment_01 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_assignment_02(self):
async with self._run_and_rollback():
await self.con.execute(r"""
# float64 is assignment castable to float32
INSERT ScalarTest {
p_float32 := 1.5,
};
""")
await self.assert_query_result(
r"""
SELECT ScalarTest {
p_float32,
};
""",
[{
'p_float32': 1.5,
}],
) | )
await self.assert_query_result(
r | test_edgeql_casts_assignment_02 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_assignment_03(self):
async with self._run_and_rollback():
# in particular, bigint and decimal are not assignment-castable
# into any other numeric type
for typename in ['int16',
'int32',
'int64',
'float32',
'float64']:
for numtype in {'bigint', 'decimal'}:
query = f'''
INSERT ScalarTest {{
p_{typename} := <{numtype}>3,
p_{numtype} := 1001,
}};
'''
async with self.assertRaisesRegexTx(
edgedb.QueryError,
r'invalid target for property',
msg=query):
await self.con.execute(query + f'''
# clean up, so other tests can proceed
DELETE (
SELECT ScalarTest
FILTER .p_{numtype} = 1001
);
''') | async with self.assertRaisesRegexTx(
edgedb.QueryError,
r'invalid target for property',
msg=query):
await self.con.execute(query + f | test_edgeql_casts_assignment_03 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_custom_scalar_02(self):
await self.assert_query_result(
"""
SELECT <foo><bar>'test'
""",
['test'],
)
await self.assert_query_result(
"""
SELECT <array<foo>><array<bar>>['test']
""",
[['test']],
) | SELECT <foo><bar>'test'
""",
['test'],
)
await self.assert_query_result( | test_edgeql_casts_custom_scalar_02 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_custom_scalar_03(self):
await self.assert_query_result(
"""
SELECT <array<custom_str_t>><array<bar>>['TEST']
""",
[['TEST']],
)
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, r'invalid'
):
await self.con.query("""
SELECT <custom_str_t><bar>'test'
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, r'invalid'
):
await self.con.query("""
SELECT <array<custom_str_t>><array<bar>>['test']
""") | SELECT <array<custom_str_t>><array<bar>>['TEST']
""",
[['TEST']],
)
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, r'invalid'
):
await self.con.query( | test_edgeql_casts_custom_scalar_03 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_custom_scalar_04(self):
await self.con.execute('''
create abstract scalar type abs extending int64;
create scalar type foo2 extending abs;
create scalar type bar2 extending abs;
''')
await self.assert_query_result(
"""
SELECT <foo2><bar2>42
""",
[42],
)
await self.assert_query_result(
"""
SELECT <array<foo2>><array<bar2>>[42]
""",
[[42]],
) | )
await self.assert_query_result( | test_edgeql_casts_custom_scalar_04 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_custom_scalar_05(self):
await self.con.execute('''
create abstract scalar type xfoo extending int64;
create abstract scalar type xbar extending int64;
create scalar type bar1 extending xfoo, xbar;
create scalar type bar2 extending xfoo, xbar;
''')
await self.assert_query_result(
"""
SELECT <bar1><bar2>42
""",
[42],
)
await self.assert_query_result(
"""
SELECT <array<bar1>><array<bar2>>[42]
""",
[[42]],
) | )
await self.assert_query_result( | test_edgeql_casts_custom_scalar_05 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_custom_scalar_06(self):
await self.con.execute(
'''
create scalar type x extending str {
create constraint expression on (false)
};
'''
)
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, 'invalid x'
):
await self.con.query("""SELECT <x>42""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, 'invalid x'
):
await self.con.query("""SELECT <x>to_json('"a"')""") | create scalar type x extending str {
create constraint expression on (false)
}; | test_edgeql_casts_custom_scalar_06 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_tuple_params_03(self):
# try *doing* something with the input
await self.con.query(
r'''
create type Record {
create required property name -> str;
create multi property tags -> int64;
}
'''
)
data = [
[],
[('x', [])],
[('x', [1])],
[('x', []), ('y', []), ('z', [])],
[('x', [1]), ('y', []), ('z', [])],
[('x', []), ('y', [1]), ('z', [])],
[('x', []), ('y', []), ('z', [1])],
[('x', []), ('y', [1, 2]), ('z', [1, 2, 3])],
]
qry = r'''
for row in array_unpack(<array<tuple<str, array<int64>>>>$0) union ((
insert Record { name := row.0, tags := array_unpack(row.1) }
))
'''
for inp in data:
exp = tb.bag([
{'name': name, 'tags': tb.bag(tags)}
for name, tags in inp
])
async with self._run_and_rollback():
await self.con.execute(qry, inp)
await self.assert_query_result(
'''
select Record { name, tags }
''',
exp,
msg=f'inp: {inp}',
) | )
data = [
[],
[('x', [])],
[('x', [1])],
[('x', []), ('y', []), ('z', [])],
[('x', [1]), ('y', []), ('z', [])],
[('x', []), ('y', [1]), ('z', [])],
[('x', []), ('y', []), ('z', [1])],
[('x', []), ('y', [1, 2]), ('z', [1, 2, 3])],
]
qry = r | test_edgeql_casts_tuple_params_03 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_tuple_params_05(self):
max_depth = 20
# Test deep nesting
t = 'int64'
v = 0
for _ in range(max_depth):
t = f'tuple<{t}>'
v = (v,)
await self.assert_query_result(
f'''
select <{t}>$0
''',
[v],
variables=(v,),
)
# One more and it should fail
t = f'tuple<{t}>'
v = (v,)
async with self.assertRaisesRegexTx(
edgedb.QueryError, r'too deeply nested'):
await self.con.query(f"""
select <{t}>$0
""", v) | ,
[v],
variables=(v,),
)
# One more and it should fail
t = f'tuple<{t}>'
v = (v,)
async with self.assertRaisesRegexTx(
edgedb.QueryError, r'too deeply nested'):
await self.con.query(f | test_edgeql_casts_tuple_params_05 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_tuple_params_06(self):
# Test multiple tuple params mixed with other stuff
await self.assert_query_result(
'''
select
(<tuple<str, str>>$0).0 ++ <str>$1 ++ (<tuple<str, str>>$0).1
''',
['foo bar'],
variables=(('foo', 'bar'), ' ',),
)
await self.assert_query_result(
'''
select
(<tuple<str, str>>$0).0 ++ <str>$1 ++ (<tuple<str, str>>$0).1
++ '!'
''',
['foo bar!'],
variables=(('foo', 'bar'), ' ',),
)
await self.assert_query_result(
'''
select
(<tuple<str, str>>$0).0 ++ <str>$1 ++ (<tuple<str, str>>$0).1
++ (with z := (<tuple<str, str>>$2) select (z.0 ++ z.1))
++ '!'
''',
['foo barxy!'],
variables=(('foo', 'bar'), ' ', ('x', 'y')),
) | select
(<tuple<str, str>>$0).0 ++ <str>$1 ++ (<tuple<str, str>>$0).1
''',
['foo bar'],
variables=(('foo', 'bar'), ' ',),
)
await self.assert_query_result( | test_edgeql_casts_tuple_params_06 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_tuple_params_08(self):
await self.assert_query_result(
'''
select { x := <optional tuple<str, str>>$0, y := <str>$1 };
''',
[{'x': None, 'y': "test"}],
variables=(None, 'test'),
)
await self.assert_query_result(
'''
select { x := <optional tuple<str, str>>$0, y := <int64>$1 };
''',
[{'x': None, 'y': 11111}],
variables=(None, 11111),
) | select { x := <optional tuple<str, str>>$0, y := <str>$1 };
''',
[{'x': None, 'y': "test"}],
variables=(None, 'test'),
)
await self.assert_query_result( | test_edgeql_casts_tuple_params_08 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_tuple_params_09(self):
await self.con.query('''
WITH
p := <tuple<test: str>>$0
insert Test { p_tup := p };
''', ('foo',))
await self.assert_query_result(
'''
select Test { p_tup } filter exists .p_tup
''',
[{'p_tup': {'test': 'foo'}}],
)
await self.assert_query_result(
'''
WITH
p := <tuple<test: str>>$0
select p
''',
[{'test': 'foo'}],
variables=(('foo',),),
)
await self.assert_query_result(
'''
select <tuple<test: str>>$0
''',
[{'test': 'foo'}],
variables=(('foo',),),
)
await self.assert_query_result(
'''
select <array<tuple<test: str>>>$0
''',
[[{'test': 'foo'}, {'test': 'bar'}]],
variables=([('foo',), ('bar',)],),
) | , ('foo',))
await self.assert_query_result( | test_edgeql_casts_tuple_params_09 | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_all_null(self):
# For *every* cast, try casting a value we know
# will be represented as NULL.
casts = await self.con.query('''
select schema::Cast { from_type: {name}, to_type: {name} }
filter not .from_type is schema::ObjectType
''')
def _t(s):
# Instantiate polymorphic types
return (
s
.replace('anytype', 'str')
.replace('anytuple', 'tuple<str, int64>')
.replace('std::anyenum', 'schema::Cardinality')
.replace('std::anypoint', 'int64')
)
from_types = {_t(cast.from_type.name) for cast in casts}
type_keys = {
name: f'x{i}' for i, name in enumerate(sorted(from_types))
}
# Populate a type that has an optional field for each cast source type
sep = '\n '
props = sep.join(
f'CREATE PROPERTY {n} -> {_t(t)};'
for t, n in type_keys.items()
)
setup = f'''
CREATE TYPE Null {{
{props}
}};
INSERT Null;
'''
await self.con.execute(setup)
# Do each cast
for cast in casts:
prop = type_keys[_t(cast.from_type.name)]
await self.assert_query_result(
f'''
SELECT Null {{
res := <{_t(cast.to_type.name)}>.{prop}
}}
''',
[{"res": None}],
msg=f'{cast.from_type.name} to {cast.to_type.name}',
)
# For casts from JSON, also do the related operation of
# casting from a JSON null, which should produce an empty
# set.
if cast.from_type.name == 'std::json':
await self.assert_query_result(
f'''
SELECT <{_t(cast.to_type.name)}>to_json('null')
''',
[],
msg=f'json null cast to {cast.to_type.name}',
) | )
def _t(s):
# Instantiate polymorphic types
return (
s
.replace('anytype', 'str')
.replace('anytuple', 'tuple<str, int64>')
.replace('std::anyenum', 'schema::Cardinality')
.replace('std::anypoint', 'int64')
)
from_types = {_t(cast.from_type.name) for cast in casts}
type_keys = {
name: f'x{i}' for i, name in enumerate(sorted(from_types))
}
# Populate a type that has an optional field for each cast source type
sep = '\n '
props = sep.join(
f'CREATE PROPERTY {n} -> {_t(t)};'
for t, n in type_keys.items()
)
setup = f | test_edgeql_casts_all_null | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
async def test_edgeql_casts_uuid_to_object(self):
persons = await self.con.query('select Person { id }')
dummy_uuid = '1' * 32
res = await self.con.query('select <Person><uuid>$0', persons[0].id)
self.assertEqual(len(res), 1)
async with self.assertRaisesRegexTx(
edgedb.CardinalityViolationError, r'with id .* does not exist'
):
await self.con.query('select <Person><uuid>$0', dummy_uuid)
await self.assert_query_result(
'''
select (<Person>{<uuid>$0, <uuid>$1}) { name }
order by .name;
''',
[{'name': 'kelly'}, {'name': 'tom'}],
json_only=True,
variables=(persons[0].id, persons[1].id),
)
async with self.assertRaisesRegexTx(
edgedb.CardinalityViolationError, r'with id .* does not exist'
):
await self.con.query(
'''
select (<Person>{<uuid>$0, <uuid>$1}) { name }
order by .name;
''', persons[0].id, dummy_uuid
)
res = await self.con.query(
'select <Person><optional uuid>$0', persons[0].id
)
self.assertEqual(len(res), 1)
res = await self.con.query(
'select <optional Person><optional uuid>$0', None
)
self.assertEqual(len(res), 0)
res = await self.con.query('select <optional Person><optional uuid>{}')
self.assertEqual(len(res), 0)
res = await self.con.query('select <Person><optional uuid>$0', None)
self.assertEqual(len(res), 0)
res = await self.con.query('select <Person>$0', persons[0].id)
self.assertEqual(len(res), 1)
res = await self.con.query('select <optional Person>$0', None)
self.assertEqual(len(res), 0)
async with self.assertRaisesRegexTx(
edgedb.CardinalityViolationError, r'with id .* does not exist'
):
await self.con.query('select <optional Person>$0', dummy_uuid)
async with self.assertRaisesRegexTx(
edgedb.CardinalityViolationError, r'with id .* does not exist'
):
await self.con.query('select <Person>$0', dummy_uuid) | select (<Person>{<uuid>$0, <uuid>$1}) { name }
order by .name;
''',
[{'name': 'kelly'}, {'name': 'tom'}],
json_only=True,
variables=(persons[0].id, persons[1].id),
)
async with self.assertRaisesRegexTx(
edgedb.CardinalityViolationError, r'with id .* does not exist'
):
await self.con.query( | test_edgeql_casts_uuid_to_object | python | geldata/gel | tests/test_edgeql_casts.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_casts.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.