-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_13.py
77 lines (70 loc) · 2.62 KB
/
test_13.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
#coding:utf-8
"""
ID: table.alter-13
TITLE: ALTER TABLE - ALTER CONSTRAINT
DESCRIPTION:
FBTEST: functional.table.alter.13
NOTES:
"""
import pytest
from firebird.qa import *
db = db_factory()
test_script = """RECREATE TABLE test_constraints(
id integer not null constraint pk_c primary key,
unq integer constraint uk unique,
nn integer constraint not_null not null,
fk integer constraint fk references test_constraints (id),
chk integer constraint chk check(chk=1)
);
-- Default activity of constraint is already checked in create/test_08
insert into test_constraints values(1,1,1,1,1);
commit;
-- Check deactivation of constraints
alter table test_constraints
alter constraint uk not enforced,
alter constraint not_null not enforced,
alter constraint fk not enforced,
alter constraint chk not enforced;
alter table test_constraints
alter constraint pk_c not enforced;
commit;
-- check that none of these constraints are not enforced now
insert into test_constraints values(1,1,NULL,11,11);
rollback;
-- Check activation of constraints
alter table test_constraints
alter constraint pk_c enforced,
alter constraint uk enforced,
alter constraint not_null enforced,
alter constraint fk enforced,
alter constraint chk enforced;
commit;
-- Check that every one has been activated
insert into test_constraints values (1,2,2,1,1); -- pk_c violation
insert into test_constraints values (3,1,3,1,1); -- uk violation
insert into test_constraints values (4,4,NULL,1,1); -- nn violation
insert into test_constraints values (5,5,5,11,1); -- fk violation
insert into test_constraints values (6,6,6,1,11); -- chk violation
"""
act = isql_act('db', test_script, substitutions=[('CHECK_[0-9]+', '')])
expected_stdout = """Statement failed, SQLSTATE = 23000
violation of PRIMARY or UNIQUE KEY constraint "PK_C" on table "TEST_CONSTRAINTS"
-Problematic key value is ("ID" = 1)
Statement failed, SQLSTATE = 23000
violation of PRIMARY or UNIQUE KEY constraint "UK" on table "TEST_CONSTRAINTS"
-Problematic key value is ("UNQ" = 1)
Statement failed, SQLSTATE = 23000
validation error for column "TEST_CONSTRAINTS"."NN", value "*** null ***"
Statement failed, SQLSTATE = 23000
violation of FOREIGN KEY constraint "FK" on table "TEST_CONSTRAINTS"
-Foreign key reference target does not exist
-Problematic key value is ("FK" = 11)
Statement failed, SQLSTATE = 23000
Operation violates CHECK constraint CHK on view or table TEST_CONSTRAINTS
-At trigger 'CHECK_1'
"""
@pytest.mark.version('>=6')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute(combine_output = True)
assert act.clean_stdout == act.clean_expected_stdout