diff --git a/docs/en_US/release_notes_4_11.rst b/docs/en_US/release_notes_4_11.rst index c534f079e..9ffa95c5d 100644 --- a/docs/en_US/release_notes_4_11.rst +++ b/docs/en_US/release_notes_4_11.rst @@ -10,6 +10,8 @@ New features ************ | `Feature #4335 `_ - Add EXPLAIN options for SETTINGS and SUMMARY. +| `Feature #4415 `_ - Add Reverse Engineered SQL tests for Roles and Resource Groups. + Bug fixes ********* diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py b/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py index 9047b7f7f..05763e144 100644 --- a/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/resource_groups/__init__.py @@ -226,8 +226,9 @@ class ResourceGroupView(NodeView): "Connection to the server has been lost." ) ) - - self.template_path = 'resource_groups/sql' + self.sql_path = 'resource_groups/sql/#{0}#'.format( + self.manager.version + ) return f(*args, **kwargs) return wrap @@ -242,7 +243,7 @@ class ResourceGroupView(NodeView): gid: Server Group 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) if not status: @@ -263,7 +264,7 @@ class ResourceGroupView(NodeView): sid: Server ID """ - sql = render_template("/".join([self.template_path, 'nodes.sql']), + sql = render_template("/".join([self.sql_path, 'nodes.sql']), rgid=rg_id) status, result = self.conn.execute_2darray(sql) if not status: @@ -295,7 +296,7 @@ class ResourceGroupView(NodeView): sid: Server ID """ 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) if not status: return internal_server_error(errormsg=result) @@ -326,7 +327,7 @@ class ResourceGroupView(NodeView): rg_id: Resource Group ID """ 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) if not status: @@ -368,7 +369,7 @@ class ResourceGroupView(NodeView): try: # Below logic will create new resource group sql = render_template( - "/".join([self.template_path, 'create.sql']), + "/".join([self.sql_path, 'create.sql']), rgname=data['name'], conn=self.conn ) 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 # transaction. sql = render_template( - "/".join([self.template_path, 'update.sql']), + "/".join([self.sql_path, 'update.sql']), data=data, conn=self.conn ) # 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 # resource group sql = render_template( - "/".join([self.template_path, 'getoid.sql']), + "/".join([self.sql_path, 'getoid.sql']), rgname=data['name'] ) # Checking if we are not executing empty query @@ -431,7 +432,7 @@ class ResourceGroupView(NodeView): try: 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) if not status: return internal_server_error(errormsg=res) @@ -442,7 +443,7 @@ class ResourceGroupView(NodeView): if data['name'] != old_data['name']: sql = render_template( - "/".join([self.template_path, 'update.sql']), + "/".join([self.sql_path, 'update.sql']), oldname=old_data['name'], newname=data['name'], conn=self.conn ) @@ -458,7 +459,7 @@ class ResourceGroupView(NodeView): if data['cpu_rate_limit'] != old_data['cpu_rate_limit'] or \ data['dirty_rate_limit'] != old_data['dirty_rate_limit']: sql = render_template( - "/".join([self.template_path, 'update.sql']), + "/".join([self.sql_path, 'update.sql']), data=data, conn=self.conn ) if sql and sql.strip('\n') and sql.strip(' '): @@ -499,7 +500,7 @@ class ResourceGroupView(NodeView): for rg_id in data['ids']: # Get name for resource group from rg_id sql = render_template( - "/".join([self.template_path, 'delete.sql']), + "/".join([self.sql_path, 'delete.sql']), rgid=rg_id, conn=self.conn ) status, rgname = self.conn.execute_scalar(sql) @@ -520,7 +521,7 @@ class ResourceGroupView(NodeView): # drop resource group sql = render_template( - "/".join([self.template_path, 'delete.sql']), + "/".join([self.sql_path, 'delete.sql']), rgname=rgname, conn=self.conn ) status, res = self.conn.execute_scalar(sql) @@ -580,7 +581,7 @@ class ResourceGroupView(NodeView): ] if rg_id is not None: 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) if not status: return internal_server_error(errormsg=res) @@ -599,7 +600,7 @@ class ResourceGroupView(NodeView): if data['name'] != old_data['name']: name_changed = True sql = render_template( - "/".join([self.template_path, 'update.sql']), + "/".join([self.sql_path, 'update.sql']), oldname=old_data['name'], newname=data['name'], conn=self.conn ) @@ -609,12 +610,12 @@ class ResourceGroupView(NodeView): sql += "\n-- Following query will be executed in a " \ "separate transaction\n" sql += render_template( - "/".join([self.template_path, 'update.sql']), + "/".join([self.sql_path, 'update.sql']), data=data, conn=self.conn ) else: sql = render_template( - "/".join([self.template_path, 'create.sql']), + "/".join([self.sql_path, 'create.sql']), rgname=data['name'], conn=self.conn ) @@ -630,7 +631,7 @@ class ResourceGroupView(NodeView): sql += "\n-- Following query will be executed in a " \ "separate transaction\n" sql += render_template( - "/".join([self.template_path, 'update.sql']), + "/".join([self.sql_path, 'update.sql']), data=data, conn=self.conn ) @@ -647,7 +648,7 @@ class ResourceGroupView(NodeView): rg_id: Resource Group ID """ 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) if not status: @@ -661,13 +662,13 @@ class ResourceGroupView(NodeView): old_data = dict(res['rows'][0]) sql = render_template( - "/".join([self.template_path, 'create.sql']), + "/".join([self.sql_path, 'create.sql']), display_comments=True, rgname=old_data['name'], conn=self.conn ) sql += "\n" sql += render_template( - "/".join([self.template_path, 'update.sql']), + "/".join([self.sql_path, 'update.sql']), data=old_data, conn=self.conn ) diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/create.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/create.sql similarity index 100% rename from web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/create.sql rename to web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/create.sql diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/delete.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/delete.sql similarity index 100% rename from web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/delete.sql rename to web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/delete.sql diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/getoid.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/getoid.sql similarity index 100% rename from web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/getoid.sql rename to web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/getoid.sql diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/nodes.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/nodes.sql similarity index 100% rename from web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/nodes.sql rename to web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/nodes.sql diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/properties.sql similarity index 100% rename from web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/properties.sql rename to web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/properties.sql diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/update.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/update.sql similarity index 97% rename from web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/update.sql rename to web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/update.sql index 2b19e1083..e5c0a2343 100644 --- a/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/update.sql +++ b/web/pgadmin/browser/server_groups/servers/resource_groups/templates/resource_groups/sql/default/update.sql @@ -6,4 +6,4 @@ ALTER RESOURCE GROUP {{ conn|qtIdent(oldname) }} RENAME TO {{ conn|qtIdent(newna {% if data %} ALTER RESOURCE GROUP {{ conn|qtIdent(data.name) }} SET cpu_rate_limit = {{data.cpu_rate_limit|default(0)}}, dirty_rate_limit = {{data.dirty_rate_limit|default(0)}}; -{% endif %} \ No newline at end of file +{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/alter_resource_group_name.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/alter_resource_group_name.sql new file mode 100644 index 000000000..c774cbf5f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/alter_resource_group_name.sql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/alter_resource_group_options.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/alter_resource_group_options.sql new file mode 100644 index 000000000..fb21309d7 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/alter_resource_group_options.sql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/create_resource_group.sql b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/create_resource_group.sql new file mode 100644 index 000000000..3eb35a6a8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/create_resource_group.sql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/test.json b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/test.json new file mode 100644 index 000000000..030653612 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/resource_groups/tests/default/test.json @@ -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": {} + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_description.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_description.sql new file mode 100644 index 000000000..7879f300c --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_description.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_name.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_name.sql new file mode 100644 index 000000000..3122bd022 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_name.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_options.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_options.sql new file mode 100644 index 000000000..8d205ec69 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_role_options.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_description.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_description.sql new file mode 100644 index 000000000..e34aa4372 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_description.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_name.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_name.sql new file mode 100644 index 000000000..0f1078d44 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_name.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_options.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_options.sql new file mode 100644 index 000000000..8e6e636a7 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/alter_user_options.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/create_role.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/create_role.sql new file mode 100644 index 000000000..7f9bf63d6 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/create_role.sql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/create_user.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/create_user.sql new file mode 100644 index 000000000..12da84a17 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/create_user.sql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/test.json b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/test.json new file mode 100644 index 000000000..0e8c69940 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.1_plus/test.json @@ -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": {} + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_description.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_description.sql new file mode 100644 index 000000000..7be339864 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_description.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_name.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_name.sql new file mode 100644 index 000000000..563404c76 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_name.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_options.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_options.sql new file mode 100644 index 000000000..980bad230 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_role_options.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_description.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_description.sql new file mode 100644 index 000000000..2eed60257 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_description.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_name.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_name.sql new file mode 100644 index 000000000..07454a798 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_name.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_options.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_options.sql new file mode 100644 index 000000000..5035fbb91 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/alter_user_options.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/create_role.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/create_role.sql new file mode 100644 index 000000000..512164772 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/create_role.sql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/create_user.sql b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/create_user.sql new file mode 100644 index 000000000..476384fba --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/create_user.sql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/test.json b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/test.json new file mode 100644 index 000000000..e902b3ee8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/tests/9.4_plus/test.json @@ -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": {} + } + ] +} diff --git a/web/regression/python_test_utils/test_utils.py b/web/regression/python_test_utils/test_utils.py index 96a009bdf..74afc10bf 100644 --- a/web/regression/python_test_utils/test_utils.py +++ b/web/regression/python_test_utils/test_utils.py @@ -991,6 +991,8 @@ def get_server_type(server): pg_cursor.execute("SELECT version()") version_string = pg_cursor.fetchone() connection.close() + if type(version_string) == tuple: + version_string = version_string[0] if "Greenplum Database" in version_string: return 'gpdb' diff --git a/web/regression/re_sql/tests/test_resql.py b/web/regression/re_sql/tests/test_resql.py index 369c8ddf0..9f4d0125e 100644 --- a/web/regression/re_sql/tests/test_resql.py +++ b/web/regression/re_sql/tests/test_resql.py @@ -6,10 +6,10 @@ # This software is released under the PostgreSQL Licence # ########################################################################## - +from __future__ import print_function import json import os - +import sys from flask import url_for from pgadmin.utils.route import BaseTestGenerator from regression.python_test_utils import test_utils as utils @@ -64,6 +64,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator): def runTest(self): # Create the module list on which reverse engineering sql test # cases will be executed. + server_info = self.server_information resql_module_list = create_resql_module_list( BaseTestGenerator.re_sql_module_list, BaseTestGenerator.exclude_pkgs) @@ -84,8 +85,69 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator): filename) with open(complete_file_name) as jsonfp: data = json.load(jsonfp) - for key, scenarios in data.items(): - self.execute_test_case(scenarios) + # 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) def tearDown(self): database_utils.disconnect_database( @@ -207,6 +269,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator): # Remove first and last double quotes if resp_sql.startswith('"') and resp_sql.endswith('"'): 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 # file is given diff --git a/web/regression/runtests.py b/web/regression/runtests.py index 1d4fa54bb..cf9ab19c7 100644 --- a/web/regression/runtests.py +++ b/web/regression/runtests.py @@ -444,6 +444,7 @@ if __name__ == '__main__': # Add the server version in server information server_information['server_version'] = connection.server_version + server_information['type'] = server['type'] # Drop the database if already exists. test_utils.drop_database(connection, test_db_name)