6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00

Added/Updated tests\bugs\core_5790_test.py: refactored: make code more robust when FB major version changes. Removed unneeded parts of code.

This commit is contained in:
pavel-zotov 2023-09-28 15:18:08 +03:00
parent 8de6057b4a
commit 5c93362438

View File

@ -15,55 +15,60 @@ from firebird.qa import *
db = db_factory()
act = python_act('db', substitutions=[('Commit current transaction \\(y/n\\)\\?', '')])
expected_stdout = """
RDB$USER TMP$C5790
RDB$GRANTOR SYSDBA
RDB$PRIVILEGE O
RDB$GRANT_OPTION 0
RDB$RELATION_NAME SQL$DATABASE
RDB$FIELD_NAME <null>
RDB$USER_TYPE 8
rdb_object_type_is_expected ? YES
Records affected: 1
Records affected: 0
"""
act = python_act('db')
test_user = user_factory('db', name='tmp$c5790', password='123')
fdb_file = temp_file('tmp_5790.fdb')
@pytest.mark.version('>=3.0.4')
def test_1(act: Action, test_user: User, fdb_file: Path):
if act.is_version('>=4'):
expected_obj_type = 21
elif act.is_version('>=3'):
expected_obj_type = 20
expected_stdout = f"""
RDB$USER TMP$C5790
RDB$GRANTOR SYSDBA
RDB$PRIVILEGE O
RDB$GRANT_OPTION 0
RDB$RELATION_NAME SQL$DATABASE
RDB$FIELD_NAME <null>
RDB$USER_TYPE 8
RDB$OBJECT_TYPE {expected_obj_type}
Records affected: 1
Records affected: 0
"""
act.expected_stdout = expected_stdout
test_script = f"""
create database 'localhost:{fdb_file}';
alter database set linger to 0;
commit;
grant drop database to {test_user.name};
commit;
connect 'localhost:{fdb_file}' user {test_user.name} password '{test_user.password}';
set list on;
set count on;
select
r.rdb$user -- {test_user.name}
,r.rdb$grantor -- sysdba
,r.rdb$privilege -- o
,r.rdb$grant_option -- 0
,r.rdb$relation_name -- sql$database
,r.rdb$field_name -- <null>
,r.rdb$user_type -- 8
,iif( r.rdb$object_type = decode( left(rdb$get_context('SYSTEM', 'ENGINE_VERSION'),1), '3',20, '4',21, '5', 21), 'YES', 'NO: ' || r.rdb$object_type) "rdb_object_type_is_expected ?"
from rdb$user_privileges r
where r.rdb$user=upper('{test_user.name}');
create database 'localhost:{fdb_file}';
alter database set linger to 0;
commit;
grant drop database to {test_user.name};
commit;
connect 'localhost:{fdb_file}' user {test_user.name} password '{test_user.password}';
set list on;
set count on;
select
r.rdb$user -- {test_user.name}
,r.rdb$grantor -- sysdba
,r.rdb$privilege -- o
,r.rdb$grant_option -- 0
,r.rdb$relation_name -- sql$database
,r.rdb$field_name -- <null>
,r.rdb$user_type -- 8
,r.rdb$object_type
from rdb$user_privileges r
where r.rdb$user=upper('{test_user.name}');
-- this should NOT show any attachments: "Records affected: 0" must be shown here.
select * from mon$attachments where mon$attachment_id != current_connection;
commit;
-- this should NOT show any attachments: "Records affected: 0" must be shown here.
select * from mon$attachments where mon$attachment_id != current_connection;
commit;
drop database;
rollback;
drop database;
rollback;
"""
act.isql(switches=['-q'], input=test_script)
act.isql(switches=['-q'], input = test_script, connect_db = False, combine_output = True)
assert act.clean_stdout == act.clean_expected_stdout
assert not fdb_file.exists()