From 3984544bdba29c87f6225061ed5577ebd2eb77e6 Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Fri, 28 Aug 2020 18:17:27 +0530 Subject: [PATCH] Fixed code smell 'String literals should not be duplicated'. --- .../browser/server_groups/servers/__init__.py | 7 +- .../servers/databases/schemas/__init__.py | 17 ++- .../databases/schemas/packages/__init__.py | 11 +- .../databases/schemas/sequences/__init__.py | 9 +- .../constraints/index_constraint/__init__.py | 40 +++---- web/pgadmin/tools/debugger/__init__.py | 102 ++++-------------- web/pgadmin/tools/grant_wizard/__init__.py | 14 ++- web/pgadmin/tools/sqleditor/__init__.py | 7 +- web/pgadmin/tools/sqleditor/command.py | 28 ++--- .../utils/is_query_resultset_updatable.py | 6 +- web/pgadmin/utils/constants.py | 2 + web/regression/feature_utils/locators.py | 3 + .../python_test_utils/test_gui_helper.py | 6 +- 13 files changed, 88 insertions(+), 164 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index 98bb1974d..18e7a55c1 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -30,7 +30,8 @@ from pgadmin.utils.exception import CryptKeyMissing from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry from psycopg2 import Error as psycopg2_Error, OperationalError from pgadmin.browser.server_groups.servers.utils import is_valid_ipaddress -from pgadmin.utils.constants import UNAUTH_REQ, MIMETYPE_APP_JS +from pgadmin.utils.constants import UNAUTH_REQ, MIMETYPE_APP_JS, \ + SERVER_CONNECTION_CLOSED def has_any(data, keys): @@ -1224,9 +1225,7 @@ class ServerNode(PGChildNodeView): else: return make_json_response(data={ 'status': False, - 'result': gettext( - 'Not connected to the server or the connection to the' - ' server has been closed.')}) + 'result': SERVER_CONNECTION_CLOSED}) def create_restore_point(self, gid, sid): """ diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py index 984b61cfd..68ac52fad 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py @@ -208,6 +208,7 @@ class SchemaView(PGChildNodeView): """ node_type = schema_blueprint.node_type _SQL_PREFIX = 'sql/' + node_icon = 'icon-%s' % node_type parent_ids = [ {'type': 'int', 'id': 'gid'}, @@ -455,8 +456,6 @@ class SchemaView(PGChildNodeView): if not status: return internal_server_error(errormsg=rset) - icon = 'icon-{0}'.format(self.node_type) - if scid is not None: if len(rset['rows']) == 0: return gone(gettext( @@ -468,7 +467,7 @@ class SchemaView(PGChildNodeView): row['oid'], did, row['name'], - icon=icon, + icon=self.node_icon, can_create=row['can_create'], has_usage=row['has_usage'] ), @@ -481,7 +480,7 @@ class SchemaView(PGChildNodeView): row['oid'], did, row['name'], - icon=icon, + icon=self.node_icon, can_create=row['can_create'], has_usage=row['has_usage'] ) @@ -523,15 +522,13 @@ Could not find the schema in the database. It may have been removed by another user. """)) - icon = 'icon-{0}'.format(self.node_type) - for row in rset['rows']: return make_json_response( data=self.blueprint.generate_browser_node( row['oid'], did, row['name'], - icon=icon, + icon=self.node_icon, can_create=row['can_create'], has_usage=row['has_usage'] ), @@ -635,14 +632,12 @@ It may have been removed by another user. if not status: return internal_server_error(errormsg=scid) - icon = 'icon-{0}'.format(self.node_type) - return jsonify( node=self.blueprint.generate_browser_node( scid, did, data['name'], - icon=icon + icon=self.node_icon ) ) except Exception as e: @@ -676,7 +671,7 @@ It may have been removed by another user. scid, did, name, - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) except Exception as e: diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py index 3c83d644e..a823d1d7a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/__init__.py @@ -83,6 +83,7 @@ blueprint = PackageModule(__name__) class PackageView(PGChildNodeView, SchemaDiffObjectCompare): node_type = blueprint.node_type node_label = "Package" + node_icon = "icon-%s" % node_type parent_ids = [ {'type': 'int', 'id': 'gid'}, @@ -223,7 +224,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare): row['oid'], scid, row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) @@ -233,7 +234,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare): row['oid'], scid, row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon )) return make_json_response( @@ -277,7 +278,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare): row['oid'], scid, row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon )) return make_json_response( @@ -409,7 +410,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare): pkgid, scid, data['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) @@ -516,7 +517,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare): pkgid, scid, name, - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py index 676855a43..b7f34a29e 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py @@ -91,6 +91,7 @@ blueprint = SequenceModule(__name__) class SequenceView(PGChildNodeView, SchemaDiffObjectCompare): node_type = blueprint.node_type node_label = "Sequence" + node_icon = "icon-%s" % node_type parent_ids = [ {'type': 'int', 'id': 'gid'}, @@ -216,7 +217,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare): row['oid'], scid, row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ), status=200 ) @@ -228,7 +229,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare): row['oid'], scid, row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon )) return make_json_response( @@ -437,7 +438,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare): row['oid'], row['relnamespace'], data['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) @@ -550,7 +551,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare): seid, row['schema'], row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py index 835a09dfe..4f601306e 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/__init__.py @@ -201,6 +201,8 @@ class IndexConstraintView(PGChildNodeView): node_label = _('Index constraint') + node_icon = "icon-%s" % node_type + parent_ids = [ {'type': 'int', 'id': 'gid'}, {'type': 'int', 'id': 'sid'}, @@ -287,10 +289,7 @@ class IndexConstraintView(PGChildNodeView): return res if len(res) == 0: - return gone(_("""Could not find the {} in the table.""").format( - _("primary key") if self.constraint_type == "p" - else _("unique key") - )) + return gone(self.key_not_found_error_msg()) result = res if cid: @@ -392,16 +391,13 @@ class IndexConstraintView(PGChildNodeView): return internal_server_error(errormsg=rset) if len(rset['rows']) == 0: - return gone(_("""Could not find the {} in the table.""").format( - _("primary key") if self.constraint_type == "p" - else _("unique key") - )) + return gone(self.key_not_found_error_msg()) res = self.blueprint.generate_browser_node( rset['rows'][0]['oid'], tid, rset['rows'][0]['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ) return make_json_response( data=res, @@ -441,7 +437,7 @@ class IndexConstraintView(PGChildNodeView): row['oid'], tid, row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) return make_json_response( @@ -486,7 +482,7 @@ class IndexConstraintView(PGChildNodeView): row['oid'], tid, row['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon )) return res @@ -627,7 +623,7 @@ class IndexConstraintView(PGChildNodeView): res['rows'][0]['oid'], tid, data['name'], - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) @@ -688,7 +684,7 @@ class IndexConstraintView(PGChildNodeView): cid, tid, name, - icon="icon-%s" % self.node_type + icon=self.node_icon ) ) except Exception as e: @@ -844,10 +840,7 @@ class IndexConstraintView(PGChildNodeView): if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone(_("""Could not find the {} in the table.""").format( - _("primary key") if self.constraint_type == "p" - else _("unique key") - )) + return gone(self.key_not_found_error_msg()) data = res['rows'][0] data['schema'] = self.schema @@ -936,12 +929,7 @@ class IndexConstraintView(PGChildNodeView): if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone( - _("""Could not find the {} in the table.""").format( - _("primary key") if self.constraint_type == "p" - else _("unique key") - ) - ) + return gone(self.key_not_found_error_msg()) result = res['rows'][0] name = result['name'] @@ -1010,6 +998,12 @@ class IndexConstraintView(PGChildNodeView): status=200 ) + def key_not_found_error_msg(self): + return _("""Could not find the {} in the table.""").format( + _("primary key") if self.constraint_type == "p" + else _("unique key") + ) + class PrimaryKeyConstraintView(IndexConstraintView): node_type = 'primary_key' diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py index 557223da2..b07a4de98 100644 --- a/web/pgadmin/tools/debugger/__init__.py +++ b/web/pgadmin/tools/debugger/__init__.py @@ -34,7 +34,7 @@ from pgadmin.tools.debugger.utils.debugger_instance import DebuggerInstance from pgadmin.browser.server_groups.servers.databases.extensions.utils \ import get_extension_details from pgadmin.utils.constants import PREF_LABEL_DISPLAY, \ - PREF_LABEL_KEYBOARD_SHORTCUTS, MIMETYPE_APP_JS + PREF_LABEL_KEYBOARD_SHORTCUTS, MIMETYPE_APP_JS, SERVER_CONNECTION_CLOSED MODULE_NAME = 'debugger' @@ -870,10 +870,7 @@ def restart_debugging(trans_id): return make_json_response( data={ 'status': False, - 'result': gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) @@ -913,10 +910,7 @@ def restart_debugging(trans_id): ) else: status = False - result = gettext( - 'Not connected to server or connection with the server has ' - 'been closed.' - ) + result = SERVER_CONNECTION_CLOSED return make_json_response(data={'status': status, 'result': result}) @@ -942,10 +936,7 @@ def start_debugger_listener(trans_id): return make_json_response( data={ 'status': False, - 'result': gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) @@ -1140,19 +1131,13 @@ def start_debugger_listener(trans_id): ) else: status = False - result = gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + result = SERVER_CONNECTION_CLOSED return make_json_response( data={'status': status, 'result': result} ) else: status = False - result = gettext( - 'Not connected to server or connection with the server has ' - 'been closed.' - ) + result = SERVER_CONNECTION_CLOSED return make_json_response(data={'status': status, 'result': result}) @@ -1185,10 +1170,7 @@ def execute_debugger_query(trans_id, query_type): return make_json_response( data={ 'status': False, - 'result': gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) @@ -1204,8 +1186,7 @@ def execute_debugger_query(trans_id, query_type): else DEBUGGER_SQL_V3_PATH if not conn.connected(): - result = gettext('Not connected to server or connection ' - 'with the server has been closed.') + result = SERVER_CONNECTION_CLOSED return internal_server_error(errormsg=result) sql = render_template( @@ -1264,10 +1245,7 @@ def messages(trans_id): return make_json_response( data={ 'status': 'NotConnected', - 'result': gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) @@ -1302,10 +1280,7 @@ def messages(trans_id): data={'status': status, 'result': port_number} ) else: - result = gettext( - 'Not connected to server or connection with the ' - 'server has been closed.' - ) + result = SERVER_CONNECTION_CLOSED return internal_server_error(errormsg=str(result)) @@ -1334,10 +1309,7 @@ def start_execution(trans_id, port_num): return make_json_response( data={ 'status': 'NotConnected', - 'result': gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) @@ -1414,10 +1386,7 @@ def set_clear_breakpoint(trans_id, line_no, set_type): return make_json_response( data={ 'status': False, - 'result': gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) @@ -1473,10 +1442,7 @@ def set_clear_breakpoint(trans_id, line_no, set_type): return internal_server_error(errormsg=result) else: status = False - result = gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + result = SERVER_CONNECTION_CLOSED return make_json_response( data={'status': status, 'result': result['rows']} @@ -1504,10 +1470,7 @@ def clear_all_breakpoint(trans_id): return make_json_response( data={ 'status': False, - 'result': gettext( - 'Not connected to server or connection ' - 'with the server has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( @@ -1543,9 +1506,7 @@ def clear_all_breakpoint(trans_id): return make_json_response(data={'status': False}) else: status = False - result = gettext( - 'Not connected to server or connection with the server has ' - 'been closed.') + result = SERVER_CONNECTION_CLOSED return make_json_response( data={'status': status, 'result': result['rows']} @@ -1573,8 +1534,7 @@ def deposit_parameter_value(trans_id): return make_json_response( data={ 'status': False, - 'result': gettext('Not connected to server or connection ' - 'with the server has been closed.') + 'result': SERVER_CONNECTION_CLOSED } ) manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( @@ -1622,10 +1582,7 @@ def deposit_parameter_value(trans_id): ) else: status = False - result = gettext( - 'Not connected to server or connection with the server has ' - 'been closed.' - ) + result = SERVER_CONNECTION_CLOSED return make_json_response(data={'status': status, 'result': result}) @@ -1652,10 +1609,7 @@ def select_frame(trans_id, frame_id): return make_json_response( data={ 'status': False, - 'result': gettext( - 'Not connected to server or connection ' - 'with the server has been closed.' - ) + 'result': SERVER_CONNECTION_CLOSED } ) @@ -1688,10 +1642,7 @@ def select_frame(trans_id, frame_id): return internal_server_error(errormsg=result) else: status = False - result = gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + result = SERVER_CONNECTION_CLOSED return make_json_response( data={'status': status, 'result': result['rows']} @@ -1969,9 +1920,7 @@ def poll_end_execution_result(trans_id): if de_inst.debugger_data is None: return make_json_response( data={'status': 'NotConnected', - 'result': gettext( - 'Not connected to server or connection with the ' - 'server has been closed.') + 'result': SERVER_CONNECTION_CLOSED } ) @@ -2070,8 +2019,7 @@ def poll_end_execution_result(trans_id): ) else: status = 'NotConnected' - result = gettext('Not connected to server or connection with the ' - 'server has been closed.') + result = SERVER_CONNECTION_CLOSED return make_json_response(data={'status': status, 'result': result}) @@ -2097,8 +2045,7 @@ def poll_result(trans_id): return make_json_response( data={ 'status': 'NotConnected', - 'result': gettext('Not connected to server or connection ' - 'with the server has been closed.') + 'result': SERVER_CONNECTION_CLOSED } ) @@ -2119,10 +2066,7 @@ def poll_result(trans_id): status = 'Busy' else: status = 'NotConnected' - result = gettext( - 'Not connected to server or connection with the server ' - 'has been closed.' - ) + result = SERVER_CONNECTION_CLOSED return make_json_response( data={ diff --git a/web/pgadmin/tools/grant_wizard/__init__.py b/web/pgadmin/tools/grant_wizard/__init__.py index 3431fc882..ee62c4c6a 100644 --- a/web/pgadmin/tools/grant_wizard/__init__.py +++ b/web/pgadmin/tools/grant_wizard/__init__.py @@ -184,6 +184,10 @@ def properties(sid, did, node_id, node_type): """It fetches the properties of object types and render into selection page of wizard """ + + function_sql_url = '/sql/function.sql' + get_schema_sql_url = '/sql/get_schemas.sql' + # unquote encoded url parameter node_type = unquote(node_type) @@ -201,7 +205,7 @@ def properties(sid, did, node_id, node_type): # Get sys_obj_values and get list of schemas ntype = 'schema' sql = render_template("/".join( - [server_prop['template_path'], '/sql/get_schemas.sql']), + [server_prop['template_path'], get_schema_sql_url]), show_sysobj=show_sysobj) status, res = conn.execute_dict(sql) @@ -210,7 +214,7 @@ def properties(sid, did, node_id, node_type): node_types = res['rows'] else: sql = render_template("/".join( - [server_prop['template_path'], '/sql/get_schemas.sql']), + [server_prop['template_path'], get_schema_sql_url]), nspid=node_id, show_sysobj=False) status, res = conn.execute_dict(sql) @@ -226,7 +230,7 @@ def properties(sid, did, node_id, node_type): # Fetch functions against schema if ntype in ['schema', 'function']: sql = render_template("/".join( - [server_prop['template_path'], '/sql/function.sql']), + [server_prop['template_path'], function_sql_url]), node_id=node_id, type='function') status, res = conn.execute_dict(sql) @@ -243,7 +247,7 @@ def properties(sid, did, node_id, node_type): server_prop['version'] >= 11000)) and ntype in ['schema', 'procedure']): sql = render_template("/".join( - [server_prop['template_path'], '/sql/function.sql']), + [server_prop['template_path'], function_sql_url]), node_id=node_id, type='procedure') status, res = conn.execute_dict(sql) @@ -257,7 +261,7 @@ def properties(sid, did, node_id, node_type): # Fetch trigger functions if ntype in ['schema', 'trigger_function']: sql = render_template("/".join( - [server_prop['template_path'], '/sql/function.sql']), + [server_prop['template_path'], function_sql_url]), node_id=node_id, type='trigger_function') status, res = conn.execute_dict(sql) diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index ec0395bfc..9f08e472f 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -44,7 +44,7 @@ from pgadmin.tools.sqleditor.utils.query_tool_fs_utils import \ read_file_generator from pgadmin.tools.sqleditor.utils.filter_dialog import FilterDialog from pgadmin.tools.sqleditor.utils.query_history import QueryHistory -from pgadmin.utils.constants import MIMETYPE_APP_JS +from pgadmin.utils.constants import MIMETYPE_APP_JS, SERVER_CONNECTION_CLOSED MODULE_NAME = 'sqleditor' @@ -964,10 +964,7 @@ def _check_and_cancel_transaction(trans_obj, delete_connection, conn, manager): manager.release(did=trans_obj.did) else: status = False - result = gettext( - 'Not connected to server or connection with the server has ' - 'been closed.' - ) + result = SERVER_CONNECTION_CLOSED return status, result diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py index 1fa7dfe7a..0664be510 100644 --- a/web/pgadmin/tools/sqleditor/command.py +++ b/web/pgadmin/tools/sqleditor/command.py @@ -23,7 +23,7 @@ from pgadmin.tools.sqleditor.utils.save_changed_data import save_changed_data from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types from pgadmin.utils.preferences import Preferences from pgadmin.utils.exception import ObjectGone, ExecuteError - +from pgadmin.utils.constants import SERVER_CONNECTION_CLOSED from config import PG_DEFAULT_DRIVER VIEW_FIRST_100_ROWS = 1 @@ -196,10 +196,7 @@ class SQLFilter(object): self.nsp_name = result['rows'][0]['nspname'] self.object_name = result['rows'][0]['relname'] else: - raise InternalServerError(gettext( - 'Not connected to server or connection with the server ' - 'has been closed.') - ) + raise InternalServerError(SERVER_CONNECTION_CLOSED) def get_filter(self): """ @@ -407,10 +404,8 @@ class GridCommand(BaseCommand, SQLFilter, FetchedRowTracker): for row in result['rows']: all_columns.append(row['attname']) else: - raise InternalServerError( - gettext('Not connected to server or connection with the ' - 'server has been closed.') - ) + raise InternalServerError(SERVER_CONNECTION_CLOSED) + # If user has custom data sorting then pass as it as it is if data_sorting and len(data_sorting) > 0: all_sorted_columns = data_sorting @@ -553,10 +548,7 @@ class TableCommand(GridCommand): # Remove last character from the string pk_names = pk_names[:-1] else: - raise InternalServerError( - gettext('Not connected to server or connection with the ' - 'server has been closed.') - ) + raise InternalServerError(SERVER_CONNECTION_CLOSED) return pk_names, primary_keys @@ -650,10 +642,7 @@ class TableCommand(GridCommand): raise ExecuteError(has_oids) else: - raise InternalServerError( - gettext('Not connected to server or connection with the ' - 'server has been closed.') - ) + raise InternalServerError(SERVER_CONNECTION_CLOSED) return has_oids @@ -1002,7 +991,4 @@ class QueryToolCommand(BaseCommand, FetchedRowTracker): self.nsp_name = result['rows'][0]['nspname'] self.object_name = result['rows'][0]['relname'] else: - raise InternalServerError(gettext( - 'Not connected to server or connection with the server ' - 'has been closed.') - ) + raise InternalServerError(SERVER_CONNECTION_CLOSED) diff --git a/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py b/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py index 4270b0289..013c05da8 100644 --- a/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py +++ b/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py @@ -28,6 +28,7 @@ from werkzeug.exceptions import InternalServerError from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types from pgadmin.utils.exception import ExecuteError +from pgadmin.utils.constants import SERVER_CONNECTION_CLOSED def is_query_resultset_updatable(conn, sql_path): @@ -86,10 +87,7 @@ def is_query_resultset_updatable(conn, sql_path): _set_all_columns_not_editable(columns_info=columns_info) return return_not_updatable() else: - raise InternalServerError( - gettext('Not connected to server or connection with the ' - 'server has been closed.') - ) + raise InternalServerError(SERVER_CONNECTION_CLOSED) def _check_single_table(columns_info): diff --git a/web/pgadmin/utils/constants.py b/web/pgadmin/utils/constants.py index 18311de1d..88ae50de2 100644 --- a/web/pgadmin/utils/constants.py +++ b/web/pgadmin/utils/constants.py @@ -27,3 +27,5 @@ PREF_LABEL_SQL_FORMATTING = gettext('SQL formatting') PGADMIN_NODE = 'pgadmin.node.%s' UNAUTH_REQ = "Unauthorized request." +SERVER_CONNECTION_CLOSED = gettext( + 'Not connected to server or connection with the server has been closed.') diff --git a/web/regression/feature_utils/locators.py b/web/regression/feature_utils/locators.py index 7853e1007..964a9fb66 100644 --- a/web/regression/feature_utils/locators.py +++ b/web/regression/feature_utils/locators.py @@ -103,6 +103,9 @@ class NavMenuLocators: "//*[contains(@class,'wcTabTop')]//*[contains(@class,'wcPanelTab') " \ "and contains(.,'{}')]" + process_watcher_error_close_xpath = \ + ".btn.btn-sm-sq.btn-primary.pg-bg-close > i" + class QueryToolLocators: btn_save_file = "#btn-save-file" diff --git a/web/regression/python_test_utils/test_gui_helper.py b/web/regression/python_test_utils/test_gui_helper.py index da070141a..de6976921 100644 --- a/web/regression/python_test_utils/test_gui_helper.py +++ b/web/regression/python_test_utils/test_gui_helper.py @@ -20,7 +20,7 @@ def close_bgprocess_popup(tester): ".ajs-message.ajs-bg-bgprocess.ajs-visible")) except Exception: tester.driver.find_element_by_css_selector( - ".btn.btn-sm-sq.btn-primary.pg-bg-close > i").click() + NavMenuLocators.process_watcher_error_close_xpath).click() # In cases where restore div is not closed (sometime due to some error) try: @@ -30,7 +30,7 @@ def close_bgprocess_popup(tester): "[contains(text(), 'Restoring backup')]")) except Exception: tester.driver.find_element_by_css_selector( - ".btn.btn-sm-sq.btn-primary.pg-bg-close > i").click() + NavMenuLocators.process_watcher_error_close_xpath).click() # In cases where maintenance window is not closed (sometime due to some # error) @@ -41,7 +41,7 @@ def close_bgprocess_popup(tester): "[contains(text(), 'Maintenance')]")) except Exception: tester.driver.find_element_by_css_selector( - ".btn.btn-sm-sq.btn-primary.pg-bg-close > i").click() + NavMenuLocators.process_watcher_error_close_xpath).click() def close_process_watcher(tester):