mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-11 16:42:34 -06:00
Add RE-SQL tests for Roles and Resource Groups. Fixes #4415
This commit is contained in:
parent
f4bc4475cd
commit
588e3814d1
@ -10,6 +10,8 @@ New features
|
|||||||
************
|
************
|
||||||
|
|
||||||
| `Feature #4335 <https://redmine.postgresql.org/issues/4335>`_ - Add EXPLAIN options for SETTINGS and SUMMARY.
|
| `Feature #4335 <https://redmine.postgresql.org/issues/4335>`_ - Add EXPLAIN options for SETTINGS and SUMMARY.
|
||||||
|
| `Feature #4415 <https://redmine.postgresql.org/issues/4415>`_ - Add Reverse Engineered SQL tests for Roles and Resource Groups.
|
||||||
|
|
||||||
|
|
||||||
Bug fixes
|
Bug fixes
|
||||||
*********
|
*********
|
||||||
|
@ -226,8 +226,9 @@ class ResourceGroupView(NodeView):
|
|||||||
"Connection to the server has been lost."
|
"Connection to the server has been lost."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self.sql_path = 'resource_groups/sql/#{0}#'.format(
|
||||||
self.template_path = 'resource_groups/sql'
|
self.manager.version
|
||||||
|
)
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
return wrap
|
return wrap
|
||||||
@ -242,7 +243,7 @@ class ResourceGroupView(NodeView):
|
|||||||
gid: Server Group ID
|
gid: Server Group ID
|
||||||
sid: Server ID
|
sid: Server ID
|
||||||
"""
|
"""
|
||||||
sql = render_template("/".join([self.template_path, 'properties.sql']))
|
sql = render_template("/".join([self.sql_path, 'properties.sql']))
|
||||||
status, res = self.conn.execute_dict(sql)
|
status, res = self.conn.execute_dict(sql)
|
||||||
|
|
||||||
if not status:
|
if not status:
|
||||||
@ -263,7 +264,7 @@ class ResourceGroupView(NodeView):
|
|||||||
sid: Server ID
|
sid: Server ID
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sql = render_template("/".join([self.template_path, 'nodes.sql']),
|
sql = render_template("/".join([self.sql_path, 'nodes.sql']),
|
||||||
rgid=rg_id)
|
rgid=rg_id)
|
||||||
status, result = self.conn.execute_2darray(sql)
|
status, result = self.conn.execute_2darray(sql)
|
||||||
if not status:
|
if not status:
|
||||||
@ -295,7 +296,7 @@ class ResourceGroupView(NodeView):
|
|||||||
sid: Server ID
|
sid: Server ID
|
||||||
"""
|
"""
|
||||||
res = []
|
res = []
|
||||||
sql = render_template("/".join([self.template_path, 'nodes.sql']))
|
sql = render_template("/".join([self.sql_path, 'nodes.sql']))
|
||||||
status, result = self.conn.execute_2darray(sql)
|
status, result = self.conn.execute_2darray(sql)
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=result)
|
return internal_server_error(errormsg=result)
|
||||||
@ -326,7 +327,7 @@ class ResourceGroupView(NodeView):
|
|||||||
rg_id: Resource Group ID
|
rg_id: Resource Group ID
|
||||||
"""
|
"""
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id)
|
||||||
status, res = self.conn.execute_dict(sql)
|
status, res = self.conn.execute_dict(sql)
|
||||||
|
|
||||||
if not status:
|
if not status:
|
||||||
@ -368,7 +369,7 @@ class ResourceGroupView(NodeView):
|
|||||||
try:
|
try:
|
||||||
# Below logic will create new resource group
|
# Below logic will create new resource group
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'create.sql']),
|
"/".join([self.sql_path, 'create.sql']),
|
||||||
rgname=data['name'], conn=self.conn
|
rgname=data['name'], conn=self.conn
|
||||||
)
|
)
|
||||||
if sql and sql.strip('\n') and sql.strip(' '):
|
if sql and sql.strip('\n') and sql.strip(' '):
|
||||||
@ -380,7 +381,7 @@ class ResourceGroupView(NodeView):
|
|||||||
# resource group you can't run multiple commands in one
|
# resource group you can't run multiple commands in one
|
||||||
# transaction.
|
# transaction.
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'update.sql']),
|
"/".join([self.sql_path, 'update.sql']),
|
||||||
data=data, conn=self.conn
|
data=data, conn=self.conn
|
||||||
)
|
)
|
||||||
# Checking if we are not executing empty query
|
# Checking if we are not executing empty query
|
||||||
@ -391,7 +392,7 @@ class ResourceGroupView(NodeView):
|
|||||||
# Below logic is used to fetch the oid of the newly created
|
# Below logic is used to fetch the oid of the newly created
|
||||||
# resource group
|
# resource group
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'getoid.sql']),
|
"/".join([self.sql_path, 'getoid.sql']),
|
||||||
rgname=data['name']
|
rgname=data['name']
|
||||||
)
|
)
|
||||||
# Checking if we are not executing empty query
|
# Checking if we are not executing empty query
|
||||||
@ -431,7 +432,7 @@ class ResourceGroupView(NodeView):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id)
|
||||||
status, res = self.conn.execute_dict(sql)
|
status, res = self.conn.execute_dict(sql)
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=res)
|
return internal_server_error(errormsg=res)
|
||||||
@ -442,7 +443,7 @@ class ResourceGroupView(NodeView):
|
|||||||
|
|
||||||
if data['name'] != old_data['name']:
|
if data['name'] != old_data['name']:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'update.sql']),
|
"/".join([self.sql_path, 'update.sql']),
|
||||||
oldname=old_data['name'], newname=data['name'],
|
oldname=old_data['name'], newname=data['name'],
|
||||||
conn=self.conn
|
conn=self.conn
|
||||||
)
|
)
|
||||||
@ -458,7 +459,7 @@ class ResourceGroupView(NodeView):
|
|||||||
if data['cpu_rate_limit'] != old_data['cpu_rate_limit'] or \
|
if data['cpu_rate_limit'] != old_data['cpu_rate_limit'] or \
|
||||||
data['dirty_rate_limit'] != old_data['dirty_rate_limit']:
|
data['dirty_rate_limit'] != old_data['dirty_rate_limit']:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'update.sql']),
|
"/".join([self.sql_path, 'update.sql']),
|
||||||
data=data, conn=self.conn
|
data=data, conn=self.conn
|
||||||
)
|
)
|
||||||
if sql and sql.strip('\n') and sql.strip(' '):
|
if sql and sql.strip('\n') and sql.strip(' '):
|
||||||
@ -499,7 +500,7 @@ class ResourceGroupView(NodeView):
|
|||||||
for rg_id in data['ids']:
|
for rg_id in data['ids']:
|
||||||
# Get name for resource group from rg_id
|
# Get name for resource group from rg_id
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'delete.sql']),
|
"/".join([self.sql_path, 'delete.sql']),
|
||||||
rgid=rg_id, conn=self.conn
|
rgid=rg_id, conn=self.conn
|
||||||
)
|
)
|
||||||
status, rgname = self.conn.execute_scalar(sql)
|
status, rgname = self.conn.execute_scalar(sql)
|
||||||
@ -520,7 +521,7 @@ class ResourceGroupView(NodeView):
|
|||||||
|
|
||||||
# drop resource group
|
# drop resource group
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'delete.sql']),
|
"/".join([self.sql_path, 'delete.sql']),
|
||||||
rgname=rgname, conn=self.conn
|
rgname=rgname, conn=self.conn
|
||||||
)
|
)
|
||||||
status, res = self.conn.execute_scalar(sql)
|
status, res = self.conn.execute_scalar(sql)
|
||||||
@ -580,7 +581,7 @@ class ResourceGroupView(NodeView):
|
|||||||
]
|
]
|
||||||
if rg_id is not None:
|
if rg_id is not None:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id)
|
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id)
|
||||||
status, res = self.conn.execute_dict(sql)
|
status, res = self.conn.execute_dict(sql)
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=res)
|
return internal_server_error(errormsg=res)
|
||||||
@ -599,7 +600,7 @@ class ResourceGroupView(NodeView):
|
|||||||
if data['name'] != old_data['name']:
|
if data['name'] != old_data['name']:
|
||||||
name_changed = True
|
name_changed = True
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'update.sql']),
|
"/".join([self.sql_path, 'update.sql']),
|
||||||
oldname=old_data['name'], newname=data['name'],
|
oldname=old_data['name'], newname=data['name'],
|
||||||
conn=self.conn
|
conn=self.conn
|
||||||
)
|
)
|
||||||
@ -609,12 +610,12 @@ class ResourceGroupView(NodeView):
|
|||||||
sql += "\n-- Following query will be executed in a " \
|
sql += "\n-- Following query will be executed in a " \
|
||||||
"separate transaction\n"
|
"separate transaction\n"
|
||||||
sql += render_template(
|
sql += render_template(
|
||||||
"/".join([self.template_path, 'update.sql']),
|
"/".join([self.sql_path, 'update.sql']),
|
||||||
data=data, conn=self.conn
|
data=data, conn=self.conn
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'create.sql']),
|
"/".join([self.sql_path, 'create.sql']),
|
||||||
rgname=data['name'], conn=self.conn
|
rgname=data['name'], conn=self.conn
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -630,7 +631,7 @@ class ResourceGroupView(NodeView):
|
|||||||
sql += "\n-- Following query will be executed in a " \
|
sql += "\n-- Following query will be executed in a " \
|
||||||
"separate transaction\n"
|
"separate transaction\n"
|
||||||
sql += render_template(
|
sql += render_template(
|
||||||
"/".join([self.template_path, 'update.sql']),
|
"/".join([self.sql_path, 'update.sql']),
|
||||||
data=data, conn=self.conn
|
data=data, conn=self.conn
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -647,7 +648,7 @@ class ResourceGroupView(NodeView):
|
|||||||
rg_id: Resource Group ID
|
rg_id: Resource Group ID
|
||||||
"""
|
"""
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'properties.sql']), rgid=rg_id
|
"/".join([self.sql_path, 'properties.sql']), rgid=rg_id
|
||||||
)
|
)
|
||||||
status, res = self.conn.execute_dict(sql)
|
status, res = self.conn.execute_dict(sql)
|
||||||
if not status:
|
if not status:
|
||||||
@ -661,13 +662,13 @@ class ResourceGroupView(NodeView):
|
|||||||
old_data = dict(res['rows'][0])
|
old_data = dict(res['rows'][0])
|
||||||
|
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
"/".join([self.template_path, 'create.sql']),
|
"/".join([self.sql_path, 'create.sql']),
|
||||||
display_comments=True,
|
display_comments=True,
|
||||||
rgname=old_data['name'], conn=self.conn
|
rgname=old_data['name'], conn=self.conn
|
||||||
)
|
)
|
||||||
sql += "\n"
|
sql += "\n"
|
||||||
sql += render_template(
|
sql += render_template(
|
||||||
"/".join([self.template_path, 'update.sql']),
|
"/".join([self.sql_path, 'update.sql']),
|
||||||
data=old_data, conn=self.conn
|
data=old_data, conn=self.conn
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
-- RESOURCE GROUP: new_test_resql_resource_group
|
||||||
|
|
||||||
|
-- DROP RESOURCE GROUP new_test_resql_resource_group
|
||||||
|
|
||||||
|
CREATE RESOURCE GROUP new_test_resql_resource_group;
|
||||||
|
|
||||||
|
ALTER RESOURCE GROUP new_test_resql_resource_group
|
||||||
|
SET cpu_rate_limit = 0, dirty_rate_limit = 0;
|
@ -0,0 +1,8 @@
|
|||||||
|
-- RESOURCE GROUP: new_test_resql_resource_group
|
||||||
|
|
||||||
|
-- DROP RESOURCE GROUP new_test_resql_resource_group
|
||||||
|
|
||||||
|
CREATE RESOURCE GROUP new_test_resql_resource_group;
|
||||||
|
|
||||||
|
ALTER RESOURCE GROUP new_test_resql_resource_group
|
||||||
|
SET cpu_rate_limit = 1, dirty_rate_limit = 5;
|
@ -0,0 +1,8 @@
|
|||||||
|
-- RESOURCE GROUP: test_resql_resource_group
|
||||||
|
|
||||||
|
-- DROP RESOURCE GROUP test_resql_resource_group
|
||||||
|
|
||||||
|
CREATE RESOURCE GROUP test_resql_resource_group;
|
||||||
|
|
||||||
|
ALTER RESOURCE GROUP test_resql_resource_group
|
||||||
|
SET cpu_rate_limit = 0, dirty_rate_limit = 0;
|
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"prerequisite": {
|
||||||
|
"minVer": 90400,
|
||||||
|
"maxVer": null,
|
||||||
|
"type": "ppas"
|
||||||
|
},
|
||||||
|
"scenarios": [
|
||||||
|
{
|
||||||
|
"type": "create",
|
||||||
|
"name": "Create Resource groups",
|
||||||
|
"endpoint": "NODE-resource_group.obj",
|
||||||
|
"sql_endpoint": "NODE-resource_group.sql_id",
|
||||||
|
"data": {
|
||||||
|
"name": "test_resql_resource_group",
|
||||||
|
"cpu_rate_limit": 0,
|
||||||
|
"dirty_rate_limit": 0
|
||||||
|
},
|
||||||
|
"expected_sql_file": "create_resource_group.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Resource groups name",
|
||||||
|
"endpoint": "NODE-resource_group.obj_id",
|
||||||
|
"sql_endpoint": "NODE-resource_group.sql_id",
|
||||||
|
"data": {
|
||||||
|
"name": "new_test_resql_resource_group"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_resource_group_name.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Resource groups options",
|
||||||
|
"endpoint": "NODE-resource_group.obj_id",
|
||||||
|
"sql_endpoint": "NODE-resource_group.sql_id",
|
||||||
|
"data": {
|
||||||
|
"cpu_rate_limit": 1,
|
||||||
|
"dirty_rate_limit": 5
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_resource_group_options.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "delete",
|
||||||
|
"name": "Drop Resource groups",
|
||||||
|
"endpoint": "NODE-resource_group.obj_id",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
-- Role: test_resql_role_pg91
|
||||||
|
-- DROP ROLE test_resql_role_pg91;
|
||||||
|
|
||||||
|
CREATE ROLE test_resql_role_pg91 WITH
|
||||||
|
NOLOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE test_resql_role_pg91 IS 'This is detailed description';
|
@ -0,0 +1,12 @@
|
|||||||
|
-- Role: new_test_resql_role_pg91
|
||||||
|
-- DROP ROLE new_test_resql_role_pg91;
|
||||||
|
|
||||||
|
CREATE ROLE new_test_resql_role_pg91 WITH
|
||||||
|
NOLOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_role_pg91 IS 'This is detailed description';
|
@ -0,0 +1,15 @@
|
|||||||
|
-- Role: new_test_resql_role_pg91
|
||||||
|
-- DROP ROLE new_test_resql_role_pg91;
|
||||||
|
|
||||||
|
CREATE ROLE new_test_resql_role_pg91 WITH
|
||||||
|
NOLOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = new_test_resql_role_pg91;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_role_pg91 IS 'This is detailed description';
|
@ -0,0 +1,15 @@
|
|||||||
|
-- User: test_resql_user_pg91
|
||||||
|
-- DROP USER test_resql_user_pg91;
|
||||||
|
|
||||||
|
CREATE USER test_resql_user_pg91 WITH
|
||||||
|
LOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = test_resql_user_pg91;
|
||||||
|
|
||||||
|
COMMENT ON ROLE test_resql_user_pg91 IS 'This is detailed description';
|
@ -0,0 +1,15 @@
|
|||||||
|
-- User: new_test_resql_user_pg91
|
||||||
|
-- DROP USER new_test_resql_user_pg91;
|
||||||
|
|
||||||
|
CREATE USER new_test_resql_user_pg91 WITH
|
||||||
|
LOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = new_test_resql_user_pg91;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_user_pg91 IS 'This is detailed description';
|
@ -0,0 +1,12 @@
|
|||||||
|
-- User: new_test_resql_user_pg91
|
||||||
|
-- DROP USER new_test_resql_user_pg91;
|
||||||
|
|
||||||
|
CREATE USER new_test_resql_user_pg91 WITH
|
||||||
|
LOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_user_pg91 IS 'This is detailed description';
|
@ -0,0 +1,10 @@
|
|||||||
|
-- Role: test_resql_role_pg91
|
||||||
|
-- DROP ROLE test_resql_role_pg91;
|
||||||
|
|
||||||
|
CREATE ROLE test_resql_role_pg91 WITH
|
||||||
|
NOLOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
@ -0,0 +1,13 @@
|
|||||||
|
-- User: test_resql_user_pg91
|
||||||
|
-- DROP USER test_resql_user_pg91;
|
||||||
|
|
||||||
|
CREATE USER test_resql_user_pg91 WITH
|
||||||
|
LOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE pg_authid SET rolcatupdate=false WHERE rolname = test_resql_user_pg91;
|
@ -0,0 +1,124 @@
|
|||||||
|
{
|
||||||
|
"scenarios": [
|
||||||
|
{
|
||||||
|
"type": "create",
|
||||||
|
"name": "Create Role",
|
||||||
|
"endpoint": "NODE-role.obj",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "test_resql_role_pg91",
|
||||||
|
"rolcanlogin": false,
|
||||||
|
"rolpassword": null,
|
||||||
|
"rolconnlimit": -1,
|
||||||
|
"rolsuper": false,
|
||||||
|
"rolcreaterole": false,
|
||||||
|
"rolcreatedb": false,
|
||||||
|
"rolinherit": true,
|
||||||
|
"rolcatupdate": false,
|
||||||
|
"rolreplication": false,
|
||||||
|
"rolmembership": [],
|
||||||
|
"rolvaliduntil": null,
|
||||||
|
"seclabels": [],
|
||||||
|
"variables": []
|
||||||
|
},
|
||||||
|
"expected_sql_file": "create_role.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Role description",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"description": "This is detailed description"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_role_description.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Role name",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "new_test_resql_role_pg91"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_role_name.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Role superuser, createdb etc options",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolsuper": true,
|
||||||
|
"rolcreatedb": true
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_role_options.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "delete",
|
||||||
|
"name": "Drop Role",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"data": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "create",
|
||||||
|
"name": "Create User",
|
||||||
|
"endpoint": "NODE-role.obj",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "test_resql_user_pg91",
|
||||||
|
"rolcanlogin": true,
|
||||||
|
"rolpassword": null,
|
||||||
|
"rolconnlimit": -1,
|
||||||
|
"rolsuper": true,
|
||||||
|
"rolcreaterole": true,
|
||||||
|
"rolcreatedb": true,
|
||||||
|
"rolinherit": true,
|
||||||
|
"rolcatupdate": true,
|
||||||
|
"rolreplication": true,
|
||||||
|
"rolmembership": [],
|
||||||
|
"rolvaliduntil": null,
|
||||||
|
"seclabels": [],
|
||||||
|
"variables": []
|
||||||
|
},
|
||||||
|
"expected_sql_file": "create_user.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter User description",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"description": "This is detailed description"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_user_description.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter User name",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "new_test_resql_user_pg91"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_user_name.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter User superuser, createdb etc options",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolsuper": false,
|
||||||
|
"rolcreatedb": false
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_user_options.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "delete",
|
||||||
|
"name": "Drop User",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
-- Role: test_resql_role_pg95
|
||||||
|
-- DROP ROLE test_resql_role_pg95;
|
||||||
|
|
||||||
|
CREATE ROLE test_resql_role_pg95 WITH
|
||||||
|
NOLOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE test_resql_role_pg95 IS 'This is detailed description';
|
@ -0,0 +1,12 @@
|
|||||||
|
-- Role: new_test_resql_role_pg95
|
||||||
|
-- DROP ROLE new_test_resql_role_pg95;
|
||||||
|
|
||||||
|
CREATE ROLE new_test_resql_role_pg95 WITH
|
||||||
|
NOLOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_role_pg95 IS 'This is detailed description';
|
@ -0,0 +1,12 @@
|
|||||||
|
-- Role: new_test_resql_role_pg95
|
||||||
|
-- DROP ROLE new_test_resql_role_pg95;
|
||||||
|
|
||||||
|
CREATE ROLE new_test_resql_role_pg95 WITH
|
||||||
|
NOLOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_role_pg95 IS 'This is detailed description';
|
@ -0,0 +1,12 @@
|
|||||||
|
-- User: test_resql_user_pg95
|
||||||
|
-- DROP USER test_resql_user_pg95;
|
||||||
|
|
||||||
|
CREATE USER test_resql_user_pg95 WITH
|
||||||
|
LOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE test_resql_user_pg95 IS 'This is detailed description';
|
@ -0,0 +1,12 @@
|
|||||||
|
-- User: new_test_resql_user_pg95
|
||||||
|
-- DROP USER new_test_resql_user_pg95;
|
||||||
|
|
||||||
|
CREATE USER new_test_resql_user_pg95 WITH
|
||||||
|
LOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_user_pg95 IS 'This is detailed description';
|
@ -0,0 +1,12 @@
|
|||||||
|
-- User: new_test_resql_user_pg95
|
||||||
|
-- DROP USER new_test_resql_user_pg95;
|
||||||
|
|
||||||
|
CREATE USER new_test_resql_user_pg95 WITH
|
||||||
|
LOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
||||||
|
|
||||||
|
COMMENT ON ROLE new_test_resql_user_pg95 IS 'This is detailed description';
|
@ -0,0 +1,10 @@
|
|||||||
|
-- Role: test_resql_role_pg95
|
||||||
|
-- DROP ROLE test_resql_role_pg95;
|
||||||
|
|
||||||
|
CREATE ROLE test_resql_role_pg95 WITH
|
||||||
|
NOLOGIN
|
||||||
|
NOSUPERUSER
|
||||||
|
INHERIT
|
||||||
|
NOCREATEDB
|
||||||
|
NOCREATEROLE
|
||||||
|
NOREPLICATION;
|
@ -0,0 +1,10 @@
|
|||||||
|
-- User: test_resql_user_pg95
|
||||||
|
-- DROP USER test_resql_user_pg95;
|
||||||
|
|
||||||
|
CREATE USER test_resql_user_pg95 WITH
|
||||||
|
LOGIN
|
||||||
|
SUPERUSER
|
||||||
|
INHERIT
|
||||||
|
CREATEDB
|
||||||
|
CREATEROLE
|
||||||
|
REPLICATION;
|
@ -0,0 +1,124 @@
|
|||||||
|
{
|
||||||
|
"scenarios": [
|
||||||
|
{
|
||||||
|
"type": "create",
|
||||||
|
"name": "Create Role",
|
||||||
|
"endpoint": "NODE-role.obj",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "test_resql_role_pg95",
|
||||||
|
"rolcanlogin": false,
|
||||||
|
"rolpassword": null,
|
||||||
|
"rolconnlimit": -1,
|
||||||
|
"rolsuper": false,
|
||||||
|
"rolcreaterole": false,
|
||||||
|
"rolcreatedb": false,
|
||||||
|
"rolinherit": true,
|
||||||
|
"rolcatupdate": false,
|
||||||
|
"rolreplication": false,
|
||||||
|
"rolmembership": [],
|
||||||
|
"rolvaliduntil": null,
|
||||||
|
"seclabels": [],
|
||||||
|
"variables": []
|
||||||
|
},
|
||||||
|
"expected_sql_file": "create_role.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Role description",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"description": "This is detailed description"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_role_description.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Role name",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "new_test_resql_role_pg95"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_role_name.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter Role superuser, createdb etc options",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolsuper": true,
|
||||||
|
"rolcreatedb": true
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_role_options.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "delete",
|
||||||
|
"name": "Drop Role",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"data": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "create",
|
||||||
|
"name": "Create User",
|
||||||
|
"endpoint": "NODE-role.obj",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "test_resql_user_pg95",
|
||||||
|
"rolcanlogin": true,
|
||||||
|
"rolpassword": null,
|
||||||
|
"rolconnlimit": -1,
|
||||||
|
"rolsuper": true,
|
||||||
|
"rolcreaterole": true,
|
||||||
|
"rolcreatedb": true,
|
||||||
|
"rolinherit": true,
|
||||||
|
"rolcatupdate": true,
|
||||||
|
"rolreplication": true,
|
||||||
|
"rolmembership": [],
|
||||||
|
"rolvaliduntil": null,
|
||||||
|
"seclabels": [],
|
||||||
|
"variables": []
|
||||||
|
},
|
||||||
|
"expected_sql_file": "create_user.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter User description",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"description": "This is detailed description"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_user_description.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter User name",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolname": "new_test_resql_user_pg95"
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_user_name.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "alter",
|
||||||
|
"name": "Alter User superuser, createdb etc options",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"sql_endpoint": "NODE-role.sql_id",
|
||||||
|
"data": {
|
||||||
|
"rolsuper": false,
|
||||||
|
"rolcreatedb": false
|
||||||
|
},
|
||||||
|
"expected_sql_file": "alter_user_options.sql"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "delete",
|
||||||
|
"name": "Drop User",
|
||||||
|
"endpoint": "NODE-role.obj_id",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -991,6 +991,8 @@ def get_server_type(server):
|
|||||||
pg_cursor.execute("SELECT version()")
|
pg_cursor.execute("SELECT version()")
|
||||||
version_string = pg_cursor.fetchone()
|
version_string = pg_cursor.fetchone()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
if type(version_string) == tuple:
|
||||||
|
version_string = version_string[0]
|
||||||
|
|
||||||
if "Greenplum Database" in version_string:
|
if "Greenplum Database" in version_string:
|
||||||
return 'gpdb'
|
return 'gpdb'
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
# This software is released under the PostgreSQL Licence
|
# This software is released under the PostgreSQL Licence
|
||||||
#
|
#
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
from __future__ import print_function
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from pgadmin.utils.route import BaseTestGenerator
|
from pgadmin.utils.route import BaseTestGenerator
|
||||||
from regression.python_test_utils import test_utils as utils
|
from regression.python_test_utils import test_utils as utils
|
||||||
@ -64,6 +64,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
|
|||||||
def runTest(self):
|
def runTest(self):
|
||||||
# Create the module list on which reverse engineering sql test
|
# Create the module list on which reverse engineering sql test
|
||||||
# cases will be executed.
|
# cases will be executed.
|
||||||
|
server_info = self.server_information
|
||||||
resql_module_list = create_resql_module_list(
|
resql_module_list = create_resql_module_list(
|
||||||
BaseTestGenerator.re_sql_module_list,
|
BaseTestGenerator.re_sql_module_list,
|
||||||
BaseTestGenerator.exclude_pkgs)
|
BaseTestGenerator.exclude_pkgs)
|
||||||
@ -84,7 +85,68 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
|
|||||||
filename)
|
filename)
|
||||||
with open(complete_file_name) as jsonfp:
|
with open(complete_file_name) as jsonfp:
|
||||||
data = json.load(jsonfp)
|
data = json.load(jsonfp)
|
||||||
for key, scenarios in data.items():
|
# CHECK SERVER VERSION & TYPE PRECONDITION
|
||||||
|
flag = False
|
||||||
|
if 'prerequisite' in data and \
|
||||||
|
data['prerequisite'] is not None:
|
||||||
|
prerequisite_data = data['prerequisite']
|
||||||
|
|
||||||
|
module_str = module.replace('_', ' ').capitalize()
|
||||||
|
db_type = server_info['type'].upper()
|
||||||
|
min_ver = prerequisite_data['minVer']
|
||||||
|
max_ver = prerequisite_data['maxVer']
|
||||||
|
|
||||||
|
if 'type' in prerequisite_data and \
|
||||||
|
prerequisite_data['type']:
|
||||||
|
if server_info['type'] != \
|
||||||
|
prerequisite_data['type']:
|
||||||
|
flag = True
|
||||||
|
print(
|
||||||
|
"\n\n"
|
||||||
|
"{0} are not supported by {1} - "
|
||||||
|
"Skipped".format(
|
||||||
|
module_str,
|
||||||
|
db_type
|
||||||
|
),
|
||||||
|
file=sys.stderr
|
||||||
|
)
|
||||||
|
|
||||||
|
if 'minVer' in prerequisite_data and \
|
||||||
|
prerequisite_data['minVer']:
|
||||||
|
if server_info['server_version'] < \
|
||||||
|
prerequisite_data['minVer']:
|
||||||
|
if not flag:
|
||||||
|
flag = True
|
||||||
|
print(
|
||||||
|
"\n\n"
|
||||||
|
"{0} are not supported by"
|
||||||
|
" {1} server less than"
|
||||||
|
" {2} - Skipped".format(
|
||||||
|
module_str, db_type, min_ver
|
||||||
|
),
|
||||||
|
file=sys.stderr
|
||||||
|
)
|
||||||
|
|
||||||
|
if 'maxVer' in prerequisite_data and \
|
||||||
|
prerequisite_data['maxVer']:
|
||||||
|
if server_info['server_version'] > \
|
||||||
|
prerequisite_data['maxVer']:
|
||||||
|
if not flag:
|
||||||
|
flag = True
|
||||||
|
print(
|
||||||
|
"\n\n"
|
||||||
|
"{0} are not supported by"
|
||||||
|
" {1} server greater than"
|
||||||
|
" {2} - Skipped".format(
|
||||||
|
module_str, db_type, max_ver
|
||||||
|
),
|
||||||
|
file=sys.stderr
|
||||||
|
)
|
||||||
|
|
||||||
|
if not flag:
|
||||||
|
tests_scenarios = {}
|
||||||
|
tests_scenarios['scenarios'] = data['scenarios']
|
||||||
|
for key, scenarios in tests_scenarios.items():
|
||||||
self.execute_test_case(scenarios)
|
self.execute_test_case(scenarios)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@ -207,6 +269,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
|
|||||||
# Remove first and last double quotes
|
# Remove first and last double quotes
|
||||||
if resp_sql.startswith('"') and resp_sql.endswith('"'):
|
if resp_sql.startswith('"') and resp_sql.endswith('"'):
|
||||||
resp_sql = resp_sql[1:-1]
|
resp_sql = resp_sql[1:-1]
|
||||||
|
resp_sql = resp_sql.rstrip()
|
||||||
|
|
||||||
# Check if expected sql is given in JSON file or path of the output
|
# Check if expected sql is given in JSON file or path of the output
|
||||||
# file is given
|
# file is given
|
||||||
|
@ -444,6 +444,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Add the server version in server information
|
# Add the server version in server information
|
||||||
server_information['server_version'] = connection.server_version
|
server_information['server_version'] = connection.server_version
|
||||||
|
server_information['type'] = server['type']
|
||||||
|
|
||||||
# Drop the database if already exists.
|
# Drop the database if already exists.
|
||||||
test_utils.drop_database(connection, test_db_name)
|
test_utils.drop_database(connection, test_db_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user