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
async def test_edgeql_advtypes_delete_complex_type_02(self): await self._setup_basic_data() await self.con.execute( r""" delete Ba[is Bb][is Bc]; """ ) # Ensure the rest of the data is unchanged await self.assert_query_result( r""" select (DISTINCT {Ba, Bb, Bc}){ tn := .__type__.name, [IS Ba].ba, [IS Bb].bb, [IS Bc].bc, } order by .tn then .ba then .bb then .bc; """, [ {'tn': 'default::CBa', 'ba': 'cba0', 'bb': None, 'bc': None}, {'tn': 'default::CBa', 'ba': 'cba1', 'bb': None, 'bc': None}, {'tn': 'default::CBaBb', 'ba': 'cba2', 'bb': 2, 'bc': None}, {'tn': 'default::CBaBb', 'ba': 'cba3', 'bb': 3, 'bc': None}, {'tn': 'default::CBaBc', 'ba': 'cba4', 'bb': None, 'bc': 4.5}, {'tn': 'default::CBaBc', 'ba': 'cba5', 'bb': None, 'bc': 5.5}, {'tn': 'default::CBb', 'ba': None, 'bb': 0, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 1, 'bc': None}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 6, 'bc': 6.5}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 7, 'bc': 7.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 0.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 1.5}, ], )
) # Ensure the rest of the data is unchanged await self.assert_query_result( r
test_edgeql_advtypes_delete_complex_type_02
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_delete_complex_type_03(self): await self._setup_basic_data() await self.con.execute( r""" delete Ba[is Bb | Bc]; """ ) # Ensure the rest of the data is unchanged await self.assert_query_result( r""" select (DISTINCT {Ba, Bb, Bc}){ tn := .__type__.name, [IS Ba].ba, [IS Bb].bb, [IS Bc].bc, } order by .tn then .ba then .bb then .bc; """, [ {'tn': 'default::CBa', 'ba': 'cba0', 'bb': None, 'bc': None}, {'tn': 'default::CBa', 'ba': 'cba1', 'bb': None, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 0, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 1, 'bc': None}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 6, 'bc': 6.5}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 7, 'bc': 7.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 0.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 1.5}, ], )
) # Ensure the rest of the data is unchanged await self.assert_query_result( r
test_edgeql_advtypes_delete_complex_type_03
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_delete_complex_type_04(self): await self._setup_basic_data() await self.con.execute( r""" delete Ba[is Bb & Bc]; """ ) # Ensure the rest of the data is unchanged await self.assert_query_result( r""" select (DISTINCT {Ba, Bb, Bc}){ tn := .__type__.name, [IS Ba].ba, [IS Bb].bb, [IS Bc].bc, } order by .tn then .ba then .bb then .bc; """, [ {'tn': 'default::CBa', 'ba': 'cba0', 'bb': None, 'bc': None}, {'tn': 'default::CBa', 'ba': 'cba1', 'bb': None, 'bc': None}, {'tn': 'default::CBaBb', 'ba': 'cba2', 'bb': 2, 'bc': None}, {'tn': 'default::CBaBb', 'ba': 'cba3', 'bb': 3, 'bc': None}, {'tn': 'default::CBaBc', 'ba': 'cba4', 'bb': None, 'bc': 4.5}, {'tn': 'default::CBaBc', 'ba': 'cba5', 'bb': None, 'bc': 5.5}, {'tn': 'default::CBb', 'ba': None, 'bb': 0, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 1, 'bc': None}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 6, 'bc': 6.5}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 7, 'bc': 7.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 0.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 1.5}, ], )
) # Ensure the rest of the data is unchanged await self.assert_query_result( r
test_edgeql_advtypes_delete_complex_type_04
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_delete_complex_type_05(self): await self._setup_basic_data() await self.con.execute( r""" delete Ba[IS CBa | Bb & Bc]; """ ) # Ensure the rest of the data is unchanged await self.assert_query_result( r""" select (DISTINCT {Ba, Bb, Bc}){ tn := .__type__.name, [IS Ba].ba, [IS Bb].bb, [IS Bc].bc, } order by .tn then .ba then .bb then .bc; """, [ {'tn': 'default::CBaBb', 'ba': 'cba2', 'bb': 2, 'bc': None}, {'tn': 'default::CBaBb', 'ba': 'cba3', 'bb': 3, 'bc': None}, {'tn': 'default::CBaBc', 'ba': 'cba4', 'bb': None, 'bc': 4.5}, {'tn': 'default::CBaBc', 'ba': 'cba5', 'bb': None, 'bc': 5.5}, {'tn': 'default::CBb', 'ba': None, 'bb': 0, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 1, 'bc': None}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 6, 'bc': 6.5}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 7, 'bc': 7.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 0.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 1.5}, ], )
) # Ensure the rest of the data is unchanged await self.assert_query_result( r
test_edgeql_advtypes_delete_complex_type_05
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_delete_complex_type_06(self): await self._setup_basic_data() await self.con.execute( r""" delete {CBa, Ba[IS Bb & Bc]}; """ ) # Ensure the rest of the data is unchanged await self.assert_query_result( r""" select (DISTINCT {Ba, Bb, Bc}){ tn := .__type__.name, [IS Ba].ba, [IS Bb].bb, [IS Bc].bc, } order by .tn then .ba then .bb then .bc; """, [ {'tn': 'default::CBaBb', 'ba': 'cba2', 'bb': 2, 'bc': None}, {'tn': 'default::CBaBb', 'ba': 'cba3', 'bb': 3, 'bc': None}, {'tn': 'default::CBaBc', 'ba': 'cba4', 'bb': None, 'bc': 4.5}, {'tn': 'default::CBaBc', 'ba': 'cba5', 'bb': None, 'bc': 5.5}, {'tn': 'default::CBb', 'ba': None, 'bb': 0, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 1, 'bc': None}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 6, 'bc': 6.5}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 7, 'bc': 7.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 0.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 1.5}, ], )
) # Ensure the rest of the data is unchanged await self.assert_query_result( r
test_edgeql_advtypes_delete_complex_type_06
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_delete_complex_type_07(self): await self._setup_basic_data() await self.con.execute( r""" delete Object[IS (Ba & Bb) | (Ba & Bc)]; """ ) # Ensure the rest of the data is unchanged await self.assert_query_result( r""" select (DISTINCT {Ba, Bb, Bc}){ tn := .__type__.name, [IS Ba].ba, [IS Bb].bb, [IS Bc].bc, } order by .tn then .ba then .bb then .bc; """, [ {'tn': 'default::CBa', 'ba': 'cba0', 'bb': None, 'bc': None}, {'tn': 'default::CBa', 'ba': 'cba1', 'bb': None, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 0, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 1, 'bc': None}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 6, 'bc': 6.5}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 7, 'bc': 7.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 0.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 1.5}, ], )
) # Ensure the rest of the data is unchanged await self.assert_query_result( r
test_edgeql_advtypes_delete_complex_type_07
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_delete_complex_type_08(self): await self._setup_basic_data() await self.con.execute( r""" delete {Object[IS Ba & Bb], Object[IS Ba & Bc]}; """ ) # Ensure the rest of the data is unchanged await self.assert_query_result( r""" select (DISTINCT {Ba, Bb, Bc}){ tn := .__type__.name, [IS Ba].ba, [IS Bb].bb, [IS Bc].bc, } order by .tn then .ba then .bb then .bc; """, [ {'tn': 'default::CBa', 'ba': 'cba0', 'bb': None, 'bc': None}, {'tn': 'default::CBa', 'ba': 'cba1', 'bb': None, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 0, 'bc': None}, {'tn': 'default::CBb', 'ba': None, 'bb': 1, 'bc': None}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 6, 'bc': 6.5}, {'tn': 'default::CBbBc', 'ba': None, 'bb': 7, 'bc': 7.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 0.5}, {'tn': 'default::CBc', 'ba': None, 'bb': None, 'bc': 1.5}, ], )
) # Ensure the rest of the data is unchanged await self.assert_query_result( r
test_edgeql_advtypes_delete_complex_type_08
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_intersection_pointers_01(self): # Type intersections with incompatible pointers should produce errors. type_roots = [ "SoloNonCompSingle", "SoloNonCompMulti", "SoloCompSingle", "SoloCompMulti", "DerivedNonCompSingle", "DerivedNonCompMulti", "DerivedCompSingle", "DerivedCompMulti", ] for type_root_a in type_roots: for type_root_b in type_roots: for type_suffix, ptr_name in ( ("Prop", "numbers"), ("Link", "siblings"), ): if ( # Either type has computed pointer ( "NonComp" not in type_root_a or "NonComp" not in type_root_b ) # but the pointer doesn't come from a common base and not ( "Derived" in type_root_a and type_root_a == type_root_b ) ): async with self.assertRaisesRegexTx( edgedb.SchemaError, r"it is illegal to create a type intersection " r"that causes a computed .* to mix " r"with other versions of the same .*" ): await self.con.execute(f""" select {type_root_a}{type_suffix}A {{ x := ( [is {type_root_b}{type_suffix}B] .{ptr_name} ) }}; """) elif ( # differing pointer cardinalities ("Single" in type_root_a) != ("Single" in type_root_b) ): async with self.assertRaisesRegexTx( edgedb.SchemaError, r"it is illegal to create a type intersection " r"that causes a .* to mix " r"with other versions of .* " r"which have a different cardinality" ): await self.con.execute(f""" select {type_root_a}{type_suffix}A {{ x := ( [is {type_root_b}{type_suffix}B] .{ptr_name} ) }}; """) else: await self.con.execute(f""" select {type_root_a}{type_suffix}A {{ x := ( [is {type_root_b}{type_suffix}B] .{ptr_name} ) }}; """)
) elif ( # differing pointer cardinalities ("Single" in type_root_a) != ("Single" in type_root_b) ): async with self.assertRaisesRegexTx( edgedb.SchemaError, r"it is illegal to create a type intersection " r"that causes a .* to mix " r"with other versions of .* " r"which have a different cardinality" ): await self.con.execute(f
test_edgeql_advtypes_intersection_pointers_01
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_intersection_pointers_02(self): # Intersection pointer should return nothing if they types are # unrelated. await self.con.execute(""" INSERT SoloOriginA { dest := (INSERT Destination{ name := "A" }) }; INSERT SoloOriginB { dest := (INSERT Destination{ name := "B" }) }; """) await self.assert_query_result( r""" SELECT SoloOriginA { x := [is SoloOriginB].dest.name } """, [{'x': None}], )
) await self.assert_query_result( r
test_edgeql_advtypes_intersection_pointers_02
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_advtypes_intersection_pointers_03(self): # Intersection pointer should return the correct values if the type # intersection is not empty. await self.con.execute(""" INSERT BaseOriginA { dest := (INSERT Destination{ name := "A" }) }; INSERT BaseOriginB { dest := (INSERT Destination{ name := "B" }) }; INSERT DerivedOriginC { dest := (INSERT Destination{ name := "C" }) }; """) await self.assert_query_result( r""" SELECT BaseOriginA { x := [is BaseOriginB].dest.name } ORDER BY .x """, [{'x': None}, {'x': 'C'}], )
) await self.assert_query_result( r
test_edgeql_advtypes_intersection_pointers_03
python
geldata/gel
tests/test_edgeql_advtypes.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_advtypes.py
Apache-2.0
async def test_edgeql_ext_pgcrypto_digest(self): CASES = [ ("md5", "rL0Y20zC+Fzt72VPzMSk2A=="), ("sha1", "C+7Hteo/D9vJXQ3UfzxbwnXaijM="), ("sha224", "CAj2TmDViXn8tnbJbsk4Jw3qQkRa7vzTpOb42w=="), ("sha256", "LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564="), ("sha384", "mMEf/f3VQGdrGhN8saIrKnA1DJpEFx1rEYDGvly7LuP3n" + "VMsih3Z7y6OCOdSo7q7"), ("sha512", "9/u6bgY2+JDlb7vzKD5STG+jIErimDgtYkdB0NxmODJuK" + "CxBvl5CVNiCB3LFUYosWowMf37aGVlK\nfrU5RT4e1w=="), ] for hash_type, result in CASES: with self.subTest(hash_type): await self.assert_query_result( """ select ext::pgcrypto::digest(<str>$data, <str>$type) """, [result], variables={ "data": "foo", "type": hash_type, }, json_only=True, ) await self.assert_query_result( """ select ext::pgcrypto::digest(<bytes>$data, <str>$type) """, [result], variables={ "data": b"foo", "type": hash_type, }, json_only=True, )
select ext::pgcrypto::digest(<str>$data, <str>$type) """, [result], variables={ "data": "foo", "type": hash_type, }, json_only=True, ) await self.assert_query_result(
test_edgeql_ext_pgcrypto_digest
python
geldata/gel
tests/test_edgeql_ext_pgcrypto.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ext_pgcrypto.py
Apache-2.0
async def test_edgeql_ext_pgcrypto_hmac(self): CASES = [ ("md5", "Mbbbnl60rdtC8abKBzZ63A=="), ("sha1", "hdFVxV7ShqMAvRzxJN4I2H6RTzo="), ("sha224", "1/UIN19LWxwjbS3xuFDeJHSpE2RIdnBeYr14zA=="), ("sha256", "FHkzIYqqvAuLEKKzpcNGhMjZQ0G88QpHNtxycPd0GFE="), ("sha384", "HZBw0Hy3dG4GZMzMbOwfqZbcf0Y2iYKs+iCV7o1z/iW1" + "tuMieZAM2w/TcqNlTkHF"), ("sha512", "JCV9chBYKmXHMexVFZyBhMwkwCSJRT5YWH9x9EwjotYb" + "S3IVSonRey1JRIqEUuoGb0/FaivOrUXA\niFcv/M2z2A=="), ] for hash_type, result in CASES: with self.subTest(hash_type): await self.assert_query_result( """ select ext::pgcrypto::hmac( <str>$data, <str>$key, <str>$type) """, [result], variables={ "data": "foo", "key": "bar", "type": hash_type, }, json_only=True, ) await self.assert_query_result( """ select ext::pgcrypto::hmac( <bytes>$data, <bytes>$key, <str>$type) """, [result], variables={ "data": b"foo", "key": b"bar", "type": hash_type, }, json_only=True, )
select ext::pgcrypto::hmac( <str>$data, <str>$key, <str>$type) """, [result], variables={ "data": "foo", "key": "bar", "type": hash_type, }, json_only=True, ) await self.assert_query_result(
test_edgeql_ext_pgcrypto_hmac
python
geldata/gel
tests/test_edgeql_ext_pgcrypto.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ext_pgcrypto.py
Apache-2.0
async def test_edgeql_ext_pgcrypto_gen_salt(self): CASES = [ ("bf", 5), ("xdes", 801), ("md5", None), ("des", None), ] await self.assert_query_result( """ select { salt := ext::pgcrypto::gen_salt() } """, [{}], json_only=True, ) for hash_type, iter_count in CASES: with self.subTest(hash_type): await self.assert_query_result( """ select { salt := ext::pgcrypto::gen_salt(<str>$type) } """, [{}], variables={ "type": hash_type, }, json_only=True, ) if iter_count is not None: await self.assert_query_result( """ select { salt := ext::pgcrypto::gen_salt( <str>$type, <int64>$iter_count, ) } """, [{}], variables={ "type": hash_type, "iter_count": iter_count, }, json_only=True, )
select { salt := ext::pgcrypto::gen_salt() } """, [{}], json_only=True, ) for hash_type, iter_count in CASES: with self.subTest(hash_type): await self.assert_query_result(
test_edgeql_ext_pgcrypto_gen_salt
python
geldata/gel
tests/test_edgeql_ext_pgcrypto.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_ext_pgcrypto.py
Apache-2.0
async def test_edgeql_links_set_01(self): await self.assert_query_result( r''' SELECT Item {name} FILTER 'plastic' IN .tag_set1 ORDER BY .name; ''', [ {'name': 'ball'}, {'name': 'floor lamp'}, ] ) await self.assert_query_result( r''' SELECT Item {name} FILTER 'plastic' IN .tag_set2 ORDER BY .name; ''', [ {'name': 'ball'}, {'name': 'floor lamp'}, {'name': 'tv'}, ] )
, [ {'name': 'ball'}, {'name': 'floor lamp'}, ] ) await self.assert_query_result( r
test_edgeql_links_set_01
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_edgeql_links_set_02(self): await self.assert_query_result( r''' SELECT Item {name} FILTER 'plastic' IN .tag_set1 ORDER BY .name; ''', [ {'name': 'ball'}, {'name': 'floor lamp'}, ] ) await self.assert_query_result( r''' SELECT Item {name} FILTER 'plastic' IN .tag_set2 ORDER BY .name; ''', [ {'name': 'ball'}, {'name': 'floor lamp'}, {'name': 'tv'}, ] )
, [ {'name': 'ball'}, {'name': 'floor lamp'}, ] ) await self.assert_query_result( r
test_edgeql_links_set_02
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_edgeql_links_set_03(self): await self.assert_query_result( r''' SELECT Item {name} FILTER array_agg(Item.tag_set1 ORDER BY Item.tag_set1) = ['rectangle', 'wood'] ORDER BY .name; ''', [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r''' SELECT Item {name} FILTER array_agg(Item.tag_set2 ORDER BY Item.tag_set2) = ['rectangle', 'wood'] ORDER BY .name; ''', [ {'name': 'table'}, ] )
, [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r
test_edgeql_links_set_03
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_edgeql_links_set_04(self): await self.assert_query_result( r''' SELECT Item {name} FILTER .tag_set1 = {'rectangle', 'wood'} ORDER BY .name; ''', [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r''' SELECT Item {name} FILTER .tag_set2 = {'rectangle', 'wood'} ORDER BY .name; ''', [ {'name': 'table'}, {'name': 'tv'}, ] )
, [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r
test_edgeql_links_set_04
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_edgeql_links_set_05(self): await self.assert_query_result( r''' # subsets # SELECT Item {name} FILTER .tag_set1 IN {'rectangle', 'wood'} ORDER BY .name; ''', [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r''' SELECT Item {name} FILTER .tag_set2 IN {'rectangle', 'wood'} ORDER BY .name; ''', [ {'name': 'table'}, {'name': 'tv'}, ] )
, [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r
test_edgeql_links_set_05
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_edgeql_links_set_07(self): await self.assert_query_result( r''' # subsets SELECT Item {name} FILTER count( ( # XXX: check test_edgeql_expr_alias for failures first SELECT _ := Item.tag_set1 FILTER _ IN {'rectangle', 'wood'} )) = 2 ORDER BY .name; ''', [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r''' SELECT Item {name} FILTER count( ( # XXX: check test_edgeql_expr_alias for failures first SELECT _ := Item.tag_set2 FILTER _ IN {'rectangle', 'wood'} )) = 2 ORDER BY .name; ''', [ {'name': 'table'}, ], )
, [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r
test_edgeql_links_set_07
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_edgeql_links_set_08(self): await self.assert_query_result( r''' # match sets WITH cmp := {'rectangle', 'wood'}, cmp_count := count(cmp) SELECT Item {name} FILTER cmp_count = count(Item.tag_set1) AND cmp_count = count(DISTINCT (Item.tag_set1 UNION cmp)) ORDER BY .name; ''', [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r''' WITH cmp := {'rectangle', 'wood'}, cmp_count := count(cmp) SELECT Item {name} FILTER cmp_count = count(.tag_set2) AND cmp_count = count(DISTINCT (.tag_set2 UNION cmp)) ORDER BY .name; ''', [ {'name': 'table'}, ], )
, [ {'name': 'chair'}, {'name': 'table'}, ] ) await self.assert_query_result( r
test_edgeql_links_set_08
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_edgeql_links_set_10(self): await self.assert_query_result( r''' # same as previous, but with a different syntax, leading # to a different failure scenario WITH cmp := {'rectangle', 'wood'}, cmp_count := count(cmp) # includes tag_set1 in the shape SELECT Item {name, tag_set1} FILTER cmp_count = count(Item.tag_set1) AND cmp_count = count(DISTINCT (Item.tag_set1 UNION cmp)) ORDER BY .name; ''', [ {'name': 'chair', 'tag_set1': {'rectangle', 'wood'}}, {'name': 'table', 'tag_set1': {'rectangle', 'wood'}}, ] ) await self.assert_query_result( r''' WITH cmp := {'rectangle', 'wood'}, cmp_count := count(cmp) # includes tag_set1 in the shape SELECT Item {name, tag_set2} FILTER cmp_count = count(Item.tag_set2) AND cmp_count = count(DISTINCT (Item.tag_set2 UNION cmp)) ORDER BY .name; ''', [ {'name': 'table', 'tag_set2': {'rectangle', 'wood'}}, ], )
, [ {'name': 'chair', 'tag_set1': {'rectangle', 'wood'}}, {'name': 'table', 'tag_set1': {'rectangle', 'wood'}}, ] ) await self.assert_query_result( r
test_edgeql_links_set_10
python
geldata/gel
tests/test_edgeql_linkatoms.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_linkatoms.py
Apache-2.0
async def test_constraints_exclusive_across_ancestry(self): async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): await self.con.execute(""" INSERT UniqueName { name := 'exclusive_name_across' }; INSERT UniqueNameInherited { name := 'exclusive_name_across' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): await self.con.execute(""" INSERT UniqueNameInherited { name := 'exclusive_name_across' }; INSERT UniqueName { name := 'exclusive_name_across' }; """) async with self._run_and_rollback(): await self.con.execute(""" INSERT UniqueName { name := 'exclusive_name_ok' }; INSERT UniqueNameInherited { name := 'exclusive_name_inherited_ok' }; """) with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): await self.con.execute(""" UPDATE UniqueNameInherited FILTER UniqueNameInherited.name = 'exclusive_name_inherited_ok' SET { name := 'exclusive_name_ok' }; """)
) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): await self.con.execute(
test_constraints_exclusive_across_ancestry
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_exclusive_delegation(self): async with self._run_and_rollback(): # This is OK, the name exclusivity constraint is delegating await self.con.execute(""" INSERT AbstractConstraintParent { name := 'exclusive_name_ap' }; INSERT AbstractConstraintParent { name := 'exclusive_name_ap' }; """) # This is OK too await self.con.execute(""" INSERT AbstractConstraintParent { name := 'exclusive_name_ap1' }; INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap1' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Not OK, abstract constraint materializes into a real one await self.con.execute(""" INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap2' }; INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap2' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Not OK, abstract constraint materializes into a real one await self.con.execute(""" INSERT AbstractConstraintMixedChild { name := 'exclusive_name_ap2' }; INSERT AbstractConstraintMixedChild { name := 'exclusive_name_AP2' }; """) async with self._run_and_rollback(): # This is OK, duplication is in different children await self.con.execute(""" INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap3' }; INSERT AbstractConstraintMixedChild { name := 'exclusive_name_ap3' }; """) # This is OK, the name exclusivity constraint is abstract again await self.con.execute(""" INSERT AbstractConstraintPropagated { name := 'exclusive_name_ap4' }; INSERT AbstractConstraintPropagated { name := 'exclusive_name_ap4' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Not OK, yet await self.con.execute(""" INSERT BecomingAbstractConstraint { name := 'exclusive_name_ap5' }; INSERT BecomingAbstractConstraintChild { name := 'exclusive_name_ap5' }; """) async with self._run_and_rollback(): await self.con.execute(""" INSERT BecomingConcreteConstraint { name := 'exclusive_name_ap6' }; INSERT BecomingConcreteConstraintChild { name := 'exclusive_name_ap6' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): await self.con.execute(""" INSERT LosingAbstractConstraintParent { name := 'exclusive_name_ap7' }; INSERT LosingAbstractConstraintParent { name := 'exclusive_name_ap7' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): await self.con.execute(""" INSERT AbstractConstraintMultipleParentsFlattening{ name := 'exclusive_name_ap8' }; INSERT AbstractConstraintMultipleParentsFlattening{ name := 'exclusive_name_ap8' }; """)
) # This is OK too await self.con.execute(
test_constraints_exclusive_delegation
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_exclusive_multi_property_distinct(self): await self.con.execute(""" INSERT PropertyContainer { tags := {"one", "two"} }; """) # Update to same values should be fine await self.con.execute(""" UPDATE PropertyContainer SET { tags := {"one", "two"} }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "tags violates exclusivity constraint", ): await self.con.execute(""" INSERT PropertyContainer { tags := {"one", "three"} }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "tags violates exclusivity constraint", ): await self.con.execute(""" INSERT PropertyContainer { tags := {"four", "four"} }; """) await self.con.execute(""" UPDATE PropertyContainer SET { tags := "one" }; """)
) # Update to same values should be fine await self.con.execute(
test_constraints_exclusive_multi_property_distinct
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_objects(self): async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, "ObjCnstr violates exclusivity constraint"): await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "bar" }; INSERT ObjCnstr { first_name := "foo", last_name := "baz" } """) async with self._run_and_rollback(): await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "bar", label := (INSERT Label {text := "obj_test" }) }; """) with self.assertRaisesRegex( edgedb.ConstraintViolationError, "ObjCnstr violates exclusivity constraint"): await self.con.execute(""" INSERT ObjCnstr { first_name := "emarg", last_name := "hatch", label := (SELECT Label FILTER .text = "obj_test" LIMIT 1) }; """)
) async with self._run_and_rollback(): await self.con.execute(
test_constraints_objects
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_endpoint_constraint_01(self): # testing (@source, @lang) on a single link # This constraint is pointless and can never fail await self.con.execute(""" insert UniqueName { translated_label := ((insert Label) { @lang := 'xxx' }) }; """) await self.con.execute(""" insert UniqueName { translated_label := ((insert Label) { @lang := 'xxx' }) }; """) await self.con.execute(""" insert UniqueName { translated_label := ((select Label limit 1) { @lang := 'yyy' }) }; """) await self.con.execute(""" insert UniqueName { translated_label := ((select Label limit 1) { @lang := 'xxx' }) }; """)
) await self.con.execute(
test_constraints_endpoint_constraint_01
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_endpoint_constraint_02(self): # testing (@source, @lang) on a multi link await self.con.execute(""" insert UniqueName { translated_labels := ((insert Label { text := "x" }) { @lang := 'x' }) }; """) await self.con.execute(""" update UniqueName set { translated_labels := Label {@lang := 'x' } }; """) # Should be fine await self.con.execute(""" insert UniqueName { translated_labels := ((insert Label { text := "y" }) { @lang := 'x' }) }; """) await self.con.execute(""" insert UniqueName { translated_labels := (Label { @lang := .text }) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" insert UniqueName { translated_labels := (Label { @lang := 'x' }) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" insert UniqueNameInherited { translated_labels := (Label { @lang := 'x' }) }; """)
) await self.con.execute(
test_constraints_endpoint_constraint_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_endpoint_constraint_03(self): # testing (@target, @lang) on a single link await self.con.execute(""" insert UniqueName { translated_label_tgt := ((insert Label { text := "x" }) { @lang := 'x' }) }; """) # Same @lang different @target await self.con.execute(""" insert UniqueName { translated_label_tgt := ((insert Label { text := "y" }) { @lang := 'x' }) }; """) # Same @target different @lang await self.con.execute(""" insert UniqueNameInherited { translated_label_tgt := ( select Label { @lang := 'y' } filter .text = 'x' limit 1) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" insert UniqueName { translated_label_tgt := ( select Label { @lang := 'x' } filter .text = 'x' limit 1) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" insert UniqueNameInherited { translated_label_tgt := ( select Label { @lang := 'x' } filter .text = 'x' limit 1) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" update UniqueName filter .translated_label_tgt.text = 'x' set { translated_label_tgt := .translated_label_tgt { @lang := '!' } } """) await self.con.execute(""" update UniqueName filter .translated_label_tgt.text = 'x' set { translated_label_tgt := .translated_label_tgt { @lang := @lang } } """)
) # Same @lang different @target await self.con.execute(
test_constraints_endpoint_constraint_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_endpoint_constraint_04(self): # testing (@target, @lang) on a multi link await self.con.execute(""" insert UniqueName { translated_labels_tgt := ((insert Label { text := "x" }) { @lang := 'x' }) }; """) # Same @lang different @target await self.con.execute(""" insert UniqueName { translated_labels_tgt := ((insert Label { text := "y" }) { @lang := 'x' }) }; """) # Same @target different @lang await self.con.execute(""" insert UniqueName { translated_labels_tgt := ( select Label { @lang := 'y' } filter .text = 'x') }; """) await self.con.execute(""" insert UniqueNameInherited { translated_labels_tgt := ( select Label { @lang := 'x!' }) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" insert UniqueName { translated_labels_tgt := ( select Label { @lang := 'x' } filter .text = 'x') }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" insert UniqueNameInherited { translated_labels_tgt := ( select Label { @lang := 'x' } filter .text = 'x') }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" insert UniqueNameInherited { translated_labels_tgt := ( select Label { @lang := .text ++ '!' } filter .text = 'x') }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'violates exclusivity constraint' ): await self.con.execute(""" update UniqueName filter 'x' in .translated_labels_tgt.text set { translated_labels_tgt := .translated_labels_tgt { @lang := '!' } } """) await self.con.execute(""" update UniqueName filter 'x' in .translated_labels_tgt.text set { translated_labels_tgt := .translated_labels_tgt { @lang := @lang } } """)
) # Same @lang different @target await self.con.execute(
test_constraints_endpoint_constraint_04
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_exclusive_migration(self): new_schema_f = os.path.join(os.path.dirname(__file__), 'schemas', 'constraints_migration', 'updated_schema.esdl') with open(new_schema_f) as f: new_schema = f.read() await self.migrate(new_schema) async with self._run_and_rollback(): # This is OK, the name exclusivity constraint is abstract await self.con.execute(""" INSERT AbstractConstraintParent { name := 'exclusive_name_ap' }; INSERT AbstractConstraintParent { name := 'exclusive_name_ap' }; """) # This is OK too await self.con.execute(""" INSERT AbstractConstraintParent { name := 'exclusive_name_ap1' }; INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap1' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Not OK, abstract constraint materializes into a real one await self.con.execute(""" INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap2' }; INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap2' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Not OK, abstract constraint materializes into a real one await self.con.execute(""" INSERT AbstractConstraintMixedChild { name := 'exclusive_name_ap2' }; INSERT AbstractConstraintMixedChild { name := 'exclusive_name_AP2' }; """) async with self._run_and_rollback(): # This is OK, duplication is in different children await self.con.execute(""" INSERT AbstractConstraintMixedChild { name := 'exclusive_name_ap3' }; INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap3' }; """) async with self._run_and_rollback(): # This is OK, the name exclusivity constraint is abstract again await self.con.execute(""" INSERT AbstractConstraintPropagated { name := 'exclusive_name_ap4' }; INSERT AbstractConstraintPropagated { name := 'exclusive_name_ap4' }; """) async with self._run_and_rollback(): # OK, former constraint was turned into an abstract constraint await self.con.execute(""" INSERT BecomingAbstractConstraint { name := 'exclusive_name_ap5' }; INSERT BecomingAbstractConstraintChild { name := 'exclusive_name_ap5' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Constraint is no longer abstract await self.con.execute(""" INSERT BecomingConcreteConstraint { name := 'exclusive_name_ap6' }; INSERT BecomingConcreteConstraintChild { name := 'exclusive_name_ap6' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Constraint is no longer abstract await self.con.execute(""" INSERT LosingAbstractConstraintParent { name := 'exclusive_name_ap6' }; INSERT LosingAbstractConstraintParent { name := 'exclusive_name_ap6' }; """) async with self._run_and_rollback(): await self.con.execute(""" INSERT LosingAbstractConstraintParent2 { name := 'exclusive_name_ap7' }; INSERT LosingAbstractConstraintParent2 { name := 'exclusive_name_ap7' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, 'name violates exclusivity constraint'): # Constraint is no longer abstract await self.con.execute(""" INSERT AbstractConstraintMultipleParentsFlattening{ name := 'exclusive_name_ap8' }; INSERT AbstractConstraintMultipleParentsFlattening{ name := 'exclusive_name_AP8' }; """) async with self._run_and_rollback(): with self.assertRaisesRegex( edgedb.ConstraintViolationError, "nope!"): await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "bar" }; INSERT ObjCnstr { first_name := "foo", last_name := "baz" } """)
) # This is OK too await self.con.execute(
test_constraints_exclusive_migration
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_01(self): qry = """ CREATE ABSTRACT LINK translated_label { CREATE PROPERTY lang -> std::str; CREATE PROPERTY prop1 -> std::str; }; CREATE ABSTRACT LINK link_with_exclusive_property { CREATE PROPERTY exclusive_property -> std::str { CREATE CONSTRAINT std::exclusive; }; }; CREATE ABSTRACT LINK link_with_exclusive_property_inherited EXTENDING link_with_exclusive_property; CREATE TYPE UniqueName { CREATE PROPERTY name -> std::str { CREATE CONSTRAINT std::exclusive; }; CREATE LINK link_with_exclusive_property -> std::Object; }; """ await self.con.execute(qry) # Simple exclusivity constraint on a link async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'name violates exclusivity constraint', ): await self.con.execute(""" INSERT UniqueName { name := 'Test' }; INSERT UniqueName { name := 'Test' }; """) qry = """ CREATE TYPE AbstractConstraintParent { CREATE PROPERTY name -> std::str { CREATE DELEGATED CONSTRAINT std::exclusive; }; }; CREATE TYPE AbstractConstraintPureChild EXTENDING AbstractConstraintParent; """ await self.con.execute(qry) # This is OK, the name exclusivity constraint is abstract await self.con.execute(""" INSERT AbstractConstraintParent { name := 'exclusive_name_ap' }; INSERT AbstractConstraintParent { name := 'exclusive_name_ap' }; """) # This is OK too await self.con.execute(""" INSERT AbstractConstraintParent { name := 'exclusive_name_ap1' }; INSERT AbstractConstraintPureChild { name := 'exclusive_name_ap1' }; """)
await self.con.execute(qry) # Simple exclusivity constraint on a link async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'name violates exclusivity constraint', ): await self.con.execute(
test_constraints_ddl_01
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_02(self): # testing the generalized constraint with 'ON (...)' clause qry = r""" CREATE ABSTRACT CONSTRAINT mymax1(max: std::int64) ON (len(__subject__)) { SET errmessage := '\(__subject__) must be no longer than \(max) characters.'; USING (__subject__ <= max); }; CREATE ABSTRACT CONSTRAINT mymax_ext1(max: std::int64) ON (len(__subject__)) EXTENDING std::max_value { SET errmessage := '\(__subject__) must be no longer than \(max) characters.'; }; CREATE TYPE ConstraintOnTest1 { CREATE PROPERTY foo -> std::str { CREATE CONSTRAINT mymax1(3); }; CREATE PROPERTY bar -> std::str { CREATE CONSTRAINT mymax_ext1(3); }; }; """ await self.con.execute(qry) await self.assert_query_result( r''' SELECT schema::Constraint { name, params: { num, name, kind, type: { name }, typemod, @value } FILTER .num > 0 ORDER BY .num ASC } FILTER .name = 'default::mymax_ext1' AND exists(.subject); ''', [ { "name": 'default::mymax_ext1', "params": [ { "num": 1, "kind": 'PositionalParam', "name": 'max', "type": {"name": 'std::int64'}, "@value": '3', "typemod": 'SingletonType' } ], }, ] ) await self.assert_query_result( r''' SELECT schema::Constraint { name, params: { num, name, kind, type: { name }, typemod } FILTER .num > 0 ORDER BY .num ASC } FILTER .name = 'default::mymax_ext1' AND NOT exists(.subject); ''', [ { "name": 'default::mymax_ext1', "params": [ { "num": 1, "kind": 'PositionalParam', "name": 'max', "type": {"name": 'std::int64'}, "typemod": 'SingletonType' } ], }, ] ) # making sure the constraint was applied successfully async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'foo must be no longer than 3 characters.', ): await self.con.execute(""" INSERT ConstraintOnTest1 { foo := 'Test' }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'bar must be no longer than 3 characters.', ): await self.con.execute(""" INSERT ConstraintOnTest1 { bar := 'Test' }; """) # constraint should not fail await self.con.execute(""" INSERT ConstraintOnTest1 { foo := '', bar := '' }; INSERT ConstraintOnTest1 { foo := 'a', bar := 'q' }; INSERT ConstraintOnTest1 { foo := 'ab', bar := 'qw' }; INSERT ConstraintOnTest1 { foo := 'abc', bar := 'qwe' }; # a duplicate 'foo' and 'bar' just for good measure INSERT ConstraintOnTest1 { foo := 'ab', bar := 'qw' }; """)
await self.con.execute(qry) await self.assert_query_result( r
test_constraints_ddl_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_03(self): # testing the specialized constraint with 'ON (...)' clause qry = r""" CREATE ABSTRACT CONSTRAINT mymax2(max: std::int64) { SET errmessage := '{__subject__} must be no longer than {max} characters.'; USING (__subject__ <= max); }; CREATE TYPE ConstraintOnTest2 { CREATE PROPERTY foo -> std::str { CREATE CONSTRAINT mymax2(3) ON (len(__subject__)); }; CREATE PROPERTY bar -> std::str { CREATE CONSTRAINT std::max_value(3) ON (len(__subject__)) { SET errmessage := # XXX: once simple string concat is possible here # formatting can be saner '{__subject__} must be no longer than {max} characters.'; }; }; }; """ await self.con.execute(qry) # making sure the constraint was applied successfully async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'foo must be no longer than 3 characters.', ): await self.con.execute(""" INSERT ConstraintOnTest2 { foo := 'Test' }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'bar must be no longer than 3 characters.', ): await self.con.execute(""" INSERT ConstraintOnTest2 { bar := 'Test' }; """) # constraint should not fail await self.con.execute(""" INSERT ConstraintOnTest2 { foo := '', bar := '' }; INSERT ConstraintOnTest2 { foo := 'a', bar := 'q' }; INSERT ConstraintOnTest2 { foo := 'ab', bar := 'qw' }; INSERT ConstraintOnTest2 { foo := 'abc', bar := 'qwe' }; # a duplicate 'foo' and 'bar' just for good measure INSERT ConstraintOnTest2 { foo := 'ab', bar := 'qw' }; """)
await self.con.execute(qry) # making sure the constraint was applied successfully async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'foo must be no longer than 3 characters.', ): await self.con.execute(
test_constraints_ddl_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_04(self): # testing an issue with expressions used for 'errmessage' qry = r""" CREATE ABSTRACT CONSTRAINT mymax3(max: std::int64) { SET errmessage := 'My custom ' ++ 'message.'; USING (__subject__ <= max); }; CREATE TYPE ConstraintOnTest3 { CREATE PROPERTY foo -> std::str { CREATE CONSTRAINT mymax3(3) ON (len(__subject__)); }; }; """ await self.con.execute(qry) # making sure the constraint was applied successfully async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'My custom message.', _details="violated constraint 'default::mymax3' on " "property 'foo' of " "object type 'default::ConstraintOnTest3'", ): await self.con.execute( """ INSERT ConstraintOnTest3 { foo := 'Test' }; """ ) # testing interpolation await self.con.execute(r""" CREATE type ConstraintOnTest4_2 { CREATE required property email -> str { CREATE constraint min_len_value(4) { SET errmessage := '{"json": "{nope} {{min}} {min}"}'; }; }; }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, '{"json": "{nope} {min} 4"}', _details="violated constraint 'std::min_len_value' on " "property 'email' of " "object type 'default::ConstraintOnTest4_2'", ): await self.con.execute( """ INSERT ConstraintOnTest4_2 { email := '' }; """ ) await self.con.execute(r""" CREATE type ConstraintOnTest4_3 { CREATE required property email -> str { CREATE constraint min_len_value(4) { SET errmessage := '\\(min) \\(min)'; }; }; }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, re.escape(r'\(min) \(min)'), ): await self.con.execute( """ INSERT ConstraintOnTest4_3 { email := '' }; """ )
await self.con.execute(qry) # making sure the constraint was applied successfully async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'My custom message.', _details="violated constraint 'default::mymax3' on " "property 'foo' of " "object type 'default::ConstraintOnTest3'", ): await self.con.execute(
test_constraints_ddl_04
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_05(self): # Test that constraint expression returns a boolean. await self.con.execute(r""" CREATE FUNCTION con05(a: int64) -> str USING EdgeQL $$ SELECT <str>a $$; """) # create a type with a constraint await self.con.execute(r""" CREATE TYPE ConstraintOnTest5 { CREATE REQUIRED PROPERTY foo -> int64 { # Use the function in a constraint expression, # s.t. it will effectively fail for any int # outside 0-9 range. CREATE CONSTRAINT std::expression on (len(con05(__subject__)) < 2); } } """) async with self.assertRaisesRegexTx( edgedb.errors.ConstraintViolationError, r'invalid foo', ): await self.con.execute(""" INSERT ConstraintOnTest5 { foo := 42 }; """) # constraint should not fail await self.con.execute(""" INSERT ConstraintOnTest5 { foo := 2 }; """)
) # create a type with a constraint await self.con.execute(r
test_constraints_ddl_05
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_06(self): # Test that constraint expression returns a boolean. await self.con.execute(r""" CREATE FUNCTION con06(a: int64) -> array<int64> USING EdgeQL $$ SELECT [a] $$; """) # create a type with a constraint await self.con.execute(r""" CREATE TYPE ConstraintOnTest6 { CREATE REQUIRED PROPERTY foo -> int64 { # Use the function in a constraint expression, # s.t. it will never fail. CREATE CONSTRAINT std::expression on (len(con06(__subject__)) < 2); } } """) # constraint should not fail await self.con.execute(""" INSERT ConstraintOnTest6 { foo := 42 }; """) await self.con.execute(""" INSERT ConstraintOnTest6 { foo := 2 }; """)
) # create a type with a constraint await self.con.execute(r
test_constraints_ddl_06
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_07(self): await self.con.execute(""" CREATE TYPE ObjCnstr { CREATE PROPERTY first_name -> str; CREATE PROPERTY last_name -> str; CREATE CONSTRAINT exclusive on (__subject__.first_name); }; """) await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "bar" } """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "ObjCnstr violates exclusivity constraint", ): await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "baz" } """) await self.con.execute(""" ALTER TYPE ObjCnstr { DROP CONSTRAINT exclusive on (__subject__.first_name); } """) await self.con.execute(""" ALTER TYPE ObjCnstr { CREATE CONSTRAINT exclusive on ((__subject__.first_name, __subject__.last_name)); } """) await self.con.execute(""" ALTER TYPE ObjCnstr { ALTER CONSTRAINT exclusive on ((__subject__.first_name, __subject__.last_name)) { SET errmessage := "nope!"; } } """) # This one should work now await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "baz" } """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "nope!", ): await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "bar" } """)
) await self.con.execute(
test_constraints_ddl_07
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_08(self): await self.con.execute(""" CREATE TYPE ObjCnstr2 { CREATE MULTI PROPERTY first_name -> str; CREATE MULTI PROPERTY last_name -> str; CREATE LINK foo -> Object { CREATE PROPERTY p -> str; }; CREATE CONSTRAINT exclusive on (__subject__.first_name); }; """) async with self.assertRaisesRegexTx( edgedb.InvalidConstraintDefinitionError, "cannot reference multiple links or properties in a " "constraint where at least one link or property is MULTI", ): await self.con.execute(""" ALTER TYPE ObjCnstr2 { CREATE CONSTRAINT exclusive on ((__subject__.first_name, __subject__.last_name)); }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::EXISTS' " "in a constraint", ): await self.con.execute(""" ALTER TYPE ObjCnstr2 { CREATE CONSTRAINT expression on (EXISTS .first_name); }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::EXISTS' " "in a constraint", ): await self.con.execute(""" ALTER TYPE ObjCnstr2 { ALTER PROPERTY first_name { CREATE CONSTRAINT expression on (EXISTS __subject__); } }; """) async with self.assertRaisesRegexTx( edgedb.InvalidConstraintDefinitionError, "constraints cannot contain paths with more than one hop", ): await self.con.execute(""" ALTER TYPE ObjCnstr2 { CREATE CONSTRAINT expression on (<str>.foo.id != 'lol'); }; """) async with self.assertRaisesRegexTx( edgedb.InvalidConstraintDefinitionError, "link constraints may not access the link target", ): await self.con.execute(""" ALTER TYPE ObjCnstr2 { ALTER LINK foo { CREATE CONSTRAINT expression on ( <str>__subject__.id != 'lol'); } }; """) async with self.assertRaisesRegexTx( edgedb.InvalidConstraintDefinitionError, "constraint expressions must be immutable", ): await self.con.execute(""" ALTER TYPE ObjCnstr2 { CREATE CONSTRAINT expression on (<str>.id != .foo@p); }; """)
) async with self.assertRaisesRegexTx( edgedb.InvalidConstraintDefinitionError, "cannot reference multiple links or properties in a " "constraint where at least one link or property is MULTI", ): await self.con.execute(
test_constraints_ddl_08
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_09(self): await self.con.execute(""" CREATE TYPE Label { CREATE PROPERTY text -> str; }; CREATE TYPE ObjCnstr3 { CREATE LINK label -> Label; CREATE CONSTRAINT exclusive on (__subject__.label); }; INSERT ObjCnstr3 { label := (INSERT Label {text := "obj_test" }) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "ObjCnstr3 violates exclusivity constraint", ): await self.con.execute(""" INSERT ObjCnstr3 { label := (SELECT Label FILTER .text = "obj_test" LIMIT 1) }; """)
) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "ObjCnstr3 violates exclusivity constraint", ): await self.con.execute(
test_constraints_ddl_09
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_10(self): await self.con.execute(r""" CREATE ABSTRACT CONSTRAINT mymax5(max: std::int64) { USING (__subject__ <= max); }; CREATE TYPE ConstraintTest10 { CREATE PROPERTY foo -> std::int64 { CREATE CONSTRAINT mymax5(3); }; }; """) await self.con.execute(r""" ALTER ABSTRACT CONSTRAINT mymax5 RENAME TO mymax6; """) async with self._run_and_rollback(): with self.assertRaises(edgedb.ConstraintViolationError): await self.con.execute(r""" INSERT ConstraintTest10 { foo := 4 } """) await self.con.execute(r""" CREATE MODULE foo IF NOT EXISTS; ALTER ABSTRACT CONSTRAINT mymax6 RENAME TO foo::mymax2; """) await self.con.execute(r""" ALTER TYPE ConstraintTest10 { ALTER PROPERTY foo { DROP CONSTRAINT foo::mymax2(3); } } """) await self.con.execute(r""" DROP ABSTRACT CONSTRAINT foo::mymax2; """)
) await self.con.execute(r
test_constraints_ddl_10
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_11(self): qry = r""" CREATE ABSTRACT CONSTRAINT mymax7(max: std::int64) { USING (__subject__ <= max); }; """ # Check that renaming and then recreating works await self.con.execute(qry) await self.con.execute(""" ALTER ABSTRACT CONSTRAINT mymax7 RENAME TO mymax8; """) await self.con.execute(qry)
# Check that renaming and then recreating works await self.con.execute(qry) await self.con.execute(
test_constraints_ddl_11
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_12(self): qry = r""" CREATE ABSTRACT CONSTRAINT mymax9(max: std::int64) { USING (__subject__ <= max); }; """ # Check that deleting and then recreating works await self.con.execute(qry) await self.con.execute(""" DROP ABSTRACT CONSTRAINT mymax9; """) await self.con.execute(qry)
# Check that deleting and then recreating works await self.con.execute(qry) await self.con.execute(
test_constraints_ddl_12
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_13(self): await self.con.execute(r""" CREATE ABSTRACT CONSTRAINT mymax13(max: std::int64) { USING (__subject__ <= max); }; CREATE TYPE ConstraintTest13 { CREATE PROPERTY foo -> std::int64 { CREATE CONSTRAINT mymax13(3); }; }; """) await self.con.execute(r""" ALTER ABSTRACT CONSTRAINT mymax13 RENAME TO mymax13b; """) res = await self.con.query_single(""" DESCRIBE MODULE default """) self.assertEqual(res.count("mymax13b"), 2)
) await self.con.execute(r
test_constraints_ddl_13
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_14(self): await self.con.execute(r""" CREATE ABSTRACT CONSTRAINT mymax14(max: std::int64) { USING (__subject__ <= max); }; CREATE TYPE ConstraintTest14 { CREATE PROPERTY foo -> std::int64 { CREATE CONSTRAINT mymax14(3); }; }; """) await self.con.execute(r""" ALTER TYPE ConstraintTest14 { ALTER PROPERTY foo { DROP CONSTRAINT mymax14(3); } } """) await self.con.execute(r""" ALTER TYPE ConstraintTest14 { ALTER PROPERTY foo { CREATE CONSTRAINT mymax14(5); } } """)
) await self.con.execute(r
test_constraints_ddl_14
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_15(self): await self.con.execute(r""" CREATE ABSTRACT CONSTRAINT not_bad { USING (__subject__ != "bad" and __subject__ != "terrible") }; """) await self.con.execute(r""" CREATE TYPE Foo { CREATE PROPERTY foo -> str { CREATE CONSTRAINT not_bad; } }; """) await self.con.execute(r""" ALTER ABSTRACT CONSTRAINT not_bad { USING (__subject__ != "bad" and __subject__ != "terrible" and __subject__ != "awful") }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "invalid foo", ): await self.con.execute(r""" INSERT Foo { foo := "awful" }; """) await self.con.execute(r""" INSERT Foo { foo := "scow" }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "invalid foo", ): await self.con.execute(r""" ALTER ABSTRACT CONSTRAINT not_bad { USING (__subject__ != "bad" and __subject__ != "terrible" and __subject__ != "scow") }; """)
) await self.con.execute(r
test_constraints_ddl_15
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_16(self): await self.con.execute(""" CREATE TYPE ObjCnstr { CREATE PROPERTY first_name -> str; CREATE PROPERTY last_name -> str; CREATE CONSTRAINT exclusive ON ( (.first_name ?? "N/A", .last_name ?? "N/A") ); }; """) await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "bar" } """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "ObjCnstr violates exclusivity constraint", ): await self.con.execute(""" INSERT ObjCnstr { first_name := "foo", last_name := "bar" } """) await self.con.execute(""" INSERT ObjCnstr { first_name := "test" } """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "ObjCnstr violates exclusivity constraint", ): await self.con.execute(""" INSERT ObjCnstr { first_name := "test" } """) await self.con.execute(""" INSERT ObjCnstr { last_name := "test" } """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "ObjCnstr violates exclusivity constraint", ): await self.con.execute(""" INSERT ObjCnstr { last_name := "test" } """)
) await self.con.execute(
test_constraints_ddl_16
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_ddl_error_05(self): # Test that constraint expression returns a boolean. schema = """ type User { required property login -> str { constraint expression on (len(__subject__)) } }; """ async with self.assertRaisesRegexTx( edgedb.SchemaDefinitionError, "constraint expression expected to return a bool value, " "got scalar type 'std::int64'", ): await self.migrate(schema) qry = """ CREATE TYPE User { CREATE REQUIRED PROPERTY login -> str { CREATE CONSTRAINT expression on (len(__subject__)); }; }; """ async with self.assertRaisesRegexTx( edgedb.SchemaDefinitionError, "constraint expression expected to return a bool value, " "got scalar type 'std::int64'", ): await self.con.execute(qry) qry = """ CREATE ABSTRACT CONSTRAINT foo { USING (__subject__); }; CREATE TYPE User { CREATE REQUIRED PROPERTY login -> str { CREATE CONSTRAINT foo; }; }; """ async with self.assertRaisesRegexTx( edgedb.SchemaDefinitionError, "constraint expression expected to return a bool value, " "got scalar type 'std::str'", ): await self.con.execute(qry) qry = """ CREATE SCALAR TYPE wrong extending str { CREATE CONSTRAINT exclusive; }; """ async with self.assertRaisesRegexTx( edgedb.SchemaDefinitionError, "abstract constraint 'std::exclusive' may not " "be used on scalar types", ): await self.con.execute(qry)
async with self.assertRaisesRegexTx( edgedb.SchemaDefinitionError, "constraint expression expected to return a bool value, " "got scalar type 'std::int64'", ): await self.migrate(schema) qry =
test_constraints_ddl_error_05
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_tuple(self): await self.con.execute(r""" CREATE TYPE Transaction { CREATE PROPERTY credit -> tuple<nest: tuple<amount: decimal, currency: str>> { CREATE CONSTRAINT max_value(0) ON (__subject__.nest.amount) }; }; """) await self.con.execute(r""" INSERT Transaction { credit := (nest := (amount := -1, currency := "usd")) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "Maximum allowed value for credit is 0.", ): await self.con.execute(r""" INSERT Transaction { credit := (nest := (amount := 1, currency := "usd")) }; """)
) await self.con.execute(r
test_constraints_tuple
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_partial_path(self): await self.con.execute('''\ CREATE TYPE Vector { CREATE PROPERTY x -> float64; CREATE PROPERTY y -> float64; CREATE CONSTRAINT expression ON ( .x^2 + .y^2 < 25 ); }; ''') await self.con.execute(r""" INSERT Vector { x := 3, y := 3 }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, 'invalid Vector', ): await self.con.execute(r""" INSERT Vector { x := 4, y := 4 }; """)
) await self.con.execute(r
test_constraints_partial_path
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_exclusive_link_prop_01(self): await self.con.execute(""" CREATE TYPE Tgt; CREATE TYPE Obj { CREATE LINK asdf -> Tgt { CREATE PROPERTY what -> str; CREATE CONSTRAINT exclusive ON ( __subject__@what ?? '??' ) } }; """) await self.con.execute(""" INSERT Tgt; INSERT Obj { asdf := assert_single((SELECT Tgt)) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "asdf violates exclusivity constraint", ): await self.con.execute(""" INSERT Obj { asdf := assert_single((SELECT Tgt)) }; """)
) await self.con.execute(
test_constraints_exclusive_link_prop_01
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_exclusive_link_prop_02(self): await self.con.execute(""" CREATE TYPE Tgt; CREATE TYPE Obj { CREATE LINK asdf -> Tgt { CREATE PROPERTY what -> str { CREATE CONSTRAINT exclusive ON (__subject__ ?? '??') } } }; """) await self.con.execute(""" INSERT Tgt; INSERT Obj { asdf := assert_single((SELECT Tgt)) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "what violates exclusivity constraint", ): await self.con.execute(""" INSERT Obj { asdf := assert_single((SELECT Tgt)) }; """)
) await self.con.execute(
test_constraints_exclusive_link_prop_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_exclusive_link_prop_03(self): await self.con.execute(""" CREATE TYPE Tgt; CREATE ABSTRACT LINK asdf { CREATE PROPERTY what -> str { CREATE CONSTRAINT exclusive ON (__subject__ ?? '??') } }; CREATE TYPE Obj { CREATE LINK asdf extending asdf -> Tgt; }; """) await self.con.execute(""" INSERT Tgt; INSERT Obj { asdf := assert_single((SELECT Tgt)) }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "what violates exclusivity constraint", ): await self.con.execute(""" INSERT Obj { asdf := assert_single((SELECT Tgt)) }; """)
) await self.con.execute(
test_constraints_exclusive_link_prop_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_non_strict_01(self): # Test constraints that use a function that is implemented # "non-strictly" (and so requires some special handling in the # compiler) await self.con.execute(""" create type X { create property a -> array<str>; create property b -> array<str>; create constraint expression on ( .a ++ .b != ["foo", "bar", "baz"]); }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "invalid X", ): await self.con.execute(""" insert X { a := ['foo'], b := ['bar', 'baz'] }; """) # These should succeed, though, because the LHS is just {} await self.con.execute(""" insert X { a := {}, b := ['foo', 'bar', 'baz'] }; """) await self.con.execute(""" insert X { a := ['foo', 'bar', 'baz'], b := {} }; """)
) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "invalid X", ): await self.con.execute(
test_constraints_non_strict_01
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_bad_args(self): async with self.assertRaisesRegexTx( edgedb.SchemaDefinitionError, "Expected 0 arguments, but found 1" ): await self.con.execute( """ create type X { create property a -> bool; create link parent -> X { create constraint expression (false); } }; """ )
create type X { create property a -> bool; create link parent -> X { create constraint expression (false); } };
test_constraints_bad_args
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_no_refs(self): await self.con.execute( """ create type X { create property name -> str { create constraint std::expression on (true); }; }; """ )
create type X { create property name -> str { create constraint std::expression on (true); }; };
test_constraints_no_refs
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_abstract_scalar(self): await self.con.execute( """ create abstract scalar type posint64 extending int64 { create constraint min_value(0); }; create scalar type limited_int64 extending posint64; create type X { create property y -> limited_int64; }; """ ) await self.con.execute("insert X { y := 1 }") async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "Minimum allowed value for" ): await self.con.execute("insert X { y := -1 }")
create abstract scalar type posint64 extending int64 { create constraint min_value(0); }; create scalar type limited_int64 extending posint64; create type X { create property y -> limited_int64; };
test_constraints_abstract_scalar
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_abstract_object_01(self): await self.con.execute( """ create abstract type ChatBase { create multi property messages: str { create constraint exclusive; }; }; create type Dialog extending ChatBase; create type Monolog extending ChatBase; insert Dialog; insert Monolog; """ ) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "messages violates exclusivity constraint" ): await self.con.execute(""" update ChatBase set { messages += 'hello world' }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "messages violates exclusivity constraint" ): await self.con.execute(""" analyze update ChatBase set { messages += 'hello world' }; """) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "messages violates exclusivity constraint" ): await self.con.execute(""" update ChatBase set { messages := 'hello world' }; """)
create abstract type ChatBase { create multi property messages: str { create constraint exclusive; }; }; create type Dialog extending ChatBase; create type Monolog extending ChatBase; insert Dialog; insert Monolog;
test_constraints_abstract_object_01
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_abstract_object_02(self): await self.con.execute( """ create abstract type ChatBase { create single property messages: str { create constraint exclusive; }; }; create type Dialog extending ChatBase; create type Monolog extending ChatBase; insert Dialog; insert Monolog; """ ) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "messages violates exclusivity constraint" ): await self.con.execute(""" update ChatBase set { messages := 'hello world' }; """)
create abstract type ChatBase { create single property messages: str { create constraint exclusive; }; }; create type Dialog extending ChatBase; create type Monolog extending ChatBase; insert Dialog; insert Monolog;
test_constraints_abstract_object_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_abstract_object_03(self): # Add one where the constraint comes from a different type # than the update await self.con.execute( """ create abstract type ChatBase { create single property messages: str { }; }; create abstract type ChatBase2 { create single property messages: str { create constraint exclusive; }; }; create type Dialog extending ChatBase, ChatBase2; create type Monolog extending ChatBase, ChatBase2; insert Dialog; insert Monolog; """ ) async with self.assertRaisesRegexTx( edgedb.ConstraintViolationError, "messages violates exclusivity constraint" ): await self.con.execute(""" update ChatBase set { messages := 'hello world' }; """)
create abstract type ChatBase { create single property messages: str { }; }; create abstract type ChatBase2 { create single property messages: str { create constraint exclusive; }; }; create type Dialog extending ChatBase, ChatBase2; create type Monolog extending ChatBase, ChatBase2; insert Dialog; insert Monolog;
test_constraints_abstract_object_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_singleton_set_ops_01(self): await self.con.execute( """ create type X { create property a -> int64 { create constraint expression on ( __subject__ in {1} ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::IN' " "in a constraint" ): await self.con.execute( """ create type Y { create multi property a -> int64 { create constraint expression on ( __subject__ in {1} ); } }; """)
create type X { create property a -> int64 { create constraint expression on ( __subject__ in {1} ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::IN' " "in a constraint" ): await self.con.execute(
test_constraints_singleton_set_ops_01
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_singleton_set_ops_02(self): await self.con.execute( """ create type X { create property a -> int64 { create constraint expression on ( __subject__ not in {1} ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::NOT IN' " "in a constraint" ): await self.con.execute( """ create type Y { create multi property a -> int64 { create constraint expression on ( __subject__ not in {1} ); } }; """)
create type X { create property a -> int64 { create constraint expression on ( __subject__ not in {1} ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::NOT IN' " "in a constraint" ): await self.con.execute(
test_constraints_singleton_set_ops_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_singleton_set_ops_03(self): await self.con.execute( """ create type X { create property a -> int64 { create constraint expression on ( exists(__subject__) ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::EXISTS' " "in a constraint" ): await self.con.execute( """ create type Y { create multi property a -> int64 { create constraint expression on ( exists(__subject__) ); } }; """)
create type X { create property a -> int64 { create constraint expression on ( exists(__subject__) ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::EXISTS' " "in a constraint" ): await self.con.execute(
test_constraints_singleton_set_ops_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_singleton_set_ops_04(self): await self.con.execute( """ create type X { create property a -> int64 { create constraint expression on ( __subject__ ?? 1 = 0 ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, r"cannot use SET OF operator 'std::\?\?' " r"in a constraint" ): await self.con.execute( """ create type Y { create multi property a -> int64 { create constraint expression on ( __subject__ ?? 1 = 0 ); } }; """)
create type X { create property a -> int64 { create constraint expression on ( __subject__ ?? 1 = 0 ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, r"cannot use SET OF operator 'std::\?\?' " r"in a constraint" ): await self.con.execute(
test_constraints_singleton_set_ops_04
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_singleton_set_ops_05(self): await self.con.execute( """ create type X { create property a -> tuple<bool, int64> { create constraint expression on ( __subject__.1 < 0 if __subject__.0 else __subject__.1 >= 0 ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::IF' " "in a constraint" ): await self.con.execute( """ create type Y { create multi property a -> tuple<bool, int64> { create constraint expression on ( __subject__.1 < 0 if __subject__.0 else __subject__.1 >= 0 ); } }; """)
create type X { create property a -> tuple<bool, int64> { create constraint expression on ( __subject__.1 < 0 if __subject__.0 else __subject__.1 >= 0 ); } }; """) async with self.assertRaisesRegexTx( edgedb.UnsupportedFeatureError, "cannot use SET OF operator 'std::IF' " "in a constraint" ): await self.con.execute(
test_constraints_singleton_set_ops_05
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_object_02(self): await self._apply_schema_inheritance_single_object() # Add base await self.con.execute(""" create type CCC { create required property name -> str; create constraint exclusive on (.name); }; create type DDD extending CCC; insert CCC {name := 'ccc'}; insert DDD {name := 'ddd'}; """) await self.con.execute(""" alter type XXX { extending CCC; } """) # Check constraints await self._check_constraint_inheritance([ [('AAA', 'name'), ('BBB', 'name'), ('XXX', 'name')], [('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name')], ])
) await self.con.execute(
test_constraints_inheritance_single_object_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_object_03(self): await self._apply_schema_inheritance_single_object() # Change base await self.con.execute(""" create type CCC { create required property name -> str; create constraint exclusive on (.name); }; create type DDD extending CCC; insert CCC {name := 'ccc'}; insert DDD {name := 'ddd'}; """) await self.con.execute(""" alter type XXX { drop extending AAA; extending CCC; } """) # Check constraints await self._check_constraint_inheritance([ [('AAA', 'name'), ('BBB', 'name')], [('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name')], ])
) await self.con.execute(
test_constraints_inheritance_single_object_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_object_02(self): await self._apply_schema_inheritance_mutli_object() # Add base await self.con.execute(""" create type EEE { create required property name -> str; create constraint exclusive on (.name); }; create type FFF extending EEE; insert EEE {name := 'eee'}; insert FFF {name := 'fff'}; """) await self.con.execute(""" alter type XXX { extending EEE; } """) # Check constraints await self._check_constraint_inheritance([ [('BBB', 'name'), ('XXX', 'name')], [('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name')], [('EEE', 'name'), ('FFF', 'name'), ('XXX', 'name')], ])
) await self.con.execute(
test_constraints_inheritance_multi_object_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_object_03(self): await self._apply_schema_inheritance_mutli_object() # Change base await self.con.execute(""" create type EEE { create required property name -> str; create constraint exclusive on (.name); }; create type FFF extending EEE; insert EEE {name := 'eee'}; insert FFF {name := 'fff'}; """) await self.con.execute(""" alter type XXX { drop extending AAA; extending EEE; } """) # Check constraints await self._check_constraint_inheritance([ [('BBB', 'name')], [('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name')], [('EEE', 'name'), ('FFF', 'name'), ('XXX', 'name')], ])
) await self.con.execute(
test_constraints_inheritance_multi_object_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_pointer_02(self): await self._apply_schema_inheritance_single_pointer() # Add base await self.con.execute(""" create type CCC { create required property name -> str { create constraint exclusive; }; }; create type DDD extending CCC; insert CCC {name := 'ccc'}; insert DDD {name := 'ddd'}; """) await self.con.execute(""" alter type XXX { extending CCC; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'name'), ('BBB', 'name'), ('XXX', 'name'), ], [ ('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_single_pointer_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_pointer_03(self): await self._apply_schema_inheritance_single_pointer() # Change base await self.con.execute(""" create type CCC { create required property name -> str { create constraint exclusive; }; }; create type DDD extending CCC; insert CCC {name := 'ccc'}; insert DDD {name := 'ddd'}; """) await self.con.execute(""" alter type XXX { drop extending AAA; extending CCC; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'name'), ('BBB', 'name'), ], [ ('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_single_pointer_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_pointer_02(self): await self._apply_schema_inheritance_multi_pointer() # Add base await self.con.execute(""" create type EEE { create required property name -> str { create constraint exclusive; }; }; create type FFF extending EEE; insert EEE {name := 'eee'}; insert FFF {name := 'fff'}; """) await self.con.execute(""" alter type XXX { extending EEE; } """) # Check constraints await self._check_constraint_inheritance([ [('AAA', 'name'), ('BBB', 'name'), ('XXX', 'name')], [('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name')], [('EEE', 'name'), ('FFF', 'name'), ('XXX', 'name')], ])
) await self.con.execute(
test_constraints_inheritance_multi_pointer_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_pointer_03(self): await self._apply_schema_inheritance_multi_pointer() # Change base await self.con.execute(""" create type EEE { create required property name -> str { create constraint exclusive; }; }; create type FFF extending EEE; insert EEE {name := 'eee'}; insert FFF {name := 'fff'}; """) await self.con.execute(""" alter type XXX { drop extending AAA; extending EEE; } """) # Check constraints await self._check_constraint_inheritance([ [('AAA', 'name'), ('BBB', 'name')], [('CCC', 'name'), ('DDD', 'name'), ('XXX', 'name')], [('EEE', 'name'), ('FFF', 'name'), ('XXX', 'name')], ])
) await self.con.execute(
test_constraints_inheritance_multi_pointer_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_abstract_link_02(self): await self._apply_schema_inheritance_single_abstract_link() # Add base await self.con.execute(""" create abstract link RRR { create property name -> str; create constraint exclusive on (@name); }; create abstract link SSS extending RRR; create type CCC { create required link tag extending RRR -> Tag; }; create type DDD { create required link tag extending SSS -> Tag; }; insert CCC {tag := (insert Tag){@name := 'ccc'}}; insert DDD {tag := (insert Tag){@name := 'ddd'}}; """) await self.con.execute(""" alter abstract link XXX { extending RRR; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_single_abstract_link_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_abstract_link_03(self): await self._apply_schema_inheritance_single_abstract_link() # Change base await self.con.execute(""" create abstract link RRR { create property name -> str; create constraint exclusive on (@name); }; create abstract link SSS extending RRR; create type CCC { create required link tag extending RRR -> Tag; }; create type DDD { create required link tag extending SSS -> Tag; }; insert CCC {tag := (insert Tag){@name := 'ccc'}}; insert DDD {tag := (insert Tag){@name := 'ddd'}}; """) await self.con.execute(""" alter abstract link XXX { extending RRR; drop extending PPP; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_single_abstract_link_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_abstract_link_02(self): await self._apply_schema_inheritance_multi_abstract_link() # Add base await self.con.execute(""" create abstract link TTT { create property name -> str; create constraint exclusive on (@name); }; create abstract link UUU extending TTT; create type EEE { create required link tag extending TTT -> Tag; }; create type FFF { create required link tag extending UUU -> Tag; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag := (insert Tag){@name := 'fff'}}; """) await self.con.execute(""" alter abstract link XXX { extending TTT; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_abstract_link_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_abstract_link_03(self): await self._apply_schema_inheritance_multi_abstract_link() # Change base await self.con.execute(""" create abstract link TTT { create property name -> str; create constraint exclusive on (@name); }; create abstract link UUU extending TTT; create type EEE { create required link tag extending TTT -> Tag; }; create type FFF { create required link tag extending UUU -> Tag; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag := (insert Tag){@name := 'fff'}}; """) await self.con.execute(""" alter abstract link XXX { extending TTT; drop extending PPP; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_abstract_link_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_mixed_link_02(self): await self._apply_schema_inheritance_multi_mixed_link() # Add base await self.con.execute(""" create abstract link RRR { create property name -> str; create constraint exclusive on (@name); }; create abstract link SSS extending RRR; create type EEE { create required link tag extending RRR -> Tag; }; create type FFF { create required link tag2 extending SSS -> Tag2; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag2 := (insert Tag2){@name := 'fff'}}; """) await self.con.execute(""" alter type XXX { extending EEE; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag2', 'Tag2', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], [ ('DDD', 'tag', 'Tag', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag2', 'Tag2', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_mixed_link_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_mixed_link_03(self): await self._apply_schema_inheritance_multi_mixed_link() # Change base await self.con.execute(""" create abstract link TTT { create property name -> str; create constraint exclusive on (@name); }; create abstract link UUU extending TTT; create type EEE { create required link tag extending TTT -> Tag; }; create type FFF { create required link tag2 extending UUU -> Tag2; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag2 := (insert Tag2){@name := 'fff'}}; """) await self.con.execute(""" alter type XXX { extending EEE; drop extending AAA; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag2', 'Tag2', 'name'), ], [ ('DDD', 'tag', 'Tag', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag2', 'Tag2', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_mixed_link_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_abstract_link_prop_02(self): await self._apply_schema_inheritance_single_abstract_link_prop() # Add base await self.con.execute(""" create abstract link RRR { create property name -> str { create constraint exclusive; }; }; create abstract link SSS extending RRR; create type CCC { create required link tag extending RRR -> Tag; }; create type DDD { create required link tag extending SSS -> Tag; }; insert CCC {tag := (insert Tag){@name := 'ccc'}}; insert DDD {tag := (insert Tag){@name := 'ddd'}}; """) await self.con.execute(""" alter abstract link XXX { extending RRR; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_single_abstract_link_prop_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_single_abstract_link_prop_03(self): await self._apply_schema_inheritance_single_abstract_link_prop() # Change base await self.con.execute(""" create abstract link RRR { create property name -> str { create constraint exclusive; }; }; create abstract link SSS extending RRR; create type CCC { create required link tag extending RRR -> Tag; }; create type DDD { create required link tag extending SSS -> Tag; }; insert CCC {tag := (insert Tag){@name := 'ccc'}}; insert DDD {tag := (insert Tag){@name := 'ddd'}}; """) await self.con.execute(""" alter abstract link XXX { extending RRR; drop extending PPP; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_single_abstract_link_prop_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_abstract_link_prop_02(self): await self._apply_schema_inheritance_multi_abstract_link_prop() # Add base await self.con.execute(""" create abstract link TTT { create property name -> str { create constraint exclusive; }; }; create abstract link UUU extending TTT; create type EEE { create required link tag extending TTT -> Tag; }; create type FFF { create required link tag extending UUU -> Tag; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag := (insert Tag){@name := 'fff'}}; """) await self.con.execute(""" alter abstract link XXX { extending TTT; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_abstract_link_prop_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_abstract_link_prop_03(self): await self._apply_schema_inheritance_multi_abstract_link_prop() # Change base await self.con.execute(""" create abstract link TTT { create property name -> str { create constraint exclusive; }; }; create abstract link UUU extending TTT; create type EEE { create required link tag extending TTT -> Tag; }; create type FFF { create required link tag extending UUU -> Tag; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag := (insert Tag){@name := 'fff'}}; """) await self.con.execute(""" alter abstract link XXX { extending TTT; drop extending PPP; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag', 'Tag', 'name'), ], [ ('CCC', 'tag', 'Tag', 'name'), ('DDD', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag', 'Tag', 'name'), ('YYY', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_abstract_link_prop_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_mixed_link_prop_02(self): await self._apply_schema_inheritance_multi_mixed_link_prop() # Add base await self.con.execute(""" create abstract link RRR { create property name -> str { create constraint exclusive; }; }; create abstract link SSS extending RRR; create type EEE { create required link tag extending RRR -> Tag; }; create type FFF { create required link tag2 extending SSS -> Tag2; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag2 := (insert Tag2){@name := 'fff'}}; """) await self.con.execute(""" alter type XXX { extending EEE; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag2', 'Tag2', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], [ ('DDD', 'tag', 'Tag', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag2', 'Tag2', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_mixed_link_prop_02
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def test_constraints_inheritance_multi_mixed_link_prop_03(self): await self._apply_schema_inheritance_multi_mixed_link_prop() # Change base await self.con.execute(""" create abstract link TTT { create property name -> str { create constraint exclusive; }; }; create abstract link UUU extending TTT; create type EEE { create required link tag extending TTT -> Tag; }; create type FFF { create required link tag2 extending UUU -> Tag2; }; insert EEE {tag := (insert Tag){@name := 'eee'}}; insert FFF {tag2 := (insert Tag2){@name := 'fff'}}; """) await self.con.execute(""" alter type XXX { extending EEE; drop extending AAA; } """) # Check constraints await self._check_constraint_inheritance([ [ ('AAA', 'tag', 'Tag', 'name'), ('BBB', 'tag2', 'Tag2', 'name'), ], [ ('DDD', 'tag', 'Tag', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], [ ('EEE', 'tag', 'Tag', 'name'), ('FFF', 'tag2', 'Tag2', 'name'), ('XXX', 'tag', 'Tag', 'name'), ], ])
) await self.con.execute(
test_constraints_inheritance_multi_mixed_link_prop_03
python
geldata/gel
tests/test_constraints.py
https://github.com/geldata/gel/blob/master/tests/test_constraints.py
Apache-2.0
async def fast_forward_describe_migration( self, *, limit: Optional[int] = None, user_input: Optional[Iterable[str]] = None, commit: bool = True, ): '''Repeatedly get the next step from DESCRIBE and execute it. The point of this as opposed to just using "POPULATE MIGRATION; COMMIT MIGRATION;" is that we want to make sure that the generated DDL is valid and in case it's not, narrow down which step is causing issues. ''' # Keep track of proposed DDL prevddl = '' if user_input is None: input_iter: Iterator[str] = iter(tuple()) else: input_iter = iter(user_input) try: step = 0 while True: mig = await self.con.query_single( 'DESCRIBE CURRENT MIGRATION AS JSON;') mig = json.loads(mig) if mig['proposed'] is None: assert_data_shape.assert_data_shape( mig, {'complete': True}, self.fail, message='No more "proposed", but not "completed" ' 'either.' ) if commit: await self.con.execute('COMMIT MIGRATION;') break interpolations = {} user_input_reqs = mig['proposed']['required_user_input'] if user_input_reqs: for var in user_input_reqs: var_name = var['placeholder'] var_desc = var['prompt'] try: var_value = next(input_iter) except StopIteration: raise AssertionError( f'missing input value for prompt: {var_desc}' ) from None interpolations[var_name] = var_value for stmt in mig['proposed']['statements']: curddl = stmt['text'] if interpolations: def _replace(match, interpolations=interpolations): var_name = match.group(1) var_value = interpolations.get(var_name) if var_value is None: raise AssertionError( f'missing value for ' f'placeholder {var_name!r}' ) return var_value curddl = re.sub(r'\\\((\w+)\)', _replace, curddl) if prevddl == curddl: raise Exception( f"Repeated previous proposed DDL {curddl!r}" ) try: await self.con.execute(curddl) except Exception as exc: raise Exception( f"Error while processing {curddl!r}" ) from exc prevddl = curddl step += 1 if limit is not None and step == limit: break except Exception: self.add_fail_notes(serialization='json') raise
Repeatedly get the next step from DESCRIBE and execute it. The point of this as opposed to just using "POPULATE MIGRATION; COMMIT MIGRATION;" is that we want to make sure that the generated DDL is valid and in case it's not, narrow down which step is causing issues.
fast_forward_describe_migration
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def start_migration( self, migration, *, populate: bool = False, module: str = 'test', explicit_modules: bool = False, ): if explicit_modules: migration_text = migration else: migration_text = f''' module {module} {{ {migration} }} ''' mig = f""" START MIGRATION TO {{ {migration_text} }}; """ await self.con.execute(mig) if populate: await self.con.execute('POPULATE MIGRATION;')
mig = f
start_migration
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def assert_last_migration(self): last_name = await self.con.query_single( ''' select assert_single( sys::Branch.last_migration filter sys::Branch.name = sys::get_current_database()); ''' ) last_mig = await self.con.query_single( ''' select assert_single( schema::Migration { name } filter not exists .<parents); ''' ) if last_mig: self.assertEqual(last_mig.name, last_name) else: self.assertIsNone(last_name)
select assert_single( sys::Branch.last_migration filter sys::Branch.name = sys::get_current_database());
assert_last_migration
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_simple_01(self): # Base case, ensuring a single SDL migration from a clean # state works. await self.migrate(""" type NamedObject { required property name -> str; multi link related -> NamedObject { property lang -> str; }; }; """) await self.con.execute(""" SET MODULE test; INSERT NamedObject { name := 'Test' }; INSERT NamedObject { name := 'Test 2', related := (SELECT DETACHED NamedObject FILTER .name = 'Test') }; """) await self.assert_query_result( r""" SELECT NamedObject { related: { name, @lang } } FILTER .name = 'Test 2'; """, [ { 'related': [{'name': 'Test', '@lang': None}], } ] )
) await self.con.execute(
test_edgeql_migration_simple_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_link_inheritance(self): schema_f = os.path.join(os.path.dirname(__file__), 'schemas', 'links_1.esdl') with open(schema_f) as f: schema = f.read() await self.migrate(schema) await self.con.execute(''' SET MODULE test; INSERT Target1 { name := 'Target1_linkinh_2' }; INSERT ObjectType01 { target := (SELECT Target1 FILTER .name = 'Target1_linkinh_2' LIMIT 1) }; INSERT Target0 { name := 'Target0_linkinh_2' }; INSERT ObjectType23 { target := (SELECT Target0 FILTER .name = 'Target0_linkinh_2' LIMIT 1) }; ''') await self.con.query('DECLARE SAVEPOINT t0;') with self.assertRaisesRegex( edgedb.InvalidLinkTargetError, r"invalid target for link 'target' of object type " r"'test::ObjectType01': " r"'test::Target0' \(expecting 'test::Target1'\)"): # Target0 is not allowed to be targeted by ObjectType01, since # ObjectType01 inherits from ObjectType1 which requires more # specific Target1. await self.con.execute(''' INSERT ObjectType01 { target := ( SELECT Target0 FILTER .name = 'Target0_linkinh_2' LIMIT 1 ) }; ''') schema_f = os.path.join(os.path.dirname(__file__), 'schemas', 'links_1_migrated.esdl') with open(schema_f) as f: schema = f.read() await self.con.query('ROLLBACK TO SAVEPOINT t0') await self.migrate(schema)
) await self.con.query('DECLARE SAVEPOINT t0;') with self.assertRaisesRegex( edgedb.InvalidLinkTargetError, r"invalid target for link 'target' of object type " r"'test::ObjectType01': " r"'test::Target0' \(expecting 'test::Target1'\)"): # Target0 is not allowed to be targeted by ObjectType01, since # ObjectType01 inherits from ObjectType1 which requires more # specific Target1. await self.con.execute(
test_edgeql_migration_link_inheritance
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_reject_01(self): await self.migrate(''' type Foo; ''') await self.start_migration(''' type Bar; ''') await self.assert_describe_migration({ 'proposed': { 'statements': [{ 'text': """ ALTER TYPE test::Foo RENAME TO test::Bar; """ }] } }) await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ''') await self.assert_describe_migration({ 'proposed': { 'statements': [{ 'text': """ CREATE TYPE test::Bar; """ }] } }) await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ''') await self.assert_describe_migration({ 'proposed': { 'statements': [{ 'text': """ DROP TYPE test::Foo; """ }] } }) await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ''') await self.assert_describe_migration({ 'proposed': None, 'complete': False, })
) await self.start_migration(
test_edgeql_migration_describe_reject_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_reject_02(self): await self.con.execute(''' START MIGRATION TO { module test { }; }; ''') await self.assert_describe_migration({ 'parent': 'm1a2l6lbzimqokzygdzbkyjrhbmjh3iljg7i2m6r2ias2z2de4x4cq', 'confirmed': [], 'complete': True, 'proposed': None, }) # Reject an empty proposal, which should be an idempotent # operation. So reject it several times. await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ALTER CURRENT MIGRATION REJECT PROPOSED; ALTER CURRENT MIGRATION REJECT PROPOSED; ''')
) await self.assert_describe_migration({ 'parent': 'm1a2l6lbzimqokzygdzbkyjrhbmjh3iljg7i2m6r2ias2z2de4x4cq', 'confirmed': [], 'complete': True, 'proposed': None, }) # Reject an empty proposal, which should be an idempotent # operation. So reject it several times. await self.con.execute(
test_edgeql_migration_describe_reject_02
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_reject_03(self): await self.con.execute(''' START MIGRATION TO { module test { type Type0; }; }; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE TYPE test::Type0;' }], 'prompt': "did you create object type 'test::Type0'?", }, }) # Reject a proposal until we run out of options. await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ALTER CURRENT MIGRATION REJECT PROPOSED; ALTER CURRENT MIGRATION REJECT PROPOSED; ALTER CURRENT MIGRATION REJECT PROPOSED; ALTER CURRENT MIGRATION REJECT PROPOSED; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': None, })
) await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE TYPE test::Type0;' }], 'prompt': "did you create object type 'test::Type0'?", }, }) # Reject a proposal until we run out of options. await self.con.execute(
test_edgeql_migration_describe_reject_03
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_reject_04(self): # Migration involving 2 modules await self.con.execute(''' START MIGRATION TO { module test { type Test; }; module other { type Test; }; }; ''') await self.fast_forward_describe_migration() await self.con.execute(''' START MIGRATION TO { module test { type Test2; }; module other { type Test3; }; }; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'ALTER TYPE other::Test RENAME TO other::Test3;', }], 'prompt': ( "did you rename object type 'other::Test' to " "'other::Test3'?" ), }, }) await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'ALTER TYPE other::Test RENAME TO test::Test2;', }], 'prompt': ( "did you rename object type 'other::Test' to " "'test::Test2'?" ), }, }) await self.con.execute(''' ALTER TYPE other::Test RENAME TO test::Test2; ''') await self.assert_describe_migration({ 'confirmed': [ 'ALTER TYPE other::Test RENAME TO test::Test2;' ], 'complete': False, 'proposed': { 'statements': [{ 'text': 'ALTER TYPE test::Test RENAME TO other::Test3;', }], 'prompt': ( "did you rename object type 'test::Test' to " "'other::Test3'?" ), }, }) await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ''') await self.assert_describe_migration({ 'confirmed': [ 'ALTER TYPE other::Test RENAME TO test::Test2;' ], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE TYPE other::Test3;', }], 'prompt': ( "did you create object type 'other::Test3'?" ), }, }) # Change our mind and use a rejected operation to rename the # type after all. So, we should be done now. await self.con.execute(''' ALTER TYPE test::Test RENAME TO other::Test3; ''') await self.assert_describe_migration({ 'confirmed': [ 'ALTER TYPE other::Test RENAME TO test::Test2;', 'ALTER TYPE test::Test RENAME TO other::Test3;', ], 'complete': True, 'proposed': None, })
) await self.fast_forward_describe_migration() await self.con.execute(
test_edgeql_migration_describe_reject_04
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_reject_05(self): await self.migrate(''' type User { required property username -> str { constraint exclusive; constraint regexp(r'asdf'); } } ''') await self.start_migration(''' type User { required property username -> str { constraint exclusive; constraint regexp(r'foo'); } } ''') await self.assert_describe_migration({ 'proposed': { 'prompt': ( "did you drop constraint 'std::regexp' " "of property 'username'?" ) } }) await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ''') # ... nothing to do, we can't get it await self.assert_describe_migration({ 'complete': False, 'proposed': None, })
) await self.start_migration(
test_edgeql_migration_describe_reject_05
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_module_01(self): # Migration that creates a new module. await self.con.execute(''' START MIGRATION TO { module new_module { type Type0; }; }; ''') # Validate that we create a 'new_module' await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE MODULE new_module IF NOT EXISTS;' }], }, }) # Auto-complete migration await self.fast_forward_describe_migration() # Drop the 'new_module' await self.con.execute(''' START MIGRATION TO { module default {}; }; ''') # Validate that we drop a 'new_module' await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'DROP TYPE new_module::Type0;' }], }, }) await self.con.execute(''' DROP TYPE new_module::Type0; ''') await self.assert_describe_migration({ 'confirmed': [ 'DROP TYPE new_module::Type0;' ], 'complete': False, 'proposed': { 'statements': [{ 'text': 'DROP MODULE new_module;' }], }, }) # Auto-complete migration await self.fast_forward_describe_migration() # Make sure that 'new_module' can be created again with no # problems (i.e. it was dropped cleanly). await self.con.execute(''' START MIGRATION TO { module new_module { type Type0; }; }; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE MODULE new_module IF NOT EXISTS;' }], }, }) await self.con.execute(''' CREATE MODULE new_module; ''') await self.assert_describe_migration({ 'confirmed': [ 'CREATE MODULE new_module;', ], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE TYPE new_module::Type0;' }], }, }) await self.con.execute(''' CREATE TYPE new_module::Type0; COMMIT MIGRATION; ''') await self.assert_query_result( r""" INSERT new_module::Type0; """, [{ 'id': uuid.UUID, }], )
) # Validate that we create a 'new_module' await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE MODULE new_module IF NOT EXISTS;' }], }, }) # Auto-complete migration await self.fast_forward_describe_migration() # Drop the 'new_module' await self.con.execute(
test_edgeql_migration_describe_module_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_type_01(self): # Migration that renames a type. await self.con.execute(''' START MIGRATION TO { module test { type Type1; }; }; ''') await self.assert_describe_migration({ 'parent': 'm1a2l6lbzimqokzygdzbkyjrhbmjh3iljg7i2m6r2ias2z2de4x4cq', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'CREATE TYPE test::Type1;' ) }], 'prompt': "did you create object type 'test::Type1'?", }, }) # Auto-complete migration await self.fast_forward_describe_migration() res = await self.con.query(r'''INSERT test::Type1;''') await self.con.execute(''' START MIGRATION TO { module test { type Type01; }; }; ''') await self.assert_describe_migration({ 'parent': 'm1jywblj6c7z25ouifcicpxniu37jdpyunf62q4th7isdafcqu67gq', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'ALTER TYPE test::Type1 RENAME TO test::Type01;' ) }], 'prompt': ( "did you rename object type 'test::Type1' to " "'test::Type01'?" ), }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.assert_query_result(''' SELECT test::Type01; ''', [{'id': res[0].id}])
) await self.assert_describe_migration({ 'parent': 'm1a2l6lbzimqokzygdzbkyjrhbmjh3iljg7i2m6r2ias2z2de4x4cq', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'CREATE TYPE test::Type1;' ) }], 'prompt': "did you create object type 'test::Type1'?", }, }) # Auto-complete migration await self.fast_forward_describe_migration() res = await self.con.query(r'''INSERT test::Type1;''') await self.con.execute(
test_edgeql_migration_describe_type_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_type_02(self): # Migration that creates a type. await self.con.execute(''' START MIGRATION TO { module test { type Type02; }; }; ''') await self.assert_describe_migration({ 'parent': 'm1a2l6lbzimqokzygdzbkyjrhbmjh3iljg7i2m6r2ias2z2de4x4cq', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'CREATE TYPE test::Type02;' ) }], 'prompt': "did you create object type 'test::Type02'?", }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.con.query(r'''INSERT test::Type02;''') # Migration that drops a type. await self.con.execute(''' START MIGRATION TO { module test { }; }; ''') await self.assert_describe_migration({ 'parent': 'm1fcvk56n44i62qwjnw5nqgafnbpulfhhaeb6kxqhh4c6lc4elwysa', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'DROP TYPE test::Type02;' ) }], 'prompt': ( "did you drop object type 'test::Type02'?" ), }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.assert_query_result(''' WITH MODULE schema SELECT ObjectType FILTER .name = 'test::Type02'; ''', []) # Make sure that type dropped cleanly by re-creating and # using the type again. await self.con.execute(''' START MIGRATION TO { module test { type Type02; }; }; ''') await self.assert_describe_migration({ 'parent': 'm1yee6qj63nps27cjnrcudwiupusdqkzrwistpvfbqf2fstcmwauwa', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'CREATE TYPE test::Type02;' ) }], 'prompt': "did you create object type 'test::Type02'?", }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.assert_query_result(''' INSERT test::Type02; ''', [{'id': uuid.UUID}])
) await self.assert_describe_migration({ 'parent': 'm1a2l6lbzimqokzygdzbkyjrhbmjh3iljg7i2m6r2ias2z2de4x4cq', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'CREATE TYPE test::Type02;' ) }], 'prompt': "did you create object type 'test::Type02'?", }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.con.query(r'''INSERT test::Type02;''') # Migration that drops a type. await self.con.execute(
test_edgeql_migration_describe_type_02
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_type_03(self): await self.migrate(''' type Type0; ''') await self.con.execute(''' START MIGRATION TO { module test { type Type1; }; }; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': "ALTER TYPE test::Type0 RENAME TO test::Type1;" }], 'prompt': ( "did you rename object type 'test::Type0' to " "'test::Type1'?" ), }, }) # Instead of the suggestion do a couple of different, but # equivalent commands. await self.con.execute(''' ALTER TYPE test::Type0 RENAME TO test::TypeXX; ALTER TYPE test::TypeXX RENAME TO test::Type1; ''') await self.assert_describe_migration({ 'confirmed': [ 'ALTER TYPE test::Type0 RENAME TO test::TypeXX;', 'ALTER TYPE test::TypeXX RENAME TO test::Type1;', ], 'complete': True, 'proposed': None, })
) await self.con.execute(
test_edgeql_migration_describe_type_03
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_type_04(self): self.maxDiff = None await self.migrate(''' type Test; ''') await self.con.execute(''' START MIGRATION TO { module test { type Test2; type Test3; }; }; ''') await self.assert_describe_migration({ 'parent': 'm1xh653zionj2aehqbh7x6km5lo3b2mjaftxdkvqoh3wluc3iv6k2a', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'ALTER TYPE test::Test RENAME TO test::Test2;', }], 'prompt': ( "did you rename object type 'test::Test' to 'test::Test2'?" ), }, }) await self.con.execute(''' ALTER CURRENT MIGRATION REJECT PROPOSED; ''') await self.assert_describe_migration({ 'parent': 'm1xh653zionj2aehqbh7x6km5lo3b2mjaftxdkvqoh3wluc3iv6k2a', 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': 'ALTER TYPE test::Test RENAME TO test::Test3;', }], 'prompt': ( "did you rename object type 'test::Test' to 'test::Test3'?" ), }, }) await self.con.execute(''' ALTER TYPE test::Test RENAME TO test::Test3; ''') await self.assert_describe_migration({ 'parent': 'm1xh653zionj2aehqbh7x6km5lo3b2mjaftxdkvqoh3wluc3iv6k2a', 'confirmed': ['ALTER TYPE test::Test RENAME TO test::Test3;'], 'complete': False, 'proposed': { 'statements': [{ 'text': 'CREATE TYPE test::Test2;', }], 'prompt': ( "did you create object type 'test::Test2'?" ), }, })
) await self.con.execute(
test_edgeql_migration_describe_type_04
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0
async def test_edgeql_migration_describe_property_01(self): # Migration that renames a property. await self.con.execute(''' START MIGRATION TO { module test { type Type01 { property field1 -> str; }; }; }; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'CREATE TYPE test::Type01 {\n' ' CREATE PROPERTY field1' ': std::str;\n' '};' ) }], 'prompt': "did you create object type 'test::Type01'?", }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.con.execute(''' INSERT test::Type01 { field1 := 'prop_test' }; ''') await self.con.execute(''' START MIGRATION TO { module test { type Type01 { property field01 -> str; }; }; }; ''') await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'ALTER TYPE test::Type01 {\n' ' ALTER PROPERTY field1 {\n' ' RENAME TO field01;\n' ' };\n' '};' ) }], 'prompt': ( "did you rename property 'field1' of object type" " 'test::Type01' to 'field01'?" ), }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.assert_query_result(''' SELECT test::Type01 { field01 }; ''', [{'field01': 'prop_test'}])
) await self.assert_describe_migration({ 'confirmed': [], 'complete': False, 'proposed': { 'statements': [{ 'text': ( 'CREATE TYPE test::Type01 {\n' ' CREATE PROPERTY field1' ': std::str;\n' '};' ) }], 'prompt': "did you create object type 'test::Type01'?", }, }) # Auto-complete migration await self.fast_forward_describe_migration() await self.con.execute(
test_edgeql_migration_describe_property_01
python
geldata/gel
tests/test_edgeql_data_migration.py
https://github.com/geldata/gel/blob/master/tests/test_edgeql_data_migration.py
Apache-2.0