Skip to content

Commit 884a6a2

Browse files
committed
Add tests
1 parent ad54565 commit 884a6a2

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

tests/schemas/insert.esdl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,12 @@ type ExceptTest {
265265
constraint exclusive on (.name) except (.deleted);
266266
};
267267
type ExceptTestSub extending ExceptTest;
268+
269+
type ConflictA {
270+
name: str;
271+
}
272+
type ConflictB {
273+
name: str { constraint exclusive };
274+
whatever: str;
275+
}
276+
type ConflictAB extending ConflictA, ConflictB;

tests/test_edgeql_insert.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7947,3 +7947,125 @@ async def test_edgeql_insert_empty_array_05(self):
79477947
""",
79487948
[{'l2': 0, 'subordinates': [{'name': 'hi', '@comment': 'a'}]}],
79497949
)
7950+
7951+
7952+
class TestRepeatableReadInsert(tb.QueryTestCase):
7953+
'''The scope of the tests is testing various modes of Object creation.'''
7954+
NO_FACTOR = True
7955+
INTERNAL_TESTMODE = False
7956+
7957+
SCHEMA = os.path.join(os.path.dirname(__file__), 'schemas',
7958+
'insert.esdl')
7959+
7960+
# Override setUp and tearDown to we run in RepeatableRead mode
7961+
def setUp(self):
7962+
self.loop.run_until_complete(
7963+
self.con.execute(
7964+
"configure session set default_transaction_isolation := "
7965+
"'RepeatableRead'"
7966+
)
7967+
)
7968+
7969+
super().setUp()
7970+
7971+
def tearDown(self):
7972+
super().tearDown()
7973+
7974+
self.loop.run_until_complete(
7975+
self.con.execute(
7976+
"configure session reset default_transaction_isolation"
7977+
)
7978+
)
7979+
7980+
async def test_edgeql_rr_insert_01(self):
7981+
# insert on A is ok, since A itself has no conflicts
7982+
await self.con.execute("""
7983+
insert ConflictA {
7984+
name := "test"
7985+
};
7986+
""")
7987+
7988+
async def test_edgeql_rr_insert_02(self):
7989+
with self.assertRaisesRegex(
7990+
edgedb.CapabilityError,
7991+
"INSERT to object type 'default::ConflictB' affects an "
7992+
"exclusive constraint on property 'name' of object type "
7993+
"'default::ConflictB' that is shared with descendant types: "
7994+
"'default::ConflictAB'"
7995+
):
7996+
await self.con.execute("""
7997+
insert ConflictB {
7998+
name := "test"
7999+
};
8000+
""")
8001+
8002+
async def test_edgeql_rr_insert_03(self):
8003+
with self.assertRaisesRegex(
8004+
edgedb.CapabilityError,
8005+
"INSERT to object type 'default::ConflictAB' affects an "
8006+
"exclusive constraint on property 'name' of object type "
8007+
"'default::ConflictAB' that is defined in ancestor object "
8008+
"type 'default::ConflictB'"
8009+
):
8010+
await self.con.execute("""
8011+
insert ConflictAB {
8012+
name := "test"
8013+
};
8014+
""")
8015+
8016+
async def test_edgeql_rr_insert_04(self):
8017+
with self.assertRaisesRegex(
8018+
edgedb.CapabilityError,
8019+
r"an exclusive constraint on object type 'default::Person2a' "
8020+
r"with expression '\(\.first, \.bff\)'"
8021+
):
8022+
await self.con.execute("""
8023+
INSERT Person2a {
8024+
first := "Emmanuel",
8025+
last := "Villip",
8026+
}
8027+
""")
8028+
8029+
async def test_edgeql_rr_update_01(self):
8030+
# *update* on A is not ok, since it hits AB which has a constraint
8031+
with self.assertRaisesRegex(
8032+
edgedb.CapabilityError,
8033+
# XXX: Should this be ConflictA
8034+
"UPDATE to object type 'default::ConflictAB' affects an "
8035+
"exclusive constraint on property 'name' of object type "
8036+
"'default::ConflictAB' that is defined in ancestor object "
8037+
"type 'default::ConflictB'"
8038+
):
8039+
await self.con.execute("""
8040+
update ConflictA set {
8041+
name := "test"
8042+
};
8043+
""")
8044+
8045+
async def test_edgeql_rr_update_02(self):
8046+
with self.assertRaisesRegex(
8047+
edgedb.CapabilityError,
8048+
"UPDATE to object type 'default::ConflictB' affects an "
8049+
"exclusive constraint on property 'name' of object type "
8050+
"'default::ConflictB' that is shared with descendant types: "
8051+
"'default::ConflictAB'"
8052+
):
8053+
await self.con.execute("""
8054+
update ConflictB set {
8055+
name := "test"
8056+
};
8057+
""")
8058+
8059+
async def test_edgeql_rr_update_03(self):
8060+
with self.assertRaisesRegex(
8061+
edgedb.CapabilityError,
8062+
"UPDATE to object type 'default::ConflictAB' affects an "
8063+
"exclusive constraint on property 'name' of object type "
8064+
"'default::ConflictAB' that is defined in ancestor object "
8065+
"type 'default::ConflictB'"
8066+
):
8067+
await self.con.execute("""
8068+
update ConflictAB set {
8069+
name := "test"
8070+
};
8071+
""")

0 commit comments

Comments
 (0)