forked from geldata/gel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dump_v2.py
143 lines (121 loc) · 4.31 KB
/
test_dump_v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#
# This source file is part of the EdgeDB open source project.
#
# Copyright 2020-present MagicStack Inc. and the EdgeDB authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os.path
import edgedb
from edb.testbase import server as tb
class DumpTestCaseMixin:
async def ensure_schema_data_integrity(self, include_data=True):
async for tx in self._run_and_rollback_retrying():
async with tx:
await self._ensure_schema_integrity()
if include_data:
await self._ensure_data_integrity()
async def _ensure_schema_integrity(self):
# Validate access policies
await self.assert_query_result(
r'''
SELECT schema::ObjectType {access_policies: {name}}
FILTER .name = 'default::Test2';
''',
[
{'access_policies': [{'name': 'test'}]},
],
)
# Validate globals
await self.assert_query_result(
r'''
SELECT schema::Global {
name, tgt := .target.name, required, default
}
ORDER BY .name
''',
[
{
'name': 'default::bar',
'tgt': 'std::int64',
'required': True,
'default': '-1',
},
{
'name': 'default::baz',
'tgt': 'default::baz',
'required': False,
'default': None,
},
{
'name': 'default::foo',
'tgt': 'std::str',
'required': False,
'default': None,
},
],
)
async def _ensure_data_integrity(self):
# Test that on source delete all work correctly still
await self.con.execute(r'DELETE SourceA FILTER .name = "s0"')
await self.assert_query_result(
r'''
SELECT TargetA {name}
FILTER .name = 't0';
''',
[],
)
# Should trigger a cascade that then causes a link policy error
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
r'prohibited by link target policy'):
async with self.con.transaction():
await self.con.execute(r'DELETE SourceA FILTER .name = "s1"')
# Shouldn't delete anything
await self.con.execute(r'DELETE SourceA FILTER .name = "s3"')
await self.assert_query_result(
r'''
SELECT TargetA {name}
FILTER .name = 't2';
''',
[{'name': 't2'}],
)
# But deleting the last reamining one should
await self.con.execute(r'DELETE SourceA FILTER .name = "s4"')
await self.assert_query_result(
r'''
SELECT TargetA {name}
FILTER .name = 't2';
''',
[],
)
class TestDumpV2(tb.StableDumpTestCase, DumpTestCaseMixin):
DEFAULT_MODULE = 'test'
SCHEMA_DEFAULT = os.path.join(os.path.dirname(__file__), 'schemas',
'dump_v2_default.esdl')
SETUP = os.path.join(os.path.dirname(__file__), 'schemas',
'dump_v2_setup.edgeql')
async def test_dump_v2_dump_restore(self):
await self.check_dump_restore(
DumpTestCaseMixin.ensure_schema_data_integrity)
async def test_dump_v2_branch_data(self):
await self.check_branching(
include_data=True,
check_method=DumpTestCaseMixin.ensure_schema_data_integrity)
class TestDumpV2Compat(
tb.DumpCompatTestCase,
DumpTestCaseMixin,
dump_subdir='dumpv2',
check_method=DumpTestCaseMixin.ensure_schema_data_integrity,
):
pass