Add support for pre-condition SQL in RE-SQL testsuite,

and use it to ensure that the right extensions are installed for the
extension tests.
pull/25/head
Nagesh Dhope 2019-07-22 09:44:17 +01:00 committed by Dave Page
parent 4a6991d0df
commit 1813eca1ca
4 changed files with 55 additions and 15 deletions

View File

@ -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';"
}
]
}

View File

@ -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';"
}
]
}

View File

@ -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';"
}
]
}

View File

@ -181,6 +181,12 @@ 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 (pre-condition SQL not satisfied)")
continue
if 'type' in scenario and scenario['type'] == 'create':
# Get the url and create the specific node.
@ -460,3 +466,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