Changeset: 62bc07550c8d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/62bc07550c8d Added Files: sql/test/Views/Tests/Indirect.test sql/test/Views/Tests/Views.test Removed Files: sql/test/Views/Tests/Indirect.py sql/test/Views/Tests/Views.SQL.py Branch: Sep2022 Log Message:
Converted to .test format. diffs (256 lines): diff --git a/sql/test/Views/Tests/Indirect.py b/sql/test/Views/Tests/Indirect.test rename from sql/test/Views/Tests/Indirect.py rename to sql/test/Views/Tests/Indirect.test --- a/sql/test/Views/Tests/Indirect.py +++ b/sql/test/Views/Tests/Indirect.test @@ -1,119 +1,102 @@ -import os, sys, pymonetdb +statement ok +start transaction +statement ok +create schema foo -port = int(os.environ['MAPIPORT']) -db = os.environ['TSTDB'] +statement ok +create user u1 with password '1' name 'u1' schema foo + +statement ok +create user u2 with password '2' name 'u2' schema foo -conn1 = pymonetdb.connect(port=port,database=db,autocommit=True,username='monetdb',password='monetdb') -cur1 = conn1.cursor() -cur1.execute(""" -start transaction; -create schema foo; -create user u1 with password '1' name 'u1' schema foo; -create user u2 with password '2' name 'u2' schema foo; -create table foo.tab1 (col1 int, col2 int); -create table foo.tab2 (col1 int, col2 int); -insert into foo.tab1 values (1, 1); -insert into foo.tab2 values (2, 2); -create view foo.v1(col1,col2) as (select col1, col2 from foo.tab1); -create view foo.v2(col1,col2) as (select v1.col1 + v1.col2, v1.col2 + 10 from foo.v1, foo.tab2); -commit; -""") -cur1.close() -conn1.close() +statement ok +create table foo.tab1 (col1 int, col2 int) + +statement ok +create table foo.tab2 (col1 int, col2 int) + +statement ok +insert into foo.tab1 values (1, 1) + +statement ok +insert into foo.tab2 values (2, 2) -conn1 = pymonetdb.connect(port=port,database=db,autocommit=True,username='u1',password='1') -cur1 = conn1.cursor() -try: - cur1.execute('SELECT "col1" FROM "foo"."v1";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: access denied for u1 to view 'foo.v1'" not in str(e): - sys.stderr.write('Wrong error %s, expected SELECT: access denied for u1 to view \'foo.v1\'' % (str(e))) -try: - cur1.execute('SELECT "col2" FROM "foo"."v1";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: access denied for u1 to view 'foo.v1'" not in str(e): - sys.stderr.write('Wrong error %s, expected SELECT: access denied for u1 to view \'foo.v1\'' % (str(e))) -try: - cur1.execute('SELECT "col1" FROM "foo"."tab1";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: access denied for u1 to table 'foo.tab1'" not in str(e): - sys.stderr.write('Wrong error %s, expected SELECT: access denied for u1 to table \'foo.tab1\'' % (str(e))) -cur1.close() -conn1.close() +statement ok +create view foo.v1(col1,col2) as (select col1, col2 from foo.tab1) + +statement ok +create view foo.v2(col1,col2) as (select v1.col1 + v1.col2, v1.col2 + 10 from foo.v1, foo.tab2) + +statement ok +commit + +@connection(id=1, username=u1, password=1) +statement error 42000!SELECT: access denied for u1 to view 'foo.v1' +SELECT "col1" FROM "foo"."v1" -conn1 = pymonetdb.connect(port=port,database=db,autocommit=True,username='monetdb',password='monetdb') -cur1 = conn1.cursor() -cur1.execute(""" -grant select ("col1") ON "foo"."v1" TO u1; -grant select ("col1") ON "foo"."v2" TO u2; -""") -cur1.close() -conn1.close() +@connection(id=1) +statement error 42000!SELECT: access denied for u1 to view 'foo.v1' +SELECT "col2" FROM "foo"."v1" + +@connection(id=1) +statement error 42000!SELECT: access denied for u1 to table 'foo.tab1' +SELECT "col1" FROM "foo"."tab1" + +statement ok +grant select ("col1") ON "foo"."v1" TO u1 + +statement ok +grant select ("col1") ON "foo"."v2" TO u2 -conn1 = pymonetdb.connect(port=port,database=db,autocommit=True,username='u1',password='1') -cur1 = conn1.cursor() -cur1.execute('SELECT "col1" FROM "foo"."v1";') -if cur1.fetchall() != [(1, )]: - sys.stderr.write("[(1, )] expected") -try: - cur1.execute('SELECT "col2" FROM "foo"."v1";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: identifier 'col2' unknown" not in str(e): - sys.stderr.write('Wrong error %s, expected "SELECT: identifier \'col2\' unknown' % (str(e))) -try: - cur1.execute('SELECT "col1" FROM "foo"."tab1";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: access denied for u1 to table 'foo.tab1'" not in str(e): - sys.stderr.write('Wrong error %s, expected SELECT: access denied for u1 to table \'foo.tab1\'' % (str(e))) -cur1.close() -conn1.close() +@connection(id=2, username=u1, password=1) +query I nosort +SELECT "col1" FROM "foo"."v1" +---- +1 + +@connection(id=2) +statement error 42000!SELECT: identifier 'col2' unknown +SELECT "col2" FROM "foo"."v1" + +@connection(id=2) +statement error 42000!SELECT: access denied for u1 to table 'foo.tab1' +SELECT "col1" FROM "foo"."tab1" + +@connection(id=u2, username=u2, password=2) +query I nosort +SELECT "col1" FROM "foo"."v2" +---- +2 + +@connection(id=u2) +statement error 42000!SELECT: identifier 'col2' unknown +SELECT "col2" FROM "foo"."v2" -conn1 = pymonetdb.connect(port=port,database=db,autocommit=True,username='u2',password='2') -cur1 = conn1.cursor() -cur1.execute('SELECT "col1" FROM "foo"."v2";') -if cur1.fetchall() != [(2, )]: - sys.stderr.write("[(2, )] expected") -try: - cur1.execute('SELECT "col2" FROM "foo"."v2";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: identifier 'col2' unknown" not in str(e): - sys.stderr.write('Wrong error %s, expected "SELECT: identifier \'col2\' unknown' % (str(e))) -try: - cur1.execute('SELECT "col1" FROM "foo"."v1";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: access denied for u2 to view 'foo.v1'" not in str(e): - sys.stderr.write('Wrong error %s, expected SELECT: access denied for u2 to view \'foo.v1\'' % (str(e))) -try: - cur1.execute('SELECT "col1" FROM "foo"."tab1";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: access denied for u2 to table 'foo.tab1'" not in str(e): - sys.stderr.write('Wrong error %s, expected SELECT: access denied for u2 to table \'foo.tab1\'' % (str(e))) -try: - cur1.execute('SELECT "col1" FROM "foo"."tab2";') # error, not allowed - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "SELECT: access denied for u2 to table 'foo.tab2'" not in str(e): - sys.stderr.write('Wrong error %s, expected SELECT: access denied for u2 to table \'foo.tab2\'' % (str(e))) -cur1.close() -conn1.close() +@connection(id=u2) +statement error 42000!SELECT: access denied for u2 to view 'foo.v1' +SELECT "col1" FROM "foo"."v1" + +@connection(id=u2) +statement error 42000!SELECT: access denied for u2 to table 'foo.tab1' +SELECT "col1" FROM "foo"."tab1" + +@connection(id=u2) +statement error 42000!SELECT: access denied for u2 to table 'foo.tab2' +SELECT "col1" FROM "foo"."tab2" -conn1 = pymonetdb.connect(port=port,database=db,autocommit=True,username='monetdb',password='monetdb') -cur1 = conn1.cursor() -cur1.execute(""" -start transaction; -drop user u1; -drop user u2; -drop schema foo cascade; -commit; -""") -cur1.close() -conn1.close() +statement ok +start transaction + +statement ok +drop user u1 + +statement ok +drop user u2 + +statement ok +drop schema foo cascade + +statement ok +commit + diff --git a/sql/test/Views/Tests/Views.SQL.py b/sql/test/Views/Tests/Views.test rename from sql/test/Views/Tests/Views.SQL.py rename to sql/test/Views/Tests/Views.test --- a/sql/test/Views/Tests/Views.SQL.py +++ b/sql/test/Views/Tests/Views.test @@ -1,11 +1,21 @@ -from MonetDBtesting.sqltest import SQLTestCase +statement ok +CREATE TABLE t1(id int, name varchar(1024), age int, PRIMARY KEY(id)) + +statement ok +CREATE VIEW v1 as select id, age from t1 where name like 'monet%' + +statement error ALTER TABLE: cannot drop column from VIEW 'v1' +ALTER TABLE v1 DROP COLUMN age -with SQLTestCase() as tc: - tc.connect(username="monetdb", password="monetdb") - tc.execute("CREATE TABLE t1(id int, name varchar(1024), age int, PRIMARY KEY(id));").assertSucceeded() - tc.execute("CREATE VIEW v1 as select id, age from t1 where name like 'monet%';").assertSucceeded() - tc.execute("ALTER TABLE v1 DROP COLUMN age;").assertFailed(err_message="ALTER TABLE: cannot drop column from VIEW 'v1'") - tc.execute("CREATE TRIGGER trigger_test AFTER INSERT ON v1 INSERT INTO t2 values(1,23);").assertFailed(err_message="CREATE TRIGGER: cannot create trigger on view 'v1'") - tc.execute("CREATE INDEX id_age_index ON v1(id,age);").assertFailed(err_message="CREATE INDEX: cannot create index on view 'v1'") - tc.execute("DROP view v1;").assertSucceeded() - tc.execute("DROP table t1;").assertSucceeded() +statement error CREATE TRIGGER: cannot create trigger on view 'v1' +CREATE TRIGGER trigger_test AFTER INSERT ON v1 INSERT INTO t2 values(1,23) + +statement error CREATE INDEX: cannot create index on view 'v1' +CREATE INDEX id_age_index ON v1(id,age) + +statement ok +DROP view v1 + +statement ok +DROP table t1 + _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org