public inbox for [email protected]  
help / color / mirror / Atom feed
Skip a RE-SQL test on the bases of precondition
2+ messages / 2 participants
[nested] [flat]

* Skip a RE-SQL test on the bases of precondition
@ 2019-07-17 06:43 Nagesh Dhope <[email protected]>
  2019-07-22 08:44 ` Re: Skip a RE-SQL test on the bases of precondition Dave Page <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Nagesh Dhope @ 2019-07-17 06:43 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,
Please find patch for skipping a RE-SQL test if precondition to execute
that test does not satisfy.

-- 
Thanks,
Nagesh


Attachments:

  [application/octet-stream] precondition_sql_in_resql.patch (8.8K, 3-precondition_sql_in_resql.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.4_plus/tests.json b/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.4_plus/tests.json
index 4f6fcfb..2ca0917 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.4_plus/tests.json
+++ b/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.4_plus/tests.json
@@ -10,7 +10,8 @@
         "schema": "test_extension_schema",
         "version": "1.0"
       },
-      "expected_sql_file": "create_extension_with_all_options.sql"
+      "expected_sql_file": "create_extension_with_all_options.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.0';"
     },
     {
       "type": "alter",
@@ -20,13 +21,15 @@
       "data": {
         "schema": "public"
       },
-      "expected_sql_file": "alter_extension_schema.sql"
+      "expected_sql_file": "alter_extension_schema.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.0';"
     },
     {
       "type": "delete",
       "name": "Drop Extension with all options",
       "endpoint": "NODE-extension.obj_id",
-      "data": {}
+      "data": {},
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.0';"
     },
     {
       "type": "create",
@@ -37,7 +40,8 @@
         "name": "citext",
         "version": "1.0"
       },
-      "expected_sql_file": "create_extension_with_default_schema.sql"
+      "expected_sql_file": "create_extension_with_default_schema.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='citext' and e2.version='1.0';"
     },
     {
       "type": "alter",
@@ -47,13 +51,15 @@
       "data": {
         "version": "1.1"
       },
-      "expected_sql_file": "alter_extension_version.sql"
+      "expected_sql_file": "alter_extension_version.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='citext' and e2.version='1.1';"
     },
     {
       "type": "delete",
       "name": "Drop Extension default schema",
       "endpoint": "NODE-extension.obj_id",
-      "data": {}
+      "data": {},
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='citext' and e2.version='1.1';"
     }
   ]
 }
diff --git a/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.5_plus/tests.json b/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.5_plus/tests.json
index bee44eb..db8452a 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.5_plus/tests.json
+++ b/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.5_plus/tests.json
@@ -10,7 +10,8 @@
         "schema": "test_extension_schema",
         "version": "1.0"
       },
-      "expected_sql_file": "create_extension_with_all_options.sql"
+      "expected_sql_file": "create_extension_with_all_options.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.0';"
     },
     {
       "type": "alter",
@@ -20,13 +21,15 @@
       "data": {
         "schema": "public"
       },
-      "expected_sql_file": "alter_extension_schema.sql"
+      "expected_sql_file": "alter_extension_schema.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.0';"
     },
     {
       "type": "delete",
       "name": "Drop Extension with all options",
       "endpoint": "NODE-extension.obj_id",
-      "data": {}
+      "data": {},
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.0';"
     }
   ]
 }
diff --git a/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.6_plus/tests.json b/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.6_plus/tests.json
index e50ee24..44fb0ec 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.6_plus/tests.json
+++ b/web/pgadmin/browser/server_groups/servers/databases/extensions/tests/9.6_plus/tests.json
@@ -10,7 +10,8 @@
         "schema": "test_extension_schema",
         "version": "1.2"
       },
-      "expected_sql_file": "create_extension_with_all_options.sql"
+      "expected_sql_file": "create_extension_with_all_options.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.2';"
     },
     {
       "type": "alter",
@@ -20,13 +21,15 @@
       "data": {
         "schema": "public"
       },
-      "expected_sql_file": "alter_extension_schema.sql"
+      "expected_sql_file": "alter_extension_schema.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.2';"
     },
     {
       "type": "delete",
       "name": "Drop Extension with all options",
       "endpoint": "NODE-extension.obj_id",
-      "data": {}
+      "data": {},
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='sslinfo' and e2.version='1.2';"
     },
     {
       "type": "create",
@@ -37,7 +40,8 @@
         "name": "adminpack",
         "version": "1.0"
       },
-      "expected_sql_file": "create_extension_with_default_schema.sql"
+      "expected_sql_file": "create_extension_with_default_schema.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='adminpack' and e2.version='1.0';"
     },
     {
       "type": "alter",
@@ -47,13 +51,15 @@
       "data": {
         "version": "1.1"
       },
-      "expected_sql_file": "alter_extension_version.sql"
+      "expected_sql_file": "alter_extension_version.sql",
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='adminpack' and e2.version='1.0';"
     },
     {
       "type": "delete",
       "name": "Drop Extension default schema",
       "endpoint": "NODE-extension.obj_id",
-      "data": {}
+      "data": {},
+      "precondition_sql": "select count(e1.name) \nfrom pg_available_extensions e1, pg_available_extension_versions e2\nwhere e1.name = e2.name and e1.name='adminpack' and e2.version='1.0';"
     }
   ]
 }
diff --git a/web/regression/re_sql/tests/test_resql.py b/web/regression/re_sql/tests/test_resql.py
index 56a98fa..490e02a 100644
--- a/web/regression/re_sql/tests/test_resql.py
+++ b/web/regression/re_sql/tests/test_resql.py
@@ -178,6 +178,11 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
         object_id = None
 
         for scenario in scenarios:
+            if 'precondition_sql' in scenario and \
+                    not self.check_precondition(scenario['precondition_sql']):
+                print(scenario['name'] + "... skipped")
+                continue
+
             if 'type' in scenario and scenario['type'] == 'create':
                 # Get the url and create the specific node.
 
@@ -451,3 +456,22 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
                 return False
 
         return True
+
+    def check_precondition(self, precondition_sql):
+        """
+        This method executes precondition_sql and returns appropriate result
+        :param precondition_sql: SQL query in format select count(*) from ...
+        :return: True/False depending on precondition_sql result
+        """
+        precondition_flag = False
+        self.get_db_connection()
+        pg_cursor = self.connection.cursor()
+        try:
+            pg_cursor.execute(precondition_sql)
+            precondition_result = pg_cursor.fetchone()
+            if len(precondition_result) >= 1 and precondition_result[0] == '1':
+                precondition_flag = True
+        except Exception as e:
+            traceback.print_exc()
+        pg_cursor.close()
+        return precondition_flag


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Skip a RE-SQL test on the bases of precondition
  2019-07-17 06:43 Skip a RE-SQL test on the bases of precondition Nagesh Dhope <[email protected]>
@ 2019-07-22 08:44 ` Dave Page <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2019-07-22 08:44 UTC (permalink / raw)
  To: Nagesh Dhope <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Sun, Jul 21, 2019 at 6:31 PM Nagesh Dhope <[email protected]>
wrote:

> Hi Hackers,
> Please find patch for skipping a RE-SQL test if precondition to execute
> that test does not satisfy.
>
> --
> Thanks,
> Nagesh
>


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-07-22 08:44 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 06:43 Skip a RE-SQL test on the bases of precondition Nagesh Dhope <[email protected]>
2019-07-22 08:44 ` Dave Page <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox