diff --git a/web/config.py b/web/config.py index d4ddd9db..40c9a164 100644 --- a/web/config.py +++ b/web/config.py @@ -20,7 +20,6 @@ if sys.version_info[0] >= 3: else: import __builtin__ as builtins - # We need to include the root directory in sys.path to ensure that we can # find everything we need when running in the standalone runtime. root = os.path.dirname(os.path.realpath(__file__)) @@ -98,7 +97,6 @@ MODULE_BLACKLIST = ['test'] # List of treeview browser nodes to skip when dynamically loading NODE_BLACKLIST = [] - ########################################################################## # Server settings ########################################################################## @@ -170,7 +168,6 @@ else: else: DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) - ########################################################################## # Log settings ########################################################################## @@ -200,7 +197,6 @@ if SERVER_MODE and not IS_WIN: else: LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') - ########################################################################## # Server Connection Driver Settings ########################################################################## @@ -309,7 +305,6 @@ UPGRADE_CHECK_URL = 'https://www.pgadmin.org/versions.json' ########################################################################## STORAGE_DIR = os.path.join(DATA_DIR, 'storage') - ########################################################################## # Default locations for binary utilities (pg_dump, pg_restore etc) # @@ -326,7 +321,7 @@ STORAGE_DIR = os.path.join(DATA_DIR, 'storage') # ########################################################################## DEFAULT_BINARY_PATHS = { - "pg": "", + "pg": "", "ppas": "", "gpdb": "" } @@ -338,7 +333,6 @@ DEFAULT_BINARY_PATHS = { # The default path for SQLite database for testing TEST_SQLITE_PATH = os.path.join(DATA_DIR, 'test_pgadmin4.db') - ########################################################################## # Allows flask application to response to the each request asynchronously ########################################################################## diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 6990d149..138ce696 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -42,6 +42,7 @@ if config.DEBUG: # Get the config database schema version. We store this in pgadmin.model # as it turns out that putting it in the config files isn't a great idea from pgadmin.model import SCHEMA_VERSION + config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION ########################################################################## @@ -54,7 +55,7 @@ if not os.path.isfile(config.SQLITE_PATH): os.path.dirname(os.path.realpath(u(__file__, fs_encoding))), u'setup.py' ) - exec(open(file_quote(setupfile), 'r').read()) + exec (open(file_quote(setupfile), 'r').read()) ########################################################################## # Server startup @@ -137,6 +138,7 @@ if __name__ == '__main__': # # Setting PYTHONHOME launch them properly. from pgadmin.utils import IS_WIN + if IS_WIN: os.environ['PYTHONHOME'] = sys.prefix @@ -150,8 +152,8 @@ if __name__ == '__main__': host=config.DEFAULT_SERVER, port=server_port, use_reloader=( - (not PGADMIN_RUNTIME) and app.debug - and os.environ.get("WERKZEUG_RUN_MAIN") is not None + (not PGADMIN_RUNTIME) and app.debug and + os.environ.get("WERKZEUG_RUN_MAIN") is not None ), threaded=config.THREADED_MODE ) diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index 90ecf99b..3546f3d3 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -18,23 +18,20 @@ from importlib import import_module from flask import Flask, abort, request, current_app, session, url_for from flask_babel import Babel, gettext from flask_login import user_logged_in, user_logged_out -from flask_security import Security, SQLAlchemyUserDatastore, current_user from flask_mail import Mail +from flask_paranoid import Paranoid +from flask_security import Security, SQLAlchemyUserDatastore, current_user from flask_security.utils import login_user from werkzeug.datastructures import ImmutableDict -from flask_paranoid import Paranoid - -from pgadmin.utils import PgAdminModule, driver -from pgadmin.utils.versioned_template_loader import VersionedTemplateLoader -from pgadmin.utils.session import create_session_interface, pga_unauthorised from werkzeug.local import LocalProxy from werkzeug.utils import find_modules -from pgadmin.utils.preferences import Preferences - from pgadmin.model import db, Role, Server, ServerGroup, \ User, Keys, Version, SCHEMA_VERSION as CURRENT_SCHEMA_VERSION - +from pgadmin.utils import PgAdminModule, driver +from pgadmin.utils.preferences import Preferences +from pgadmin.utils.session import create_session_interface, pga_unauthorised +from pgadmin.utils.versioned_template_loader import VersionedTemplateLoader # If script is running under python3, it will not have the xrange function # defined @@ -169,7 +166,6 @@ current_blueprint = LocalProxy(_find_blueprint) def create_app(app_name=None): - # Configuration settings import config if not app_name: @@ -217,8 +213,10 @@ def create_app(app_name=None): logger.setLevel(logging.INFO) # Set SQLITE_PATH to TEST_SQLITE_PATH while running test cases - if "PGADMIN_TESTING_MODE" in os. environ and \ - os.environ["PGADMIN_TESTING_MODE"] == "1": + if ( + 'PGADMIN_TESTING_MODE' in os.environ and + os.environ['PGADMIN_TESTING_MODE'] == '1' + ): config.SQLITE_PATH = config.TEST_SQLITE_PATH # Ensure the various working directories exist @@ -291,7 +289,7 @@ def create_app(app_name=None): # Setup authentication ########################################################################## - app.config['SQLALCHEMY_DATABASE_URI'] = u'sqlite:///{0}?timeout={1}'\ + app.config['SQLALCHEMY_DATABASE_URI'] = u'sqlite:///{0}?timeout={1}' \ .format(config.SQLITE_PATH.replace(u'\\', u'/'), getattr(config, 'SQLITE_TIMEOUT', 500) ) @@ -406,6 +404,7 @@ def create_app(app_name=None): servergroup_id = servergroup.id '''Add a server to the config database''' + def add_server(user_id, servergroup_id, name, superuser, port, discovery_id, comment): # Create a server object if needed, and store it. @@ -503,8 +502,10 @@ def create_app(app_name=None): # Loop the sections, and get the data from any that are PG or PPAS for section in sections: - if section.startswith('PostgreSQL/') \ - or section.startswith('EnterpriseDB/'): + if ( + section.startswith('PostgreSQL/') or + section.startswith('EnterpriseDB/') + ): svr_name = registry.get(section, 'Description') svr_superuser = registry.get(section, 'Superuser') svr_port = registry.getint(section, 'Port') @@ -516,9 +517,9 @@ def create_app(app_name=None): data_directory = data_directory.decode('utf-8') svr_comment = gettext(u"Auto-detected %s installation " u"with the data directory at %s" % ( - description, - data_directory - ) + description, + data_directory + ) ) add_server(user_id, servergroup_id, svr_name, svr_superuser, svr_port, svr_discovery_id, @@ -552,7 +553,7 @@ def create_app(app_name=None): if not config.SERVER_MODE and app.PGADMIN_KEY != '': if ( ('key' not in request.args or - request.args['key'] != app.PGADMIN_KEY) and + request.args['key'] != app.PGADMIN_KEY) and request.cookies.get('PGADMIN_KEY') != app.PGADMIN_KEY and request.endpoint != 'help.static' ): diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index dd2542fb..a12edc69 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -10,33 +10,33 @@ import json import logging from abc import ABCMeta, abstractmethod, abstractproperty -import six -from socket import error as SOCKETErrorException -from smtplib import SMTPConnectError, SMTPResponseException,\ +from smtplib import SMTPConnectError, SMTPResponseException, \ SMTPServerDisconnected, SMTPDataError, SMTPHeloError, SMTPException, \ SMTPAuthenticationError, SMTPSenderRefused, SMTPRecipientsRefused +from socket import error as SOCKETErrorException + +import six from flask import current_app, render_template, url_for, make_response, \ flash, Response, request, after_this_request, redirect from flask_babel import gettext -from flask_login import current_user, login_required -from flask_security.decorators import anonymous_user_required from flask_gravatar import Gravatar -from pgadmin.settings import get_setting -from pgadmin.utils import PgAdminModule -from pgadmin.utils.ajax import make_json_response -from pgadmin.utils.preferences import Preferences -from werkzeug.datastructures import MultiDict -from flask_security.views import _security, _commit, _render_json, _ctx +from flask_login import current_user, login_required from flask_security.changeable import change_user_password +from flask_security.decorators import anonymous_user_required from flask_security.recoverable import reset_password_token_status, \ generate_reset_password_token, update_password -from flask_security.utils import config_value, do_flash, get_url, get_message,\ - slash_url_suffix, login_user, send_mail from flask_security.signals import reset_password_instructions_sent - +from flask_security.utils import config_value, do_flash, get_url, \ + get_message, slash_url_suffix, login_user, send_mail +from flask_security.views import _security, _commit, _render_json, _ctx +from werkzeug.datastructures import MultiDict import config from pgadmin import current_blueprint +from pgadmin.settings import get_setting +from pgadmin.utils import PgAdminModule +from pgadmin.utils.ajax import make_json_response +from pgadmin.utils.preferences import Preferences try: import urllib.request as urlreq @@ -51,17 +51,19 @@ class BrowserModule(PgAdminModule): def get_own_stylesheets(self): stylesheets = [] + context_menu_file = 'vendor/jQuery-contextMenu/' \ + 'jquery.contextMenu.min.css' + wcdocker_file = 'vendor/wcDocker/wcDocker.min.css' + if current_app.debug: + context_menu_file = 'vendor/jQuery-contextMenu/' \ + 'jquery.contextMenu.css' + wcdocker_file = 'vendor/wcDocker/wcDocker.css' # Add browser stylesheets for (endpoint, filename) in [ ('static', 'vendor/codemirror/codemirror.css'), ('static', 'vendor/codemirror/addon/dialog/dialog.css'), - ('static', 'vendor/jQuery-contextMenu/jquery.contextMenu.css' - if current_app.debug - else - 'vendor/jQuery-contextMenu/jquery.contextMenu.min.css'), - ('static', 'vendor/wcDocker/wcDocker.css' - if current_app.debug - else 'vendor/wcDocker/wcDocker.min.css'), + ('static', context_menu_file), + ('static', wcdocker_file), ('browser.static', 'css/browser.css'), ('browser.static', 'vendor/aciTree/css/aciTree.css') ]: @@ -86,8 +88,8 @@ class BrowserModule(PgAdminModule): 'path': url_for( 'static', filename='vendor/jQuery-contextMenu/jquery.ui.position' if - current_app.debug else - 'vendor/jQuery-contextMenu/jquery.ui.position.min' + current_app.debug else + 'vendor/jQuery-contextMenu/jquery.ui.position.min' ), 'deps': ['jquery'], 'exports': 'jQuery.ui.position', @@ -98,8 +100,8 @@ class BrowserModule(PgAdminModule): 'path': url_for( 'static', filename='vendor/jQuery-contextMenu/jquery.contextMenu' if - current_app.debug else - 'vendor/jQuery-contextMenu/jquery.contextMenu.min' + current_app.debug else + 'vendor/jQuery-contextMenu/jquery.contextMenu.min' ), 'deps': ['jquery', 'jqueryui.position'], 'exports': 'jQuery.contextMenu', @@ -167,9 +169,10 @@ class BrowserModule(PgAdminModule): }) for name, script in [ - ['pgadmin.browser', 'js/browser'], - ['pgadmin.browser.endpoints', 'js/endpoints'], - ['pgadmin.browser.error', 'js/error']]: + ['pgadmin.browser', 'js/browser'], + ['pgadmin.browser.endpoints', 'js/endpoints'], + ['pgadmin.browser.error', 'js/error'] + ]: scripts.append({ 'name': name, 'path': url_for('browser.index') + script, @@ -177,9 +180,10 @@ class BrowserModule(PgAdminModule): }) for name, script in [ - ['pgadmin.browser.node', 'js/node'], - ['pgadmin.browser.messages', 'js/messages'], - ['pgadmin.browser.collection', 'js/collection']]: + ['pgadmin.browser.node', 'js/node'], + ['pgadmin.browser.messages', 'js/messages'], + ['pgadmin.browser.collection', 'js/collection'] + ]: scripts.append({ 'name': name, 'path': url_for('browser.index') + script, @@ -188,9 +192,10 @@ class BrowserModule(PgAdminModule): }) for name, end in [ - ['pgadmin.browser.menu', 'js/menu'], - ['pgadmin.browser.panel', 'js/panel'], - ['pgadmin.browser.frame', 'js/frame']]: + ['pgadmin.browser.menu', 'js/menu'], + ['pgadmin.browser.panel', 'js/panel'], + ['pgadmin.browser.frame', 'js/frame'] + ]: scripts.append({ 'name': name, 'path': url_for('browser.static', filename=end), 'preloaded': True}) @@ -582,7 +587,7 @@ class BrowserPluginModule(PgAdminModule): return scripts def generate_browser_node( - self, node_id, parent_id, label, icon, inode, node_type, **kwargs + self, node_id, parent_id, label, icon, inode, node_type, **kwargs ): """ Helper function to create a browser node for this particular subnode. @@ -950,6 +955,7 @@ def get_nodes(): return make_json_response(data=nodes) + # Only register route if SECURITY_CHANGEABLE is set to True # We can't access app context here so cannot # use app.config['SECURITY_CHANGEABLE'] @@ -1019,7 +1025,6 @@ if hasattr(config, 'SECURITY_CHANGEABLE') and config.SECURITY_CHANGEABLE: change_password_form=form, **_ctx('change_password')) - # Only register route if SECURITY_RECOVERABLE is set to True if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE: diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py index 3438d451..dc465b0c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py @@ -9,26 +9,26 @@ """Implements the Database Node""" -import simplejson as json import re from functools import wraps -import pgadmin.browser.server_groups.servers as servers +import simplejson as json from flask import render_template, current_app, request, jsonify from flask_babel import gettext as _ + +import pgadmin.browser.server_groups.servers as servers +from config import PG_DEFAULT_DRIVER from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.server_groups.servers.databases.utils import \ parse_sec_labels_from_db, parse_variables_from_db from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ parse_priv_to_db from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils.ajax import gone from pgadmin.utils.ajax import make_json_response, \ make_response as ajax_response, internal_server_error, unauthorized -from pgadmin.utils.ajax import gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER - class DatabaseModule(CollectionNodeModule): NODE_TYPE = 'database' @@ -201,10 +201,7 @@ class DatabaseView(PGChildNodeView): @check_precondition(action="list") def list(self, gid, sid): - last_system_oid = 0 if self.blueprint.show_system_objects else \ - (self.manager.db_info[self.manager.did])['datlastsysoid'] \ - if self.manager.db_info is not None and \ - self.manager.did in self.manager.db_info else 0 + last_system_oid = self.retrieve_last_system_oid() db_disp_res = None params = None @@ -230,14 +227,21 @@ class DatabaseView(PGChildNodeView): status=200 ) + def retrieve_last_system_oid(self): + last_system_oid = 0 + if self.blueprint.show_system_objects: + last_system_oid = 0 + elif ( + self.manager.db_info is not None and + self.manager.did in self.manager.db_info + ): + last_system_oid = (self.manager.db_info[self.manager.did])[ + 'datlastsysoid'] + return last_system_oid + def get_nodes(self, gid, sid, show_system_templates=False): res = [] - last_system_oid = 0 if self.blueprint.show_system_objects or \ - show_system_templates else ( - (self.manager.db_info[self.manager.did])['datlastsysoid'] - if self.manager.db_info is not None and - self.manager.did in self.manager.db_info else 0 - ) + last_system_oid = self.retrieve_last_system_oid() server_node_res = self.manager db_disp_res = None @@ -321,13 +325,15 @@ class DatabaseView(PGChildNodeView): else: conn = self.manager.connection(row['name']) connected = conn.connected() + icon_css_class = "pg-icon-database" + if not connected: + icon_css_class = "icon-database-not-connected" return make_json_response( data=self.blueprint.generate_browser_node( row['did'], sid, row['name'], - icon="icon-database-not-connected" if not connected - else "pg-icon-database", + icon=icon_css_class, connected=connected, spcname=row['spcname'], allowConn=row['datallowconn'], @@ -580,7 +586,7 @@ class DatabaseView(PGChildNodeView): ) ) - @check_precondition(action="update") + @check_precondition(action='update') def update(self, gid, sid, did): """Update the database.""" @@ -589,7 +595,7 @@ class DatabaseView(PGChildNodeView): ) # Generic connection for offline updates - conn = self.manager.connection(conn_id="db_offline_update") + conn = self.manager.connection(conn_id='db_offline_update') status, errmsg = conn.connect() if not status: current_app.logger.error( @@ -611,7 +617,7 @@ class DatabaseView(PGChildNodeView): if len(rset['rows']) == 0: return gone( - _("Could not find the database on the server.") + _('Could not find the database on the server.') ) data['old_name'] = (rset['rows'][0])['name'] @@ -639,8 +645,8 @@ class DatabaseView(PGChildNodeView): if not status: current_app.logger.error( - "Could not connected to database(#{0}).\n" - "Error: {1}".format(did, errmsg) + 'Could not connected to database(#{0}).\n' + 'Error: {1}'.format(did, errmsg) ) return internal_server_error(errmsg) @@ -904,10 +910,7 @@ class DatabaseView(PGChildNodeView): otherwise it will return statistics for all the databases in that server. """ - last_system_oid = 0 if self.blueprint.show_system_objects else \ - (self.manager.db_info[self.manager.did])['datlastsysoid'] \ - if self.manager.db_info is not None and \ - self.manager.did in self.manager.db_info else 0 + last_system_oid = self.retrieve_last_system_oid() db_disp_res = None params = None @@ -918,14 +921,12 @@ class DatabaseView(PGChildNodeView): params = tuple(self.manager.db_res.split(',')) conn = self.manager.connection() - status, res = conn.execute_dict( - render_template( - "/".join([self.template_path, 'stats.sql']), - did=did, - conn=conn, - last_system_oid=last_system_oid, - db_restrictions=db_disp_res - ), + status, res = conn.execute_dict(render_template( + "/".join([self.template_path, 'stats.sql']), + did=did, + conn=conn, + last_system_oid=last_system_oid, + db_restrictions=db_disp_res), params ) @@ -1022,7 +1023,7 @@ class DatabaseView(PGChildNodeView): sid: Server ID did: Database ID """ - dependents_result = self.get_dependents(self.conn, did) if\ + dependents_result = self.get_dependents(self.conn, did) if \ self.conn.connected() else [] return ajax_response( response=dependents_result, @@ -1040,7 +1041,7 @@ class DatabaseView(PGChildNodeView): sid: Server ID did: Database ID """ - dependencies_result = self.get_dependencies(self.conn, did) if\ + dependencies_result = self.get_dependencies(self.conn, did) if \ self.conn.connected() else [] return ajax_response( response=dependencies_result, 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 004d7b5c..9a43b4d3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/__init__.py @@ -7,13 +7,15 @@ # ########################################################################## -import simplejson as json import re from functools import wraps -import pgadmin.browser.server_groups.servers as servers +import simplejson as json from flask import render_template, request, jsonify, current_app from flask_babel import gettext + +import pgadmin.browser.server_groups.servers as servers +from config import PG_DEFAULT_DRIVER from pgadmin.browser.collection import CollectionNodeModule, PGChildModule from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ parse_priv_to_db @@ -22,8 +24,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone, bad_request from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER - """ This module is responsible for generating two nodes 1) Schema @@ -283,7 +283,8 @@ class SchemaView(PGChildNodeView): data[aclcol][modifier], allowedacl['acl'] ) else: - data[aclcol] = parse_priv_to_db(data[aclcol], allowedacl['acl']) + data[aclcol] = parse_priv_to_db(data[aclcol], + allowedacl['acl']) return acls @@ -366,7 +367,8 @@ class SchemaView(PGChildNodeView): @check_precondition def list(self, gid, sid, did): """ - This function is used to list all the schema nodes within the collection. + This function is used to list all the schema nodes within the + collection. Args: gid: Server group ID @@ -491,13 +493,13 @@ It may have been removed by another user. for row in rset['rows']: return make_json_response( data=self.blueprint.generate_browser_node( - row['oid'], - did, - row['name'], - icon=icon, - can_create=row['can_create'], - has_usage=row['has_usage'] - ), + row['oid'], + did, + row['name'], + icon=icon, + can_create=row['can_create'], + has_usage=row['has_usage'] + ), status=200 ) @@ -528,9 +530,10 @@ It may have been removed by another user. return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone( - gettext("Could not find the schema in the database. It may have been removed by another user." - )) + return gone(gettext( + "Could not find the schema in the database. " + "It may have been removed by another user." + )) # Making copy of output for future use copy_data = dict(res['rows'][0]) @@ -801,7 +804,9 @@ It may have been removed by another user. return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone(gettext("""Could not find the schema in the database. It may have been removed by another user.""")) + return gone(gettext( + 'Could not find the schema in the database.' + ' It may have been removed by another user.')) data = res['rows'][0] data = self._formatter(data, scid) @@ -892,10 +897,12 @@ It may have been removed by another user. nodes = [] for module in self.blueprint.submodules: if isinstance(module, PGChildModule): - if self.manager is not None and \ - module.BackendSupported( - self.manager, **backend_support_keywords - ): + if ( + self.manager is not None and + module.BackendSupported( + self.manager, **backend_support_keywords + ) + ): nodes.extend(module.get_nodes(**kwargs)) else: nodes.extend(module.get_nodes(**kwargs)) @@ -1007,5 +1014,6 @@ It may have been removed by another user. return ajax_response(response=SQL.strip("\n")) + SchemaView.register_node_view(schema_blueprint) CatalogView.register_node_view(catalog_blueprint) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/__init__.py index cab5e012..6f2f3524 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/__init__.py @@ -11,18 +11,18 @@ from functools import wraps -import pgadmin.browser.server_groups.servers.databases as database from flask import render_template from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases as database +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils \ import SchemaChildModule from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils.ajax import gone from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response from pgadmin.utils.driver import get_driver -from pgadmin.utils.ajax import gone - -from config import PG_DEFAULT_DRIVER class CatalogObjectModule(SchemaChildModule): @@ -55,7 +55,8 @@ class CatalogObjectModule(SchemaChildModule): def __init__(self, *args, **kwargs): """ - Method is used to initialize the CatalogObjectModule and it's base module. + Method is used to initialize the CatalogObjectModule and it's base + module. Args: *args: @@ -188,7 +189,8 @@ class CatalogObjectView(PGChildNodeView): @check_precondition def nodes(self, gid, sid, did, scid): """ - This function will used to create all the child node within that collection. + This function will used to create all the child node within that + collection. Here it will create all the catalog objects node. Args: @@ -257,7 +259,8 @@ class CatalogObjectView(PGChildNodeView): status=200 ) - return gone(errormsg=gettext("Could not find the specified catalog object.")) + return gone( + errormsg=gettext("Could not find the specified catalog object.")) @check_precondition def properties(self, gid, sid, did, scid, coid): @@ -286,7 +289,8 @@ class CatalogObjectView(PGChildNodeView): return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone(gettext("""Could not find the specified catalog object.""")) + return gone( + gettext("""Could not find the specified catalog object.""")) return ajax_response( response=res['rows'][0], diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/columns/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/columns/__init__.py index 890f11af..e1b513fc 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/columns/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/columns/__init__.py @@ -11,19 +11,19 @@ from functools import wraps -import pgadmin.browser.server_groups.servers.databases as database from flask import render_template from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases as database +from config import PG_DEFAULT_DRIVER from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils.ajax import gone from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response from pgadmin.utils.driver import get_driver -from pgadmin.utils.ajax import gone from pgadmin.utils.preferences import Preferences -from config import PG_DEFAULT_DRIVER - class CatalogObjectColumnsModule(CollectionNodeModule): """ @@ -174,7 +174,8 @@ class CatalogObjectColumnsView(PGChildNodeView): kwargs['sid'] ) self.conn = self.manager.connection(did=kwargs['did']) - self.template_path = 'catalog_object_column/sql/#{0}#'.format(self.manager.version) + self.template_path = 'catalog_object_column/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) @@ -210,7 +211,8 @@ class CatalogObjectColumnsView(PGChildNodeView): @check_precondition def nodes(self, gid, sid, did, scid, coid): """ - This function will used to create all the child node within that collection. + This function will used to create all the child node within that + collection. Here it will create all the column node. Args: @@ -262,7 +264,8 @@ class CatalogObjectColumnsView(PGChildNodeView): JSON of selected column node """ SQL = render_template("/".join([self.template_path, - 'properties.sql']), coid=coid, clid=clid) + 'properties.sql']), coid=coid, + clid=clid) status, res = self.conn.execute_dict(SQL) if not status: @@ -321,7 +324,8 @@ class CatalogObjectColumnsView(PGChildNodeView): elif dep_str == 'i': dep_type = 'internal' - dependents_result.append({'type': 'sequence', 'name': ref_name, 'field': dep_type}) + dependents_result.append( + {'type': 'sequence', 'name': ref_name, 'field': dep_type}) return ajax_response( response=dependents_result, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py index 42fcfdb0..947a0539 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/__init__.py @@ -9,21 +9,23 @@ """ Implements Collation Node """ -import simplejson as json from functools import wraps -import pgadmin.browser.server_groups.servers.databases as database +import simplejson as json from flask import render_template, request, jsonify from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases as database +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils \ import SchemaChildModule from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.compile_template_name import compile_template_path from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -197,12 +199,14 @@ class CollationView(PGChildNodeView): ) return f(*args, **kwargs) + return wrap @check_precondition def list(self, gid, sid, did, scid): """ - This function is used to list all the collation nodes within that collection. + This function is used to list all the collation nodes within that + collection. Args: gid: Server group ID @@ -228,7 +232,8 @@ class CollationView(PGChildNodeView): @check_precondition def nodes(self, gid, sid, did, scid): """ - This function will used to create all the child node within that collection. + This function will used to create all the child node within that + collection. Here it will create all the collation node. Args: @@ -380,22 +385,28 @@ class CollationView(PGChildNodeView): missing_definition_flag = False for arg in definition_args: - if arg == 'locale' and \ - (arg not in data or data[arg] == ''): + if ( + arg == 'locale' and + (arg not in data or data[arg] == '') + ): if 'copy_collation' not in data and ( - 'lc_collate' not in data and 'lc_type' not in data + 'lc_collate' not in data and 'lc_type' not in data ): missing_definition_flag = True - if arg == 'copy_collation' and \ - (arg not in data or data[arg] == ''): + if ( + arg == 'copy_collation' and + (arg not in data or data[arg] == '') + ): if 'locale' not in data and ( - 'lc_collate' not in data and 'lc_type' not in data + 'lc_collate' not in data and 'lc_type' not in data ): missing_definition_flag = True - if (arg == 'lc_collate' or arg == 'lc_type') and \ - (arg not in data or data[arg] == ''): + if ( + (arg == 'lc_collate' or arg == 'lc_type') and + (arg not in data or data[arg] == '') + ): if 'copy_collation' not in data and 'locale' not in data: missing_definition_flag = True @@ -435,7 +446,8 @@ class CollationView(PGChildNodeView): status=410, success=0, errormsg=gettext( - "Definition incomplete. Please provide Locale OR Copy Collation OR LC_TYPE/LC_COLLATE." + "Definition incomplete. Please provide Locale OR Copy " + "Collation OR LC_TYPE/LC_COLLATE." ) ) @@ -603,7 +615,7 @@ class CollationView(PGChildNodeView): return make_json_response( data=SQL, status=200 - ) + ) except Exception as e: return internal_server_error(errormsg=str(e)) @@ -620,7 +632,8 @@ class CollationView(PGChildNodeView): return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( - gettext("Could not find the collation object in the database.") + gettext( + "Could not find the collation object in the database.") ) old_data = res['rows'][0] @@ -628,7 +641,8 @@ class CollationView(PGChildNodeView): "/".join([self.template_path, 'update.sql']), data=data, o_data=old_data, conn=self.conn ) - return SQL.strip('\n'), data['name'] if 'name' in data else old_data['name'] + return SQL.strip('\n'), data['name'] if 'name' in data else \ + old_data['name'] else: required_args = [ 'name' @@ -649,7 +663,8 @@ class CollationView(PGChildNodeView): @check_precondition def sql(self, gid, sid, did, scid, coid): """ - This function will generates reverse engineered sql for collation object + This function will generates reverse engineered sql for collation + object Args: gid: Server Group ID diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/__init__.py index 4e52e2c1..ccd081c4 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/__init__.py @@ -14,4 +14,3 @@ class CollationTestGenerator(BaseTestGenerator): def generate_tests(self): return - diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_add.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_add.py index b541580e..220f4715 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_add.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_add.py @@ -64,8 +64,8 @@ class CollationAddTestCase(BaseTestGenerator): "schema": schema_name } response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/' + - str(server_id) + '/' + str( - db_id) + '/' + str(schema_id) + '/', + str(server_id) + '/' + str(db_id) + '/' + + str(schema_id) + '/', data=json.dumps(data), content_type='html/json') self.assertEquals(response.status_code, 200) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_put.py index 4c8330ff..0cf47988 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_put.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/collations/tests/test_collation_put.py @@ -69,8 +69,9 @@ class CollationPutTestCase(BaseTestGenerator): "id": collation_id } put_response = self.tester.put(self.url + str(utils.SERVER_GROUP) + - '/' + str(server_id) + '/' + str(db_id) - + '/' + str(schema_id) + '/' + + '/' + str(server_id) + '/' + + str(db_id) + '/' + str(schema_id) + + '/' + str(collation_id), data=json.dumps(data), follow_redirects=True) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py index 7ec87af4..73ad23ea 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/__init__.py @@ -9,23 +9,25 @@ """Implements the Domain Node.""" -import simplejson as json from functools import wraps -import pgadmin.browser.server_groups.servers.databases as databases +import simplejson as json from flask import render_template, make_response, request, jsonify from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases as databases +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ SchemaChildModule, DataTypeReader from pgadmin.browser.server_groups.servers.databases.utils import \ parse_sec_labels_from_db from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.compile_template_name import compile_template_path from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -209,7 +211,8 @@ class DomainView(PGChildNodeView, DataTypeReader): status=410, success=0, errormsg=gettext( - "Could not find the required parameter (%s)." % arg + "Could not find the required parameter (%s)." % + arg ) ) @@ -219,15 +222,19 @@ class DomainView(PGChildNodeView, DataTypeReader): list_params = ['constraints', 'seclabels'] for key in req: - if key in list_params and req[key] != '' \ - and req[key] is not None: + if ( + key in list_params and req[key] != '' and + req[key] is not None + ): # Coverts string into python list as expected. data[key] = json.loads(req[key], encoding='utf-8') elif key == 'typnotnull': - data[key] = True if req[key] == 'true' or req[key] is \ - True else \ - (False if req[key] == 'false' or req[key] is - False else '') + if req[key] == 'true' or req[key] is True: + data[key] = True + elif req[key] == 'false' or req[key] is False: + data[key] = False + else: + data[key] = '' else: data[key] = req[key] @@ -611,7 +618,7 @@ AND relkind != 'c'))""" ) ) - name = res['rows'][0]['name'] + name = res['rows'][0]['name'] basensp = res['rows'][0]['basensp'] SQL = render_template("/".join([self.template_path, @@ -659,7 +666,7 @@ AND relkind != 'c'))""" # Get Schema Id SQL = render_template("/".join([self.template_path, 'get_oid.sql']), - doid=doid) + doid=doid) status, scid = self.conn.execute_scalar(SQL) if not status: return internal_server_error(errormsg=res) @@ -693,9 +700,9 @@ AND relkind != 'c'))""" if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone( - gettext("Could not find the specified domain.") - ) + return gone( + gettext("Could not find the specified domain.") + ) data = res['rows'][0] @@ -762,7 +769,7 @@ AND relkind != 'c'))""" return make_json_response( data=SQL, status=200 - ) + ) except Exception as e: return internal_server_error(errormsg=str(e)) @@ -787,9 +794,9 @@ AND relkind != 'c'))""" if not status: return False, internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone( - gettext("Could not find the specified domain.") - ) + return gone( + gettext("Could not find the specified domain.") + ) old_data = res['rows'][0] @@ -810,7 +817,8 @@ AND relkind != 'c'))""" SQL = render_template( "/".join([self.template_path, 'update.sql']), data=data, o_data=old_data) - return SQL.strip('\n'), data['name'] if 'name' in data else old_data['name'] + return SQL.strip('\n'), data['name'] if 'name' in data else \ + old_data['name'] else: SQL = render_template("/".join([self.template_path, 'create.sql']), diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py index c416324d..0d584c62 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py @@ -9,19 +9,20 @@ """Implements the Domain Constraint Module.""" -import simplejson as json from functools import wraps -import pgadmin.browser.server_groups.servers.databases.schemas.domains \ - as domains +import simplejson as json from flask import render_template, request, jsonify from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases.schemas.domains \ + as domains +from config import PG_DEFAULT_DRIVER from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.utils import PGChildNodeView from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER class DomainConstraintModule(CollectionNodeModule): @@ -211,7 +212,8 @@ class DomainConstraintView(PGChildNodeView): status=410, success=0, errormsg=gettext( - "Could not find the required parameter (%s)." % arg + "Could not find the required parameter (%s)." % + arg ) ) @@ -247,9 +249,11 @@ class DomainConstraintView(PGChildNodeView): self.qtIdent = driver.qtIdent # Set the template path for the SQL scripts - self.template_path = 'domain_constraints/sql/#{0}#'.format(self.manager.version) + self.template_path = 'domain_constraints/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) + return wrap @check_precondition @@ -383,7 +387,7 @@ class DomainConstraintView(PGChildNodeView): if len(res['rows']) == 0: return gone(gettext( "Could not find the specified domain constraint." - ) + ) ) data = res['rows'][0] @@ -585,7 +589,7 @@ class DomainConstraintView(PGChildNodeView): if len(res['rows']) == 0: return gone(gettext( "Could not find the specified domain constraint." - ) + ) ) data = res['rows'][0] @@ -657,7 +661,7 @@ class DomainConstraintView(PGChildNodeView): if len(res['rows']) == 0: return False, gone(gettext( "Could not find the specified domain constraint." - ) + ) ) old_data = res['rows'][0] @@ -672,7 +676,10 @@ class DomainConstraintView(PGChildNodeView): SQL = render_template("/".join([self.template_path, 'create.sql']), data=data, domain=domain, schema=schema) - return True, SQL.strip('\n'), data['name'] if 'name' in data else old_data['name'] + if 'name' in data: + return True, SQL.strip('\n'), data['name'] + else: + return True, SQL.strip('\n'), old_data['name'] except Exception as e: return False, internal_server_error(errormsg=str(e)), None diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/test_domain_add.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/test_domain_add.py index cc9bd6e6..c803538b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/test_domain_add.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/test_domain_add.py @@ -67,8 +67,8 @@ class DomainAddTestCase(BaseTestGenerator): } # Call POST API to add domain response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/' + - str(self.server_id) + '/' + str( - self.db_id) + + str(self.server_id) + '/' + + str(self.db_id) + '/' + str(schema_id) + '/', data=json.dumps(data), content_type='html/json') diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/utils.py index 23b75610..a50bc0e3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/tests/utils.py @@ -37,8 +37,8 @@ def create_domain(server, db_name, schema_name, schema_id, domain_name): server['host'], server['port']) pg_cursor = connection.cursor() - query = 'CREATE DOMAIN '+schema_name+'.'+domain_name+' AS' \ - ' character(10) COLLATE pg_catalog."POSIX" DEFAULT 1' + query = 'CREATE DOMAIN ' + schema_name + '.' + domain_name + \ + ' AS character(10) COLLATE pg_catalog."POSIX" DEFAULT 1' pg_cursor.execute(query) connection.commit() # Get 'oid' from newly created domain diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py index c36598c0..a98ada74 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py @@ -9,15 +9,17 @@ """Implements the Foreign Table Module.""" -import simplejson as json import sys import traceback from functools import wraps -import pgadmin.browser.server_groups.servers.databases as databases +import simplejson as json from flask import render_template, make_response, request, jsonify, \ current_app from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases as databases +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ SchemaChildModule, DataTypeReader from pgadmin.browser.server_groups.servers.databases.utils import \ @@ -25,12 +27,12 @@ from pgadmin.browser.server_groups.servers.databases.utils import \ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ parse_priv_to_db from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.compile_template_name import compile_template_path from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -252,7 +254,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): status=410, success=0, errormsg=gettext( - "Could not find the required parameter (%s)." % arg + "Could not find the required parameter (%s)." % + arg ) ) @@ -265,12 +268,14 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): list_params = ['inherits'] for key in req: - if key in list_params and req[key] != '' \ - and req[key] is not None: + if ( + key in list_params and req[key] != '' and + req[key] is not None + ): # Coverts string into python list as expected. - data[key] = [] if \ - type(req[key]) == list and len(req[key]) == 0 else \ - json.loads(req[key], encoding='utf-8') + data[key] = [] + if type(req[key]) != list or len(req[key]) != 0: + data[key] = json.loads(req[key], encoding='utf-8') if key == 'inherits': # Convert Table ids from unicode/string to int @@ -352,6 +357,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): ) return f(*args, **kwargs) + return wrap @check_precondition @@ -442,8 +448,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): ) return gone(gettext( - 'Could not find the specified foreign table.' - )) + 'Could not find the specified foreign table.' + )) @check_precondition def properties(self, gid, sid, did, scid, foid): @@ -458,7 +464,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): foid: Foreign Table Id """ data = self._fetch_properties(gid, sid, did, scid, foid) - if data == False: + if data is False: return gone( gettext("Could not find the foreign table on the server.") ) @@ -579,7 +585,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): res = [] try: SQL = render_template("/".join( - [self.template_path,'get_tables.sql']), + [self.template_path, 'get_tables.sql']), foid=foid, server_type=self.manager.server_type, show_sys_objects=self.blueprint.show_system_objects) status, rset = self.conn.execute_dict(SQL) @@ -591,7 +597,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): status=200 ) - except: + except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() current_app.logger.error( traceback.print_exception(exc_type, @@ -634,7 +640,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): data=res['rows'], status=200 ) - except: + except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() current_app.logger.error(traceback.print_exception( exc_type, @@ -722,7 +728,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): try: # Fetch Name and Schema Name to delete the foreign table. SQL = render_template("/".join([self.template_path, - 'delete.sql']), scid=scid, foid=foid) + 'delete.sql']), scid=scid, + foid=foid) status, res = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=res) @@ -738,7 +745,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): ) ) - name = res['rows'][0]['name'] + name = res['rows'][0]['name'] basensp = res['rows'][0]['basensp'] SQL = render_template("/".join([self.template_path, @@ -823,14 +830,14 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): foid: Foreign Table Id """ data = self._fetch_properties(gid, sid, did, scid, foid, inherits=True) - if data == False: + if data is False: return gone( gettext("Could not find the foreign table on the server.") ) col_data = [] for c in data['columns']: - if (not 'inheritedfrom' in c) or (c['inheritedfrom'] is None): + if ('inheritedfrom' not in c) or (c['inheritedfrom'] is None): col_data.append(c) data['columns'] = col_data @@ -878,7 +885,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): return make_json_response( data=SQL, status=200 - ) + ) except Exception as e: return internal_server_error(errormsg=str(e)) @@ -896,7 +903,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): if foid is not None: old_data = self._fetch_properties(gid, sid, did, scid, foid, inherits=True) - if old_data == False: + if old_data is False: return gone( gettext("Could not find the foreign table on the server.") ) @@ -920,7 +927,10 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): # Parse Column Options for c in data['columns']['changed']: - old_col_options = c['attfdwoptions'] if ('attfdwoptions' in c and c['attfdwoptions']) else [] + old_col_options = c['attfdwoptions'] = [] + if 'attfdwoptions' in c and c['attfdwoptions']: + old_col_options = c['attfdwoptions'] + old_col_frmt_options = {} for o in old_col_options: @@ -933,8 +943,10 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): if 'coloptions' in c and len(c['coloptions']) > 0: for o in c['coloptions']: - if o['option'] in old_col_frmt_options and \ - o['value'] != old_col_frmt_options[o['option']]: + if ( + o['option'] in old_col_frmt_options and + o['value'] != old_col_frmt_options[o['option']] + ): c['coloptions_updated']['changed'].append(o) elif o['option'] not in old_col_frmt_options: c['coloptions_updated']['added'].append(o) @@ -942,7 +954,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): del old_col_frmt_options[o['option']] for o in old_col_frmt_options: - c['coloptions_updated']['deleted'].append({'option': o}) + c['coloptions_updated']['deleted'].append( + {'option': o}) # Parse Privileges if 'acl' in data and 'added' in data['acl']: @@ -972,7 +985,6 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): 'create.sql']), data=data) return SQL, data['name'] - @check_precondition def dependents(self, gid, sid, did, scid, foid): """ @@ -1096,13 +1108,13 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): # So, we need to separate it as Length: 1, Precision: 1 for c in cols['rows']: if c['fulltype'] != '' and c['fulltype'].find("(") > 0: - substr = c['fulltype'][c['fulltype'].find("(") + 1:c['fulltype'].find(")")] + substr = self.extract_type_length_precision(c) typlen = substr.split(",") if len(typlen) > 1: - c['typlen'] = int(typlen[0]) if typlen[0].isdigit() else typlen[0] - c['precision'] = int(typlen[1]) if typlen[1].isdigit() else typlen[1] + c['typlen'] = self.convert_typlen_to_int(typlen) + c['precision'] = self.convert_precision_to_int(typlen) else: - c['typlen'] = int(typlen[0]) if typlen[0].isdigit() else typlen[0] + c['typlen'] = self.convert_typlen_to_int(typlen) c['precision'] = None # Get formatted Column Options @@ -1133,6 +1145,29 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): return data + @staticmethod + def convert_precision_to_int(typlen): + return int(typlen[1]) if typlen[1].isdigit() else \ + typlen[1] + + @staticmethod + def convert_typlen_to_int(typlen): + return int(typlen[0]) if typlen[0].isdigit() else \ + typlen[0] + + def extract_type_length_precision(self, column): + full_type = column['fulltype'] + return full_type[self.type_start_position(column): + self.type_end_position(column)] + + @staticmethod + def type_end_position(column): + return column['fulltype'].find(")") + + @staticmethod + def type_start_position(column): + return column['fulltype'].find("(") + 1 + def _format_proacl_from_db(self, proacl): """ Returns privileges. @@ -1200,7 +1235,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): SELECT Script sql for the object """ data = self._fetch_properties(gid, sid, did, scid, foid) - if data == False: + if data is False: return gone( gettext("Could not find the foreign table on the server.") ) @@ -1237,7 +1272,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): INSERT Script sql for the object """ data = self._fetch_properties(gid, sid, did, scid, foid) - if data == False: + if data is False: return gone( gettext("Could not find the foreign table on the server.") ) @@ -1279,7 +1314,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): UPDATE Script sql for the object """ data = self._fetch_properties(gid, sid, did, scid, foid) - if data == False: + if data is False: return gone( gettext("Could not find the foreign table on the server.") ) @@ -1324,7 +1359,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader): DELETE Script sql for the object """ data = self._fetch_properties(gid, sid, did, scid, foid) - if data == False: + if data is False: return gone( gettext("Could not find the foreign table on the server.") ) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_add.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_add.py index fff92c59..511582cb 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_add.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_add.py @@ -12,9 +12,9 @@ from __future__ import print_function import json import uuid -from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\ +from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers. \ foreign_servers.tests import utils as fsrv_utils -from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\ +from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers. \ tests import utils as fdw_utils from pgadmin.browser.server_groups.servers.databases.tests import \ utils as database_utils @@ -71,14 +71,13 @@ class ForeignTableAddTestCase(BaseTestGenerator): data = { "acl": [], "basensp": self.schema_name, - "columns": - [ - { - "attname": "ename", - "datatype": "text", - "coloptions": [] - } - ], + "columns": [ + { + "attname": "ename", + "datatype": "text", + "coloptions": [] + } + ], "constraints": [], "ftoptions": [], "inherits": [], @@ -92,8 +91,8 @@ class ForeignTableAddTestCase(BaseTestGenerator): response = self.tester.post( self.url + str(utils.SERVER_GROUP) + '/' + - str(self.server_id) + '/' + str(self.db_id) + '/' - + str(self.schema_id) + '/', data=json.dumps(data), + str(self.server_id) + '/' + str(self.db_id) + '/' + + str(self.schema_id) + '/', data=json.dumps(data), content_type='html/json') self.assertEquals(response.status_code, 200) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_delete.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_delete.py index 9973d106..f116f346 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_delete.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_delete.py @@ -52,7 +52,8 @@ class ForeignTableDeleteTestCase(BaseTestGenerator): self.fsrv_name, self.fdw_name) self.ft_id = ft_utils.create_foreign_table(self.server, self.db_name, self.schema_name, - self.fsrv_name, self.ft_name) + self.fsrv_name, + self.ft_name) def runTest(self): """This function will delete foreign table under test database.""" diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_get.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_get.py index 4653cac7..1c908b95 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_get.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_get.py @@ -11,9 +11,9 @@ from __future__ import print_function import uuid -from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\ +from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers. \ foreign_servers.tests import utils as fsrv_utils -from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\ +from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers. \ tests import utils as fdw_utils from pgadmin.browser.server_groups.servers.databases.tests import \ utils as database_utils @@ -52,7 +52,8 @@ class ForeignTableGetTestCase(BaseTestGenerator): self.fsrv_name, self.fdw_name) self.ft_id = ft_utils.create_foreign_table(self.server, self.db_name, self.schema_name, - self.fsrv_name, self.ft_name) + self.fsrv_name, + self.ft_name) def runTest(self): """This function will fetch foreign table under test database.""" diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_put.py index e72c4cca..aa62ea54 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_put.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/test_foreign_table_put.py @@ -53,7 +53,8 @@ class ForeignTablePutTestCase(BaseTestGenerator): self.fsrv_name, self.fdw_name) self.ft_id = ft_utils.create_foreign_table(self.server, self.db_name, self.schema_name, - self.fsrv_name, self.ft_name) + self.fsrv_name, + self.ft_name) def runTest(self): """This function will update foreign table under test database.""" diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/utils.py index fe67a325..a3c98bfb 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/utils.py @@ -48,8 +48,8 @@ def create_foreign_table(server, db_name, schema_name, fsrv_name, # Get 'oid' from newly created foreign table pg_cursor.execute( "SELECT ftrelid FROM pg_foreign_table WHERE ftserver = " - "(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') ORDER BY " - "ftrelid ASC limit 1" % fsrv_name) + "(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') " + "ORDER BY ftrelid ASC limit 1" % fsrv_name) oid = pg_cursor.fetchone() ft_id = '' @@ -74,8 +74,8 @@ def verify_foreign_table(server, db_name, fsrv_name): pg_cursor.execute( "SELECT ftrelid FROM pg_foreign_table WHERE ftserver = " - "(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') ORDER BY " - "ftrelid ASC limit 1" % fsrv_name) + "(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') " + "ORDER BY ftrelid ASC limit 1" % fsrv_name) fts = pg_cursor.fetchone() connection.close() return fts diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py index 9f2d6cf3..9c0db1d6 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/__init__.py @@ -9,20 +9,22 @@ """Defines views for management of Fts Configuration node""" -import simplejson as json from functools import wraps -import pgadmin.browser.server_groups.servers.databases as databases +import simplejson as json from flask import render_template, make_response, current_app, request, jsonify from flask_babel import gettext as _ + +import pgadmin.browser.server_groups.servers.databases as databases +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils \ import SchemaChildModule from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -32,7 +34,8 @@ class FtsConfigurationModule(SchemaChildModule): """ class FtsConfigurationModule(SchemaChildModule) - A module class for FTS Configuration node derived from SchemaChildModule. + A module class for FTS Configuration node derived from + SchemaChildModule. Methods: ------- @@ -102,7 +105,8 @@ class FtsConfigurationView(PGChildNodeView): Methods: ------- * __init__(**kwargs) - - Method is used to initialize the FtsConfigurationView and it's base view. + - Method is used to initialize the FtsConfigurationView and it's base + view. * module_js() - This property defines (if javascript) exists for this node. @@ -117,7 +121,8 @@ class FtsConfigurationView(PGChildNodeView): - This function is used to list all the nodes within that collection. * nodes() - - This function will be used to create all the child node within collection. + - This function will be used to create all the child node within + collection. Here it will create all the FTS Configuration nodes. * node() @@ -125,13 +130,15 @@ class FtsConfigurationView(PGChildNodeView): Here it will create the FTS Template node based on its oid * properties(gid, sid, did, scid, cfgid) - - This function will show the properties of the selected FTS Configuration node + - This function will show the properties of the selected + FTS Configuration node * create(gid, sid, did, scid) - This function will create the new FTS Configuration object * update(gid, sid, did, scid, cfgid) - - This function will update the data for the selected FTS Configuration node + - This function will update the data for the selected + FTS Configuration node * delete(self, gid, sid, did, scid, cfgid): - This function will drop the FTS Configuration object @@ -149,7 +156,8 @@ class FtsConfigurationView(PGChildNodeView): - This function will fetch all ftp parsers from the same schema * copyConfig(): - - This function will fetch all existed fts configurations from same schema + - This function will fetch all existed fts configurations from same + schema * tokens(): - This function will fetch all tokens from fts parser related to node @@ -234,9 +242,11 @@ class FtsConfigurationView(PGChildNodeView): kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # Set the template path for the SQL scripts - self.template_path = 'fts_configuration/sql/#{0}#'.format(self.manager.version) + self.template_path = 'fts_configuration/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) + return wrap @check_precondition @@ -363,7 +373,9 @@ class FtsConfigurationView(PGChildNodeView): if len(res['rows']) == 0: return gone( - _("Could not find the FTS Configuration node in the database node.") + _( + "Could not find the FTS Configuration node in the " + "database node.") ) # In edit mode fetch token/dictionary list also @@ -614,7 +626,7 @@ class FtsConfigurationView(PGChildNodeView): return make_json_response( data=SQL, status=200 - ) + ) def get_sql(self, gid, sid, did, scid, data, cfgid=None): """ @@ -675,7 +687,10 @@ class FtsConfigurationView(PGChildNodeView): data=new_data, o_data=old_data ) # Fetch sql query for modified data - return sql.strip('\n'), data['name'] if 'name' in data else old_data['name'] + if 'name' in data: + return sql.strip('\n'), data['name'] + + return sql.strip('\n'), old_data['name'] else: # Fetch schema name from schema oid sql = render_template( @@ -691,8 +706,10 @@ class FtsConfigurationView(PGChildNodeView): new_data = data.copy() new_data['schema'] = schema - if 'name' in new_data and \ - 'schema' in new_data: + if ( + 'name' in new_data and + 'schema' in new_data + ): sql = render_template("/".join([self.template_path, 'create.sql']), data=new_data, @@ -862,16 +879,16 @@ class FtsConfigurationView(PGChildNodeView): if not status: return internal_server_error( _( - "Could not generate reversed engineered query for the FTS Configuration.\n{0}" - ).format( - res - ) + "Could not generate reversed engineered query for the " + "FTS Configuration.\n{0}" + ).format(res) ) if res is None: return gone( _( - "Could not generate reversed engineered query for FTS Configuration node.") + "Could not generate reversed engineered query for " + "FTS Configuration node.") ) return ajax_response(response=res) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/tests/utils.py index 1d6e5d27..f28ac02d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/tests/utils.py @@ -31,8 +31,8 @@ def create_fts_configuration(server, db_name, schema_name, fts_conf_name): server['sslmode']) pg_cursor = connection.cursor() - query = "CREATE TEXT SEARCH CONFIGURATION " + schema_name + "." + fts_conf_name + \ - "(PARSER=default)" + query = "CREATE TEXT SEARCH CONFIGURATION " + schema_name + "." + \ + fts_conf_name + "(PARSER=default)" pg_cursor.execute(query) connection.commit() diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py index 7262f95a..b8796a92 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py @@ -9,20 +9,22 @@ """Defines views for management of Fts Dictionary node""" -import simplejson as json from functools import wraps -import pgadmin.browser.server_groups.servers.databases as databases +import simplejson as json from flask import render_template, make_response, current_app, request, jsonify from flask_babel import gettext as _ + +import pgadmin.browser.server_groups.servers.databases as databases +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils \ import SchemaChildModule from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -122,7 +124,8 @@ class FtsDictionaryView(PGChildNodeView): - This function is used to list all the nodes within that collection. * nodes() - - This function will be used to create all the child node within collection. + - This function will be used to create all the child node within + collection. Here it will create all the FTS Dictionary nodes. * node() @@ -130,7 +133,8 @@ class FtsDictionaryView(PGChildNodeView): Here it will create the FTS Template node based on its oid * properties(gid, sid, did, scid, dcid) - - This function will show the properties of the selected FTS Dictionary node + - This function will show the properties of the selected FTS Dictionary + node * create(gid, sid, did, scid) - This function will create the new FTS Dictionary object @@ -228,9 +232,11 @@ class FtsDictionaryView(PGChildNodeView): driver = get_driver(PG_DEFAULT_DRIVER) self.qtIdent = driver.qtIdent # Set the template path for the SQL scripts - self.template_path = 'fts_dictionary/sql/#{0}#'.format(self.manager.version) + self.template_path = 'fts_dictionary/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) + return wrap def tokenize_options(self, option_value): @@ -384,9 +390,9 @@ class FtsDictionaryView(PGChildNodeView): if res['rows'][0]['template_schema'] is not None: if res['rows'][0]['template_schema'] != "pg_catalog": res['rows'][0]['template'] = self.qtIdent( - self.conn, res['rows'][0]['template_schema'], - res['rows'][0]['template'] - ) + self.conn, res['rows'][0]['template_schema'], + res['rows'][0]['template'] + ) if res['rows'][0]['options'] is not None: res['rows'][0]['options'] = self.tokenize_options( @@ -423,7 +429,8 @@ class FtsDictionaryView(PGChildNodeView): return make_json_response( status=410, success=0, - errormsg=_("Could not find the required parameter (%s)." % arg) + errormsg=_( + "Could not find the required parameter (%s)." % arg) ) # Fetch schema name from schema oid sql = render_template( @@ -456,7 +463,7 @@ class FtsDictionaryView(PGChildNodeView): name=data['name'], scid=data['schema'] ) - status, dcid= self.conn.execute_scalar(sql) + status, dcid = self.conn.execute_scalar(sql) if not status: return internal_server_error(errormsg=dcid) @@ -612,7 +619,7 @@ class FtsDictionaryView(PGChildNodeView): return make_json_response( data=SQL, status=200 - ) + ) def get_sql(self, gid, sid, did, scid, data, dcid=None): """ @@ -681,7 +688,10 @@ class FtsDictionaryView(PGChildNodeView): data=new_data, o_data=old_data ) # Fetch sql query for modified data - return sql.strip('\n'), data['name'] if 'name' in data else old_data['name'] + if 'name' in data: + return sql.strip('\n'), data['name'] + + return sql.strip('\n'), old_data['name'] else: # Fetch schema name from schema oid sql = render_template("/".join([self.template_path, 'schema.sql']), @@ -695,9 +705,11 @@ class FtsDictionaryView(PGChildNodeView): new_data = data.copy() new_data['schema'] = schema - if 'template' in new_data and \ - 'name' in new_data and \ - 'schema' in new_data: + if ( + 'template' in new_data and + 'name' in new_data and + 'schema' in new_data + ): sql = render_template("/".join([self.template_path, 'create.sql']), data=new_data, @@ -803,7 +815,8 @@ class FtsDictionaryView(PGChildNodeView): -- DROP TEXT SEARCH DICTIONARY {0}; -""".format(self.qtIdent(self.conn, res['rows'][0]['schema'], res['rows'][0]['name'])) +""".format(self.qtIdent(self.conn, res['rows'][0]['schema'], + res['rows'][0]['name'])) sql = sql_header + sql diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py index 414b728a..39bf2431 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/__init__.py @@ -9,19 +9,22 @@ """Defines views for management of FTS Parser node""" -import simplejson as json from functools import wraps +import simplejson as json from flask import render_template, request, jsonify, current_app from flask_babel import gettext as _ + +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases import DatabaseModule -from pgadmin.browser.server_groups.servers.databases.schemas.utils import SchemaChildModule +from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ + SchemaChildModule from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -192,11 +195,15 @@ class FtsParserView(PGChildNodeView): 'dependency': [{'get': 'dependencies'}], 'dependent': [{'get': 'dependents'}], 'module.js': [{}, {}, {'get': 'module_js'}], - 'start_functions': [{'get': 'start_functions'}, {'get': 'start_functions'}], - 'token_functions': [{'get': 'token_functions'}, {'get': 'token_functions'}], + 'start_functions': [{'get': 'start_functions'}, + {'get': 'start_functions'}], + 'token_functions': [{'get': 'token_functions'}, + {'get': 'token_functions'}], 'end_functions': [{'get': 'end_functions'}, {'get': 'end_functions'}], - 'lextype_functions': [{'get': 'lextype_functions'}, {'get': 'lextype_functions'}], - 'headline_functions': [{'get': 'headline_functions'}, {'get': 'headline_functions'}], + 'lextype_functions': [{'get': 'lextype_functions'}, + {'get': 'lextype_functions'}], + 'headline_functions': [{'get': 'headline_functions'}, + {'get': 'headline_functions'}], }) def _init_(self, **kwargs): @@ -227,9 +234,11 @@ class FtsParserView(PGChildNodeView): kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # Set the template path for the SQL scripts - self.template_path = 'fts_parser/sql/#{0}#'.format(self.manager.version) + self.template_path = 'fts_parser/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) + return wrap @check_precondition @@ -310,7 +319,8 @@ class FtsParserView(PGChildNodeView): return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone(_("Could not find the FTS Parser node in the database node.")) + return gone( + _("Could not find the FTS Parser node in the database node.")) return ajax_response( response=res['rows'][0], @@ -442,7 +452,6 @@ class FtsParserView(PGChildNodeView): ) ) - @check_precondition def delete(self, gid, sid, did, scid, pid): """ @@ -534,7 +543,7 @@ class FtsParserView(PGChildNodeView): return make_json_response( data=SQL, status=200 - ) + ) def get_sql(self, gid, sid, did, scid, data, pid=None): """ @@ -597,7 +606,9 @@ class FtsParserView(PGChildNodeView): o_data=old_data ) # Fetch sql query for modified data - return sql.strip('\n'), data['name'] if 'name' in data else old_data['name'] + if 'name' in data: + return sql.strip('\n'), data['name'] + return sql.strip('\n'), old_data['name'] else: # Fetch schema name from schema oid sql = render_template( @@ -613,12 +624,14 @@ class FtsParserView(PGChildNodeView): new_data = data.copy() new_data['schema'] = schema - if 'prsstart' in new_data and \ - 'prstoken' in new_data and \ - 'prsend' in new_data and \ - 'prslextype' in new_data and \ - 'name' in new_data and \ - 'schema' in new_data: + if ( + 'prsstart' in new_data and + 'prstoken' in new_data and + 'prsend' in new_data and + 'prslextype' in new_data and + 'name' in new_data and + 'schema' in new_data + ): sql = render_template( "/".join([self.template_path, 'create.sql']), data=new_data, @@ -784,14 +797,16 @@ class FtsParserView(PGChildNodeView): if not status: return internal_server_error( _( - "Could not generate reversed engineered query for the FTS Parser.\n{0}" + "Could not generate reversed engineered query for the " + "FTS Parser.\n{0}" ).format(res) ) if res is None: return gone( _( - "Could not generate reversed engineered query for FTS Parser node" + "Could not generate reversed engineered query for " + "FTS Parser node" ) ) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_delete.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_delete.py index ae391abf..664fed64 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_delete.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_delete.py @@ -61,9 +61,10 @@ class FtsParserDeleteTestCase(BaseTestGenerator): if not schema_response: raise Exception("Could not find the schema.") - parser_response = fts_parser_utils.verify_fts_parser(self.server, - self.db_name, - self.fts_parser_name) + parser_response = fts_parser_utils.verify_fts_parser( + self.server, + self.db_name, + self.fts_parser_name) if not parser_response: raise Exception("Could not find the FTS parser.") diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_put.py index 4c860ee3..b1ef78d3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_put.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/test_fts_parser_put.py @@ -62,9 +62,10 @@ class FtsParserPutTestCase(BaseTestGenerator): if not schema_response: raise Exception("Could not find the schema.") - parser_response = fts_parser_utils.verify_fts_parser(self.server, - self.db_name, - self.fts_parser_name) + parser_response = fts_parser_utils.verify_fts_parser( + self.server, + self.db_name, + self.fts_parser_name) if not parser_response: raise Exception("Could not find the FTS parser.") diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/utils.py index 7a1c44fb..eac8724f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/tests/utils.py @@ -30,10 +30,12 @@ def create_fts_parser(server, db_name, schema_name, fts_parser_name): server['sslmode']) pg_cursor = connection.cursor() - query = "DROP TEXT SEARCH PARSER IF EXISTS " + schema_name + "." + fts_parser_name + query = "DROP TEXT SEARCH PARSER IF EXISTS " + schema_name + "." + \ + fts_parser_name pg_cursor.execute(query) - query = "CREATE TEXT SEARCH PARSER " + schema_name + "." + fts_parser_name + \ + query = "CREATE TEXT SEARCH PARSER " + schema_name + "." + \ + fts_parser_name + \ "(START=prsd_start, GETTOKEN=prsd_nexttoken, " \ "END=prsd_end, LEXTYPES=dispell_init)" diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py index e040fb2b..7aa05e97 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/__init__.py @@ -9,19 +9,22 @@ """Defines views for management of Fts Template node""" -import simplejson as json from functools import wraps +import simplejson as json from flask import render_template, make_response, request, jsonify from flask_babel import gettext + +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases import DatabaseModule -from pgadmin.browser.server_groups.servers.databases.schemas.utils import SchemaChildModule +from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ + SchemaChildModule from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -36,7 +39,8 @@ class FtsTemplateModule(SchemaChildModule): Methods: ------- * __init__(*args, **kwargs) - - Method is used to initialize the FtsTemplateModule and it's base module. + - Method is used to initialize the FtsTemplateModule and it's base + module. * get_nodes(gid, sid, did, scid) - Method is used to generate the browser collection node. @@ -90,10 +94,11 @@ class FtsTemplateView(PGChildNodeView): """ class FtsTemplateView(PGChildNodeView) - A view class for FTS Tempalte node derived from PGChildNodeView. This class is - responsible for all the stuff related to view like create/update/delete - responsible for all the stuff related to view like create/update/delete - FTS template, showing properties of node, showing sql in sql pane. + A view class for FTS Tempalte node derived from PGChildNodeView. This + class is responsible for all the stuff related to view like + create/update/delete responsible for all the stuff related to view + like create/update/delete FTS template, showing properties of node, + showing sql in sql pane. Methods: ------- @@ -113,11 +118,13 @@ class FtsTemplateView(PGChildNodeView): - This function is used to list all the nodes within that collection. * nodes() - - This function will used to create all the child node within that collection. + - This function will used to create all the child node within that + collection. Here it will create all the FTS Template nodes. * properties(gid, sid, did, scid, tid) - - This function will show the properties of the selected FTS Template node + - This function will show the properties of the selected FTS Template + node * create(gid, sid, did, scid) - This function will create the new FTS Template object @@ -129,22 +136,27 @@ class FtsTemplateView(PGChildNodeView): - This function will drop the FTS Template object * msql(gid, sid, did, scid, tid) - - This function is used to return modified SQL for the selected FTS Template node + - This function is used to return modified SQL for the selected FTS + Template node * get_sql(data, tid) - This function will generate sql from model data * sql(gid, sid, did, scid, tid): - - This function will generate sql to show it in sql pane for the selected FTS Template node. + - This function will generate sql to show it in sql pane for the selected + FTS Template node. * get_type(): - - This function will fetch all the types for source and target types select control. + - This function will fetch all the types for source and target types + select control. * dependents(gid, sid, did, scid, tid): - - This function get the dependents and return ajax response for the Fts Tempalte node. + - This function get the dependents and return ajax response for the + Fts Template node. * dependencies(self, gid, sid, did, scid, tid): - - This function get the dependencies and return ajax response for the FTS Tempalte node. + - This function get the dependencies and return ajax response for the + FTS Template node. """ @@ -212,9 +224,11 @@ class FtsTemplateView(PGChildNodeView): self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) - self.template_path = 'fts_template/sql/#{0}#'.format(self.manager.version) + self.template_path = 'fts_template/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) + return wrap @check_precondition @@ -502,7 +516,7 @@ class FtsTemplateView(PGChildNodeView): return make_json_response( data=SQL, status=200 - ) + ) def get_sql(self, gid, sid, did, scid, data, tid=None): """ @@ -533,7 +547,8 @@ class FtsTemplateView(PGChildNodeView): old_data = res['rows'][0] # If user has changed the schema then fetch new schema directly - # using its oid otherwise fetch old schema name using fts template oid + # using its oid otherwise fetch old schema name using + # fts template oid sql = render_template( "/".join([self.template_path, 'schema.sql']), data=data) @@ -564,7 +579,9 @@ class FtsTemplateView(PGChildNodeView): data=new_data, o_data=old_data ) # Fetch sql query for modified data - return sql.strip('\n'), data['name'] if 'name' in data else old_data['name'] + if 'name' in data: + return sql.strip('\n'), data['name'] + return sql.strip('\n'), old_data['name'] else: # Fetch schema name from schema oid sql = render_template("/".join([self.template_path, 'schema.sql']), @@ -578,9 +595,11 @@ class FtsTemplateView(PGChildNodeView): new_data = data.copy() new_data['schema'] = schema - if 'tmpllexize' in new_data and \ - 'name' in new_data and \ - 'schema' in new_data: + if ( + 'tmpllexize' in new_data and + 'name' in new_data and + 'schema' in new_data + ): sql = render_template("/".join([self.template_path, 'create.sql']), data=new_data, @@ -667,15 +686,15 @@ class FtsTemplateView(PGChildNodeView): if not status: return internal_server_error( gettext( - "Could not generate reversed engineered query for the FTS Template.\n{0}").format( - res - ) + "Could not generate reversed engineered query for the " + "FTS Template.\n{0}").format(res) ) if res is None: return gone( gettext( - "Could not generate reversed engineered query for FTS Template node.") + "Could not generate reversed engineered query for " + "FTS Template node.") ) return ajax_response(response=res) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_add.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_add.py index 022d1080..12c44a85 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_add.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_add.py @@ -28,7 +28,8 @@ class FtsTemplateAddTestCase(BaseTestGenerator): scenarios = [ # Fetching default URL for FTS template node. ( - 'Fetch FTS templates Node URL', dict(url='/browser/fts_template/obj/')) + 'Fetch FTS templates Node URL', + dict(url='/browser/fts_template/obj/')) ] def runTest(self): diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_get.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_get.py index 2aac2c8a..fa64648f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_get.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/test_fts_templates_get.py @@ -26,7 +26,9 @@ class FtsTemplateGetTestCase(BaseTestGenerator): scenarios = [ # Fetching default URL for FTS template node. - ('Fetch FTS templates Node URL', dict(url='/browser/fts_template/obj/')) + ('Fetch FTS templates Node URL', dict( + url='/browser/fts_template/obj/') + ) ] def setUp(self): diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/utils.py index f373ebe6..35c19a53 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/tests/utils.py @@ -30,17 +30,20 @@ def create_fts_template(server, db_name, schema_name, fts_temp_name): server['sslmode']) pg_cursor = connection.cursor() - query = "DROP TEXT SEARCH TEMPLATE IF EXISTS " + schema_name + "." + fts_temp_name + query = "DROP TEXT SEARCH TEMPLATE IF EXISTS " + schema_name + "." + \ + fts_temp_name pg_cursor.execute(query) - query = "CREATE TEXT SEARCH TEMPLATE " + schema_name + "." + fts_temp_name + \ + query = "CREATE TEXT SEARCH TEMPLATE " + schema_name + "." + \ + fts_temp_name + \ "(INIT=dispell_init, LEXIZE=dispell_lexize)" pg_cursor.execute(query) connection.commit() # Get 'oid' from newly created template pg_cursor.execute("select oid from pg_catalog.pg_ts_template where " - "tmplname = '%s' order by oid ASC limit 1" % fts_temp_name) + "tmplname = '%s' order by oid ASC limit 1" % + fts_temp_name) oid = pg_cursor.fetchone() fts_temp_id = '' diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py index 2b7d2331..506964b4 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py @@ -260,13 +260,14 @@ class FunctionView(PGChildNodeView, DataTypeReader): for arg in self.required_args: if (arg not in req or req[arg] == '') or \ - (arg == 'probin' and req['lanname'] == 'c' - and (arg not in req or req[arg] == '')): + (arg == 'probin' and req['lanname'] == 'c' and + (arg not in req or req[arg] == '')): return make_json_response( status=410, success=0, errormsg=gettext( - "Could not find the required parameter (%s)." % arg + "Could not find the required parameter (%s)." % + arg ) ) @@ -276,14 +277,16 @@ class FunctionView(PGChildNodeView, DataTypeReader): 'seclabels', 'acl', 'args'] for key in req: - if key in list_params and req[key] != '' \ - and req[key] is not None: + if ( + key in list_params and req[key] != '' and + req[key] is not None + ): # Coverts string into python list as expected. data[key] = json.loads(req[key], encoding='utf-8') elif ( - key == 'proretset' or key == 'proisstrict' or - key == 'prosecdef' or key == 'proiswindow' or - key == 'proleakproof' + key == 'proretset' or key == 'proisstrict' or + key == 'prosecdef' or key == 'proiswindow' or + key == 'proleakproof' ): data[key] = True if ( req[key] == 'true' or req[key] is True) \ @@ -392,7 +395,8 @@ class FunctionView(PGChildNodeView, DataTypeReader): if fnid is not None: if len(rset['rows']) == 0: return gone( - _("Could not find the specified %s.").format(self.node_type) + _("Could not find the specified %s.").format( + self.node_type) ) row = rset['rows'][0] @@ -572,7 +576,7 @@ class FunctionView(PGChildNodeView, DataTypeReader): proargnames[i] if len(proargnames) > i else '', proargdefaultvals[i] if len(proargdefaultvals) > i else '' ) - for i in range(len(proargtypes))] + for i in range(len(proargtypes))] proargs = {"proargs": ", ".join(proargs)} @@ -654,9 +658,12 @@ class FunctionView(PGChildNodeView, DataTypeReader): fnid: Function Id """ - condition = "(typtype IN ('b', 'c', 'd', 'e', 'p', 'r') AND typname NOT IN ('any', 'trigger', 'language_handler', 'event_trigger'))" + condition = "(typtype IN ('b', 'c', 'd', 'e', 'p', 'r') AND " \ + "typname NOT IN ('any', 'trigger', 'language_handler', " \ + "'event_trigger'))" if self.blueprint.show_system_objects: - condition += " AND nspname NOT LIKE E'pg\\\\_toast%' AND nspname NOT LIKE E'pg\\\\_temp%'" + condition += " AND nspname NOT LIKE E'pg\\\\_toast%' AND " \ + "nspname NOT LIKE E'pg\\\\_temp%'" # Get Types status, types = self.get_types(self.conn, condition, False, scid) @@ -697,7 +704,7 @@ class FunctionView(PGChildNodeView, DataTypeReader): data=res, status=200 ) - except: + except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() current_app.logger.error(traceback.print_exception( exc_type, @@ -810,7 +817,8 @@ class FunctionView(PGChildNodeView, DataTypeReader): try: # Fetch Name and Schema Name to delete the Function. SQL = render_template("/".join([self.sql_template_path, - 'delete.sql']), scid=scid, fnid=fnid) + 'delete.sql']), scid=scid, + fnid=fnid) status, res = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=res) @@ -941,13 +949,18 @@ class FunctionView(PGChildNodeView, DataTypeReader): resp_data['args'] = resp_data['arguments'] for a in args_list: - if (('argmode' in a and a['argmode'] != 'OUT' and + if ( + ( + 'argmode' in a and a['argmode'] != 'OUT' and a['argmode'] is not None - ) or 'argmode' not in a): + ) or 'argmode' not in a + ): if 'argmode' in a: args += a['argmode'] + " " - if 'argname' in a and a['argname'] != '' \ - and a['argname'] is not None: + if ( + 'argname' in a and a['argname'] != '' and + a['argname'] is not None + ): args += self.qtIdent( self.conn, a['argname']) + " " if 'argtype' in a: @@ -970,8 +983,8 @@ class FunctionView(PGChildNodeView, DataTypeReader): # Get Schema Name from its OID. if 'pronamespace' in resp_data: - resp_data['pronamespace'] = self._get_schema(resp_data[ - 'pronamespace']) + resp_data['pronamespace'] = self._get_schema( + resp_data['pronamespace']) SQL = render_template("/".join([self.sql_template_path, 'get_definition.sql'] @@ -982,11 +995,11 @@ class FunctionView(PGChildNodeView, DataTypeReader): if not status: return internal_server_error(errormsg=res) - name_with_default_args = self.qtIdent(self.conn, - res['rows'][0]['nspname'], - res['rows'][0][ - 'proname']) + '(' + \ - res['rows'][0]['func_args'] + ')' + name_with_default_args = self.qtIdent( + self.conn, + res['rows'][0]['nspname'], + res['rows'][0]['proname'] + ) + '(' + res['rows'][0]['func_args'] + ')' # Add newline and tab before each argument to format name_with_default_args = name_with_default_args.replace( ', ', ',\r\t').replace('(', '(\r\t') @@ -996,13 +1009,14 @@ class FunctionView(PGChildNodeView, DataTypeReader): resp_data['acl'] = parse_priv_to_db(resp_data['acl'], ['X']) # Check Revoke all for public - resp_data['revoke_all'] = self._set_revoke_all(resp_data['acl']) + resp_data['revoke_all'] = self._set_revoke_all( + resp_data['acl']) # Generate sql for "SQL panel" # func_def is procedure signature with default arguments # query_for - To distinguish the type of call func_def = render_template("/".join([self.sql_template_path, - 'create.sql']), + 'create.sql']), data=resp_data, query_type="create", func_def=name_with_default_args, query_for="sql_panel") @@ -1011,15 +1025,17 @@ class FunctionView(PGChildNodeView, DataTypeReader): # Get Schema Name from its OID. if 'pronamespace' in resp_data: - resp_data['pronamespace'] = self._get_schema(resp_data[ - 'pronamespace']) + resp_data['pronamespace'] = self._get_schema( + resp_data['pronamespace'] + ) # Parse privilege data if 'acl' in resp_data: resp_data['acl'] = parse_priv_to_db(resp_data['acl'], ['X']) # Check Revoke all for public - resp_data['revoke_all'] = self._set_revoke_all(resp_data['acl']) + resp_data['revoke_all'] = self._set_revoke_all( + resp_data['acl']) SQL = render_template("/".join([self.sql_template_path, 'get_definition.sql'] @@ -1030,11 +1046,16 @@ class FunctionView(PGChildNodeView, DataTypeReader): if not status: return internal_server_error(errormsg=res) - name_with_default_args = self.qtIdent(self.conn, - res['rows'][0]['nspname'], res['rows'][0]['proname']) + '(' + res['rows'][0]['func_args'] + ')' + name_with_default_args = self.qtIdent( + self.conn, + res['rows'][0]['nspname'], + res['rows'][0]['proname'] + ) + '(' + res['rows'][0]['func_args'] + ')' # Add newline and tab before each argument to format - name_with_default_args = name_with_default_args.replace(', ', ',\r\t').replace('(', - '(\r\t') + name_with_default_args = name_with_default_args.replace( + ', ', + ',\r\t' + ).replace('(', '(\r\t') # Generate sql for "SQL panel" # func_def is function signature with default arguments @@ -1107,8 +1128,9 @@ class FunctionView(PGChildNodeView, DataTypeReader): # Get Schema Name from its OID. if 'pronamespace' in data: - data['pronamespace'] = self._get_schema(data[ - 'pronamespace']) + data['pronamespace'] = self._get_schema( + data['pronamespace'] + ) if 'provolatile' in data: data['provolatile'] = vol_dict[data['provolatile']] @@ -1127,14 +1149,16 @@ class FunctionView(PGChildNodeView, DataTypeReader): ) # Get Schema Name - old_data['pronamespace'] = self._get_schema(old_data[ - 'pronamespace']) + old_data['pronamespace'] = self._get_schema( + old_data['pronamespace'] + ) if 'provolatile' in old_data: old_data['provolatile'] = vol_dict[old_data['provolatile']] if 'proparallel' in old_data: - old_data['proparallel'] = parallel_dict[old_data['proparallel']] + old_data['proparallel'] = parallel_dict[ + old_data['proparallel']] # If any of the below argument is changed, # then CREATE OR REPLACE SQL statement should be called @@ -1145,8 +1169,7 @@ class FunctionView(PGChildNodeView, DataTypeReader): data['change_func'] = False for arg in fun_change_args: - if arg == 'arguments' and arg in data and len(data[arg]) \ - > 0: + if arg == 'arguments' and arg in data and len(data[arg]) > 0: data['change_func'] = True elif arg in data: data['change_func'] = True @@ -1204,8 +1227,10 @@ class FunctionView(PGChildNodeView, DataTypeReader): # Prepare final dict of new and old variables for name, val in old_data['chngd_variables'].items(): - if name not in chngd_variables and name not in \ - del_variables: + if ( + name not in chngd_variables and + name not in del_variables + ): chngd_variables[name] = val # Prepare dict in [{'name': var_name, 'value': var_val},..] @@ -1243,15 +1268,19 @@ class FunctionView(PGChildNodeView, DataTypeReader): elif 'args' in data and len(data['args']) > 0: args_list = data['args'] for a in args_list: - if (('argmode' in a and a['argmode'] != 'OUT' and - a['argmode'] is not None - ) or 'argmode' not in a): + if ( + ( + 'argmode' in a and a['argmode'] != 'OUT' and + a['argmode'] is not None + ) or 'argmode' not in a + ): if 'argmode' in a: args += a['argmode'] + " " - if 'argname' in a and a['argname'] != '' \ - and a['argname'] is not None: - args += self.qtIdent( - self.conn, a['argname']) + " " + if ( + 'argname' in a and a['argname'] != '' and + a['argname'] is not None + ): + args += self.qtIdent(self.conn, a['argname']) + " " if 'argtype' in a: args += a['argtype'] args_without_name.append(a['argtype']) @@ -1353,7 +1382,7 @@ class FunctionView(PGChildNodeView, DataTypeReader): for p in privileges: if p['grantee'] == 'PUBLIC': revoke_all = False - break; + break return revoke_all @@ -1409,14 +1438,16 @@ class FunctionView(PGChildNodeView, DataTypeReader): """ # Fetch the function definition. SQL = render_template("/".join([self.sql_template_path, - 'get_definition.sql']), fnid=fnid, scid=scid) + 'get_definition.sql']), fnid=fnid, + scid=scid) status, res = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=res) - name = self.qtIdent(self.conn, res['rows'][0]['nspname'], - res['rows'][0]['proname']) + '(' + \ - res['rows'][0]['func_with_identity_arguments'] + ')' + name = self.qtIdent( + self.conn, res['rows'][0]['nspname'], + res['rows'][0]['proname'] + ) + '(' + res['rows'][0]['func_with_identity_arguments'] + ')' # Fetch only arguments argString = name[name.rfind('('):].strip('(').strip(')') @@ -1498,7 +1529,8 @@ class FunctionView(PGChildNodeView, DataTypeReader): # Get schema name status, schema_name = self.conn.execute_scalar( render_template( - 'schema/pg/#{0}#/sql/get_name.sql'.format(self.manager.version), + 'schema/pg/#{0}#/sql/get_name.sql'.format( + self.manager.version), scid=scid ) ) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_add.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_add.py index c9da16ae..8d50ffee 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_add.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_add.py @@ -102,8 +102,9 @@ class TriggerFuncAddTestCase(BaseTestGenerator): schema_id = data['pronamespace'] response = self.tester.post( self.url + str(utils.SERVER_GROUP) + '/' + - str(server_id) + '/' + str(db_id) + '/' + str(schema_id) - + '/', data=json.dumps(data), content_type='html/json') + str(server_id) + '/' + str(db_id) + '/' + str(schema_id) + + '/', data=json.dumps(data), content_type='html/json' + ) self.assertEquals(response.status_code, 200) # Disconnect the database diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_delete.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_delete.py index 54883606..23cfce52 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_delete.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_delete.py @@ -62,10 +62,11 @@ class TriggerFuncDeleteTestCase(BaseTestGenerator): raise Exception("Could not find the schema to add the collation.") trigger_func_id = self.function_info[0] response = self.tester.delete( - self.url + str(utils.SERVER_GROUP) + '/' - + str(server_id) + '/' + str(db_id) + '/' + + self.url + str(utils.SERVER_GROUP) + '/' + str(server_id) + '/' + + str(db_id) + '/' + str(self.schema_id) + '/' + str(trigger_func_id), - content_type='html/json') + content_type='html/json' + ) self.assertEquals(response.status_code, 200) # Disconnect the database database_utils.disconnect_database(self, server_id, db_id) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_get.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_get.py index 1dc60de5..6e4c5b47 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_get.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_get.py @@ -63,8 +63,8 @@ class TriggerFuncGetTestCase(BaseTestGenerator): raise Exception("Could not find the schema to add the collation.") trigger_func_id = self.function_info[0] response = self.tester.get( - self.url + str(utils.SERVER_GROUP) + '/' - + str(server_id) + '/' + str(db_id) + '/' + + self.url + str(utils.SERVER_GROUP) + '/' + str(server_id) + '/' + + str(db_id) + '/' + str(self.schema_id) + '/' + str(trigger_func_id), content_type='html/json') self.assertEquals(response.status_code, 200) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_put.py index 3fed203a..02561d9d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_put.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/test_trigger_func_put.py @@ -75,12 +75,13 @@ class TriggerFuncPutTestCase(BaseTestGenerator): "id": trigger_func_id } - put_response = self.tester.put(self.url + str(utils.SERVER_GROUP) + - '/' + str(server_id) + '/' + str(db_id) - + '/' + str(self.schema_id) + '/' + - str(trigger_func_id), - data=json.dumps(data), - follow_redirects=True) + put_response = self.tester.put( + self.url + str(utils.SERVER_GROUP) + + '/' + str(server_id) + '/' + str(db_id) + '/' + + str(self.schema_id) + '/' + + str(trigger_func_id), + data=json.dumps(data), + follow_redirects=True) self.assertEquals(put_response.status_code, 200) # Disconnect the database database_utils.disconnect_database(self, server_id, db_id) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/utils.py index 93e7b540..4facf608 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/tests/utils.py @@ -29,10 +29,12 @@ def create_trigger_function(server, db_name, schema_name, func_name, r_type = "event_trigger" if server_version != 0: r_type = "trigger" - query = "CREATE FUNCTION "+schema_name+"."+func_name+"()" \ + query = "CREATE FUNCTION " + schema_name + "." + func_name + \ + "()" \ " RETURNS {0} LANGUAGE 'plpgsql' STABLE LEAKPROOF" \ " SECURITY DEFINER SET enable_sort=true AS $BODY$ BEGIN" \ - " NULL; END; $BODY$".format(r_type) + " NULL; END; $BODY$".format( + r_type) pg_cursor.execute(query) connection.commit() # Get 'oid' from newly created function @@ -47,7 +49,7 @@ def create_trigger_function(server, db_name, schema_name, func_name, def create_trigger_function_with_trigger(server, db_name, schema_name, - func_name): + func_name): """This function add the trigger function to schema""" try: connection = utils.get_db_connection(db_name, @@ -57,7 +59,8 @@ def create_trigger_function_with_trigger(server, db_name, schema_name, server['port'], server['sslmode']) pg_cursor = connection.cursor() - query = "CREATE FUNCTION "+schema_name+"."+func_name+"()" \ + query = "CREATE FUNCTION " + schema_name + "." + func_name + \ + "()" \ " RETURNS trigger LANGUAGE 'plpgsql' STABLE LEAKPROOF" \ " SECURITY DEFINER SET enable_sort=true AS $BODY$ BEGIN" \ " NULL; END; $BODY$" 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 efa89fb7..c8a9a5ad 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 @@ -9,23 +9,25 @@ """Implements Package Node""" import re -import simplejson as json from functools import wraps -import pgadmin.browser.server_groups.servers.databases as database +import simplejson as json from flask import render_template, make_response, request, jsonify from flask_babel import gettext as _ + +import pgadmin.browser.server_groups.servers.databases as database +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils \ import SchemaChildModule from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ parse_priv_to_db from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, \ make_response as ajax_response, internal_server_error, \ precondition_required, gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -148,7 +150,8 @@ class PackageView(PGChildNodeView): "Connection to the server has been lost." ) ) - self.template_path = 'package/ppas/#{0}#'.format(self.manager.version) + self.template_path = 'package/ppas/#{0}#'.format( + self.manager.version) SQL = render_template( "/".join([self.template_path, 'get_schema.sql']), @@ -171,7 +174,8 @@ class PackageView(PGChildNodeView): @check_precondition(action='list') def list(self, gid, sid, did, scid): """ - This function is used to list all the package nodes within the collection. + This function is used to list all the package nodes within the + collection. Args: gid: Server Group ID @@ -182,7 +186,8 @@ class PackageView(PGChildNodeView): Returns: """ - SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid) + SQL = render_template("/".join([self.template_path, 'properties.sql']), + scid=scid) status, res = self.conn.execute_dict(SQL) if not status: @@ -195,7 +200,8 @@ class PackageView(PGChildNodeView): @check_precondition(action='nodes') def nodes(self, gid, sid, did, scid, pkgid=None): """ - This function is used to create all the child nodes within the collection. + This function is used to create all the child nodes within the + collection. Here it will create all the package nodes. Args: @@ -220,7 +226,7 @@ class PackageView(PGChildNodeView): if pkgid is not None: if len(rset['rows']) == 0: return gone( - errormsg=_("Could not find the package.") + errormsg=_("Could not find the package.") ) row = rset['rows'][0] @@ -305,7 +311,8 @@ class PackageView(PGChildNodeView): Returns: """ - SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid) + SQL = render_template("/".join([self.template_path, 'properties.sql']), + scid=scid, pkgid=pkgid) status, res = self.conn.execute_dict(SQL) if not status: @@ -316,8 +323,10 @@ class PackageView(PGChildNodeView): errormsg=_("Could not find the package in the database.") ) - res['rows'][0]['pkgheadsrc'] = self.get_inner(res['rows'][0]['pkgheadsrc']) - res['rows'][0]['pkgbodysrc'] = self.get_inner(res['rows'][0]['pkgbodysrc']) + res['rows'][0]['pkgheadsrc'] = self.get_inner( + res['rows'][0]['pkgheadsrc']) + res['rows'][0]['pkgbodysrc'] = self.get_inner( + res['rows'][0]['pkgbodysrc']) SQL = render_template("/".join([self.template_path, 'acl.sql']), scid=scid, @@ -425,7 +434,9 @@ class PackageView(PGChildNodeView): cascade = False try: - SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid) + SQL = render_template( + "/".join([self.template_path, 'properties.sql']), scid=scid, + pkgid=pkgid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) @@ -571,7 +582,9 @@ class PackageView(PGChildNodeView): if pkgid is not None: data['schema'] = self.schema - SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid) + SQL = render_template( + "/".join([self.template_path, 'properties.sql']), scid=scid, + pkgid=pkgid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) @@ -580,8 +593,10 @@ class PackageView(PGChildNodeView): errormsg=_("Could not find the package in the database.") ) - res['rows'][0]['pkgheadsrc'] = self.get_inner(res['rows'][0]['pkgheadsrc']) - res['rows'][0]['pkgbodysrc'] = self.get_inner(res['rows'][0]['pkgbodysrc']) + res['rows'][0]['pkgheadsrc'] = self.get_inner( + res['rows'][0]['pkgheadsrc']) + res['rows'][0]['pkgbodysrc'] = self.get_inner( + res['rows'][0]['pkgbodysrc']) SQL = render_template("/".join([self.template_path, 'acl.sql']), scid=scid, @@ -603,11 +618,14 @@ class PackageView(PGChildNodeView): for key in ['pkgacl']: if key in data and data[key] is not None: if 'added' in data[key]: - data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl) + data[key]['added'] = parse_priv_to_db( + data[key]['added'], self.acl) if 'changed' in data[key]: - data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl) + data[key]['changed'] = parse_priv_to_db( + data[key]['changed'], self.acl) if 'deleted' in data[key]: - data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl) + data[key]['deleted'] = parse_priv_to_db( + data[key]['deleted'], self.acl) # If name is not present with in update data then copy it # from old data @@ -623,7 +641,8 @@ class PackageView(PGChildNodeView): if 'pkgacl' in data: data['pkgacl'] = parse_priv_to_db(data['pkgacl'], self.acl) - SQL = render_template("/".join([self.template_path, 'create.sql']), data=data, conn=self.conn) + SQL = render_template("/".join([self.template_path, 'create.sql']), + data=data, conn=self.conn) return SQL, data['name'] @@ -640,7 +659,9 @@ class PackageView(PGChildNodeView): pkgid: Package ID """ try: - SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid) + SQL = render_template( + "/".join([self.template_path, 'properties.sql']), scid=scid, + pkgid=pkgid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) @@ -649,8 +670,10 @@ class PackageView(PGChildNodeView): errormsg=_("Could not find the package in the database.") ) - res['rows'][0]['pkgheadsrc'] = self.get_inner(res['rows'][0]['pkgheadsrc']) - res['rows'][0]['pkgbodysrc'] = self.get_inner(res['rows'][0]['pkgbodysrc']) + res['rows'][0]['pkgheadsrc'] = self.get_inner( + res['rows'][0]['pkgheadsrc']) + res['rows'][0]['pkgbodysrc'] = self.get_inner( + res['rows'][0]['pkgbodysrc']) SQL = render_template("/".join([self.template_path, 'acl.sql']), scid=scid, @@ -686,7 +709,7 @@ class PackageView(PGChildNodeView): return ajax_response(response=sql) except Exception as e: - return internal_server_error(errormsg=str(e)) + return internal_server_error(errormsg=str(e)) @check_precondition(action="dependents") def dependents(self, gid, sid, did, scid, pkgid): @@ -745,4 +768,5 @@ class PackageView(PGChildNodeView): return sql[start:end].strip("\n") + PackageView.register_node_view(blueprint) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbfuncs/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbfuncs/__init__.py index 600a2234..3b7e0be6 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbfuncs/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbfuncs/__init__.py @@ -13,9 +13,12 @@ import copy import re from functools import wraps -import pgadmin.browser.server_groups.servers.databases.schemas.packages as packages from flask import render_template, make_response from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases\ + .schemas.packages as packages +from config import PG_DEFAULT_DRIVER from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ DataTypeReader @@ -26,8 +29,6 @@ from pgadmin.utils.ajax import precondition_required from pgadmin.utils.driver import get_driver from pgadmin.utils.preferences import Preferences -from config import PG_DEFAULT_DRIVER - class EdbFuncModule(CollectionNodeModule): """ @@ -125,8 +126,8 @@ class EdbFuncView(PGChildNodeView, DataTypeReader): """ class EdbFuncView(PGChildNodeView, DataTypeReader) - This class inherits PGChildNodeView and DataTypeReader to get the different routes for - the module. + This class inherits PGChildNodeView and DataTypeReader to get the different + routes for the module. The class is responsible to Create, Read, Update and Delete operations for the Functions. @@ -461,7 +462,7 @@ class EdbFuncView(PGChildNodeView, DataTypeReader): proargnames[i] if len(proargnames) > i else '', proargdefaultvals[i] if len(proargdefaultvals) > i else '' ) - for i in range(len(proargtypes))] + for i in range(len(proargtypes))] proargs = {"proargs": ", ".join(proargs)} @@ -529,9 +530,10 @@ class EdbFuncView(PGChildNodeView, DataTypeReader): scid: Schema Id fnid: Function Id """ - SQL = render_template("/".join([self.sql_template_path, 'get_body.sql']), - scid=scid, - pkgid=pkgid) + SQL = render_template( + "/".join([self.sql_template_path, 'get_body.sql']), + scid=scid, + pkgid=pkgid) status, res = self.conn.execute_dict(SQL) if not status: @@ -620,6 +622,7 @@ class EdbFuncView(PGChildNodeView, DataTypeReader): return sql[start:end].strip("\n") + EdbFuncView.register_node_view(blueprint) @@ -709,6 +712,7 @@ class EdbProcModule(CollectionNodeModule): """ return False + procedure_blueprint = EdbProcModule(__name__) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbvars/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbvars/__init__.py index a32d3b2d..8758123b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbvars/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/edbvars/__init__.py @@ -9,12 +9,14 @@ """Implements Edb Functions/Edb Procedures Node.""" -import copy from functools import wraps -import pgadmin.browser.server_groups.servers.databases.schemas.packages as packages from flask import render_template, make_response from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases.schemas \ + .packages as packages +from config import PG_DEFAULT_DRIVER from pgadmin.browser.collection import CollectionNodeModule from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ DataTypeReader @@ -24,8 +26,6 @@ from pgadmin.utils.ajax import make_json_response, \ from pgadmin.utils.ajax import precondition_required from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER - class EdbVarModule(CollectionNodeModule): """ @@ -99,6 +99,7 @@ class EdbVarModule(CollectionNodeModule): """ return False + blueprint = EdbVarModule(__name__) @@ -106,7 +107,8 @@ class EdbVarView(PGChildNodeView, DataTypeReader): """ class EdbFuncView(PGChildNodeView, DataTypeReader) - This class inherits PGChildNodeView and DataTypeReader to get the different routes for + This class inherits PGChildNodeView and DataTypeReader to get the different + routes for the module. The class is responsible to Create, Read, Update and Delete operations for @@ -315,9 +317,10 @@ class EdbVarView(PGChildNodeView, DataTypeReader): pkgid: Package Id varid: variable Id """ - SQL = render_template("/".join([self.sql_template_path, 'properties.sql']), - varid=varid, - pkgid=pkgid) + SQL = render_template( + "/".join([self.sql_template_path, 'properties.sql']), + varid=varid, + pkgid=pkgid) status, res = self.conn.execute_dict(SQL) if not status: @@ -335,4 +338,5 @@ class EdbVarView(PGChildNodeView, DataTypeReader): return ajax_response(response=sql) + EdbVarView.register_node_view(blueprint) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_delete.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_delete.py index b73e3985..28dbd1f5 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_delete.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_delete.py @@ -35,7 +35,7 @@ class PackageDeleteTestCase(BaseTestGenerator): self.schema_id = schema_info["schema_id"] self.schema_name = schema_info["schema_name"] self.db_name = parent_node_dict["database"][-1]["db_name"] - self.pkg_name= "pkg_%s" % str(uuid.uuid4())[1:8] + self.pkg_name = "pkg_%s" % str(uuid.uuid4())[1:8] self.proc_name = "proc_%s" % str(uuid.uuid4())[1:8] self.server_id = schema_info["server_id"] self.db_id = schema_info["db_id"] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_get.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_get.py index 8b3c2b18..c02045c1 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_get.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_get.py @@ -35,7 +35,7 @@ class PackageGetTestCase(BaseTestGenerator): self.schema_id = schema_info["schema_id"] self.schema_name = schema_info["schema_name"] self.db_name = parent_node_dict["database"][-1]["db_name"] - self.pkg_name= "pkg_%s" % str(uuid.uuid4())[1:8] + self.pkg_name = "pkg_%s" % str(uuid.uuid4())[1:8] self.proc_name = "proc_%s" % str(uuid.uuid4())[1:8] self.server_id = schema_info["server_id"] self.db_id = schema_info["db_id"] @@ -70,11 +70,13 @@ class PackageGetTestCase(BaseTestGenerator): if not schema_response: raise Exception("Could not find the schema.") - response = self.tester.get(self.url - + str(utils.SERVER_GROUP) + '/' + - str(self.server_id) + '/' + str(self.db_id) + '/' + - str(self.schema_id) + '/' + str(self.package_id), - content_type='html/json') + response = self.tester.get(self.url + + str(utils.SERVER_GROUP) + '/' + + str(self.server_id) + '/' + + str(self.db_id) + '/' + + str(self.schema_id) + '/' + + str(self.package_id), + content_type='html/json') self.assertEquals(response.status_code, 200) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_put.py index 7c2b00ec..fd0cbf50 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_put.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/test_package_put.py @@ -36,7 +36,7 @@ class PackagePutTestCase(BaseTestGenerator): self.schema_id = schema_info["schema_id"] self.schema_name = schema_info["schema_name"] self.db_name = parent_node_dict["database"][-1]["db_name"] - self.pkg_name= "pkg_%s" % str(uuid.uuid4())[1:8] + self.pkg_name = "pkg_%s" % str(uuid.uuid4())[1:8] self.proc_name = "proc_%s" % str(uuid.uuid4())[1:8] self.server_id = schema_info["server_id"] self.db_id = schema_info["db_id"] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/utils.py index 4465e4c7..80bac6f2 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/packages/tests/utils.py @@ -38,8 +38,9 @@ def create_package(server, db_name, schema_name, pkg_name, proc_name): server['sslmode']) pg_cursor = connection.cursor() query = "CREATE OR REPLACE PACKAGE %s.%s IS PROCEDURE %s(); END %s; " \ - "CREATE OR REPLACE PACKAGE BODY %s.%s IS PROCEDURE %s() IS BEGIN " \ - "dbms_output.put_line('Test_pkg.Proc...'); END; END %s;" % \ + "CREATE OR REPLACE PACKAGE BODY %s.%s IS PROCEDURE %s() IS " \ + "BEGIN dbms_output.put_line('Test_pkg.Proc...'); END; " \ + "END %s;" % \ (schema_name, pkg_name, proc_name, pkg_name, schema_name, pkg_name, proc_name, pkg_name) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py index 47d22a74..94062de7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py @@ -24,6 +24,7 @@ from pgadmin.utils.ajax import precondition_required from pgadmin.utils.driver import get_driver from config import PG_DEFAULT_DRIVER from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -203,7 +204,8 @@ class SynonymView(PGChildNodeView): ) # we will set template path for sql scripts - self.template_path = 'synonym/sql/#{0}#'.format(self.manager.version) + self.template_path = 'synonym/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) @@ -212,7 +214,8 @@ class SynonymView(PGChildNodeView): @check_precondition def list(self, gid, sid, did, scid): """ - This function is used to list all the synonym nodes within that collection. + This function is used to list all the synonym nodes within that + collection. Args: gid: Server group ID @@ -238,7 +241,8 @@ class SynonymView(PGChildNodeView): @check_precondition def nodes(self, gid, sid, did, scid): """ - This function will used to create all the child node within that collection. + This function will used to create all the child node within that + collection. Here it will create all the synonym node. Args: @@ -335,19 +339,23 @@ class SynonymView(PGChildNodeView): data[k] = v is_valid_request = True - if 'trgTyp' not in data or data['trgTyp'] is None or \ - data['trgTyp'].strip() == '': + if ( + 'trgTyp' not in data or data['trgTyp'] is None or + data['trgTyp'].strip() == '' + ): is_valid_request = False - if 'trgSchema' not in data or data['trgSchema'] is None or \ - data['trgSchema'].strip() == '': + if ( + 'trgSchema' not in data or data['trgSchema'] is None or + data['trgSchema'].strip() == '' + ): is_valid_request = False if is_valid_request: sql = render_template("/".join([self.template_path, 'get_objects.sql']), - trgTyp=data['trgTyp'], - trgSchema=data['trgSchema']) + trgTyp=data['trgTyp'], + trgSchema=data['trgSchema']) status, rset = self.conn.execute_dict(sql) if not status: @@ -642,7 +650,7 @@ class SynonymView(PGChildNodeView): return internal_server_error(errormsg=res) if len(res['rows']) > 0: - data = res['rows'][0] + data = res['rows'][0] else: return gone( gettext('The specified synonym could not be found.') diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/__init__.py index 3d256681..3cac44f7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/__init__.py @@ -14,4 +14,3 @@ class SynonymTestGenerator(BaseTestGenerator): def generate_tests(self): return - diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/test_synonym_add.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/test_synonym_add.py index 07c194dd..517b6453 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/test_synonym_add.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/tests/test_synonym_add.py @@ -72,8 +72,8 @@ class SynonymAddTestCase(BaseTestGenerator): } response = self.tester.post( - self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) - + '/' + str(self.db_id) + '/' + str(self.schema_id) + '/', + self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) + + '/' + str(self.db_id) + '/' + str(self.schema_id) + '/', data=json.dumps(data), content_type='html/json') self.assertEquals(response.status_code, 200) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py index 2bd30d1c..1160cfbb 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py @@ -349,7 +349,6 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings): if not status: return internal_server_error(errormsg=rset) - for row in rset['rows']: if 'is_partitioned' in row and row['is_partitioned']: icon = "icon-partition" diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py index 3cdc292d..0cbcaf11 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py @@ -167,16 +167,19 @@ class ColumnMsqlTestCase(BaseTestGenerator): if not expected_precision and hasattr(self, 'old_precision'): expected_precision = self.old_precision - self.assertEquals(response_data['data'], - self.expected_res.format( - **dict([('schema', self.schema_name), - ('table', self.table_name), - ('column', self.column_name), - ('len', expected_len), - ('precision', expected_precision) - ] - ) - )) + self.assertEquals( + response_data['data'], + self.expected_res.format( + **dict( + [('schema', self.schema_name), + ('table', self.table_name), + ('column', self.column_name), + ('len', expected_len), + ('precision', expected_precision) + ] + ) + ) + ) def tearDown(self): # Disconnect the database diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_schema_delete.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_schema_delete.py index c4ada6fa..ae8e047b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_schema_delete.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_schema_delete.py @@ -56,8 +56,8 @@ class SchemaDeleteTestCase(BaseTestGenerator): if not schema_response: raise Exception("Could not find the schema to delete.") - response = self.tester.delete(self.url + str(utils.SERVER_GROUP) - + '/' + str(server_id) + '/' + + response = self.tester.delete(self.url + str(utils.SERVER_GROUP) + + '/' + str(server_id) + '/' + str(db_id) + '/' + str(schema_id), follow_redirects=True) self.assertEquals(response.status_code, 200) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_utils.py index 7550ce4d..826c003c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/test_utils.py @@ -9,7 +9,8 @@ import sys -from pgadmin.browser.server_groups.servers.databases.schemas.utils import DataTypeReader +from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ + DataTypeReader from pgadmin.utils.route import BaseTestGenerator if sys.version_info < (3, 3): @@ -55,7 +56,8 @@ class DataTypeReaderTest(BaseTestGenerator): expected_sql_template_path='someplate/where/templates/are', expected_function_output=_default_expected_function_output )), - ('When no data_type_template_path is present in class, should create template path with version number', + ('When no data_type_template_path is present in class, ' + 'should create template path with version number', dict( manager=_default_manager, execute_return_values=_default_database_response, @@ -81,7 +83,8 @@ class DataTypeReaderTest(BaseTestGenerator): )) ] - @patch('pgadmin.browser.server_groups.servers.databases.schemas.utils.render_template') + @patch('pgadmin.browser.server_groups.servers.databases.schemas.utils' + '.render_template') def runTest(self, template_mock): template_mock.return_value = 'Some SQL' connection = Mock() @@ -101,7 +104,8 @@ class DataTypeReaderTest(BaseTestGenerator): reader.data_type_template_path = self.data_type_template_path except AttributeError: '' - result = reader.get_types(connection, self.sql_condition, self.add_serials, self.schema_oid) + result = reader.get_types(connection, self.sql_condition, + self.add_serials, self.schema_oid) self.assertEqual(result[1], self.expected_function_output) self.assertTrue(result[0]) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/utils.py index ab4082fc..bcf3ba85 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tests/utils.py @@ -26,24 +26,24 @@ def get_schema_config_data(db_user): "name": "test_schema_{0}".format(str(uuid.uuid4())[1:8]), "namespaceowner": db_user, "nspacl": [ - { - "grantee": db_user, - "grantor": db_user, - "privileges": - [ - { + { + "grantee": db_user, + "grantor": db_user, + "privileges": + [ + { "privilege_type": "C", "privilege": True, "with_grant": False - }, - { + }, + { "privilege_type": "U", "privilege": True, "with_grant": False - } - ] - } - ], + } + ] + } + ], "seclabels": [] } return data diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py index a5ed56ab..2395439c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py @@ -9,22 +9,24 @@ """ Implements Type Node """ -import simplejson as json from functools import wraps -import pgadmin.browser.server_groups.servers.databases as database +import simplejson as json from flask import render_template, request, jsonify from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases as database +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils \ import SchemaChildModule, DataTypeReader from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ parse_priv_to_db from pgadmin.browser.utils import PGChildNodeView +from pgadmin.utils import IS_PY2 from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.driver import get_driver -from config import PG_DEFAULT_DRIVER -from pgadmin.utils import IS_PY2 + # If we are in Python3 if not IS_PY2: unicode = str @@ -203,9 +205,11 @@ class TypeView(PGChildNodeView, DataTypeReader): 'get_stypes': [{'get': 'get_subtypes'}, {'get': 'get_subtypes'}], 'get_subopclass': [{'get': 'get_subtype_opclass'}, {'get': 'get_subtype_opclass'}], - 'get_stypediff': [{'get': 'get_subtype_diff'}, {'get': 'get_subtype_diff'}], + 'get_stypediff': [{'get': 'get_subtype_diff'}, + {'get': 'get_subtype_diff'}], 'get_canonical': [{'get': 'get_canonical'}, {'get': 'get_canonical'}], - 'get_collations': [{'get': 'get_collations'}, {'get': 'get_collations'}], + 'get_collations': [{'get': 'get_collations'}, + {'get': 'get_collations'}], 'get_external_functions': [{'get': 'get_external_functions_list'}, {'get': 'get_external_functions_list'}] }) @@ -221,14 +225,18 @@ class TypeView(PGChildNodeView, DataTypeReader): def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] - self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) + self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( + kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # We need datlastsysoid to check if current type is system type - self.datlastsysoid = self.manager.db_info[ - kwargs['did'] - ]['datlastsysoid'] if self.manager.db_info is not None and \ - kwargs['did'] in self.manager.db_info else 0 + self.datlastsysoid = 0 + if ( + self.manager.db_info is not None and + kwargs['did'] in self.manager.db_info + ): + self.datlastsysoid = self.manager.db_info[kwargs['did']][ + 'datlastsysoid'] # Declare allows acl on type self.acl = ['U'] @@ -243,12 +251,14 @@ class TypeView(PGChildNodeView, DataTypeReader): ) return f(*args, **kwargs) + return wrap @check_precondition def list(self, gid, sid, did, scid): """ - This function is used to list all the type nodes within that collection. + This function is used to list all the type nodes within that + collection. Args: gid: Server group ID @@ -261,10 +271,11 @@ class TypeView(PGChildNodeView, DataTypeReader): JSON of available type nodes """ - SQL = render_template("/".join([self.template_path, 'properties.sql']), - scid=scid, - datlastsysoid=self.datlastsysoid, - show_system_objects=self.blueprint.show_system_objects) + SQL = render_template( + "/".join([self.template_path, 'properties.sql']), + scid=scid, + datlastsysoid=self.datlastsysoid, + show_system_objects=self.blueprint.show_system_objects) status, res = self.conn.execute_dict(SQL) @@ -278,7 +289,8 @@ class TypeView(PGChildNodeView, DataTypeReader): @check_precondition def node(self, gid, sid, did, scid, tid): """ - This function will used to create all the child node within that collection. + This function will used to create all the child node within that + collection. Here it will create all the type node. Args: @@ -292,24 +304,26 @@ class TypeView(PGChildNodeView, DataTypeReader): JSON of available type child nodes """ - SQL = render_template("/".join([self.template_path, - 'nodes.sql']), - scid=scid, - tid=tid, - show_system_objects=self.blueprint.show_system_objects) + SQL = render_template( + "/".join([self.template_path, + 'nodes.sql']), + scid=scid, + tid=tid, + show_system_objects=self.blueprint.show_system_objects) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) if len(rset['rows']) == 0: - return gone(gettext("""Could not find the type in the database.""")) + return gone( + gettext("""Could not find the type in the database.""")) res = self.blueprint.generate_browser_node( - rset['rows'][0]['oid'], - scid, - rset['rows'][0]['name'], - icon="icon-%s" % self.node_type - ) + rset['rows'][0]['oid'], + scid, + rset['rows'][0]['name'], + icon="icon-%s" % self.node_type + ) return make_json_response( data=res, @@ -319,7 +333,8 @@ class TypeView(PGChildNodeView, DataTypeReader): @check_precondition def nodes(self, gid, sid, did, scid): """ - This function will used to create all the child node within that collection. + This function will used to create all the child node within that + collection. Here it will create all the type node. Args: @@ -334,9 +349,10 @@ class TypeView(PGChildNodeView, DataTypeReader): """ res = [] - SQL = render_template("/".join([self.template_path, - 'nodes.sql']), scid=scid, - show_system_objects=self.blueprint.show_system_objects) + SQL = render_template( + "/".join([self.template_path, + 'nodes.sql']), scid=scid, + show_system_objects=self.blueprint.show_system_objects) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) @@ -394,7 +410,8 @@ class TypeView(PGChildNodeView, DataTypeReader): def additional_properties(self, copy_dict, tid): """ - We will use this function to add additional properties according to type + We will use this function to add additional properties according to + type Returns: additional properties for type like range/composite/enum @@ -403,7 +420,8 @@ class TypeView(PGChildNodeView, DataTypeReader): # Fetching type of type of_type = copy_dict['typtype'] res = dict() - # If type is of Composite then we need to add members list in our output + # If type is of Composite then we need to add members list in our + # output if of_type == 'c': SQL = render_template("/".join([self.template_path, 'additional_properties.sql']), @@ -421,10 +439,14 @@ class TypeView(PGChildNodeView, DataTypeReader): for row in rset['rows']: # We will fetch Full type name - typelist = ' '.join([row['attname'], row['fulltype']]) - if not row['collname'] or (row['collname'] == 'default' - and row['collnspname'] == 'pg_catalog'): + if ( + not row['collname'] or + ( + row['collname'] == 'default' and + row['collnspname'] == 'pg_catalog' + ) + ): full_collate = '' collate = '' else: @@ -437,9 +459,11 @@ class TypeView(PGChildNodeView, DataTypeReader): is_tlength = False is_precision = False if 'elemoid' in row: - is_tlength, is_precision, typeval = self.get_length_precision(row['elemoid']) + is_tlength, is_precision, typeval = \ + self.get_length_precision(row['elemoid']) - # Below logic will allow us to split length, precision from type name for grid + # Below logic will allow us to split length, precision from + # type name for grid import re t_len = None t_prec = None @@ -457,18 +481,19 @@ class TypeView(PGChildNodeView, DataTypeReader): t_len = matchObj.group(1) t_prec = None - type_name = DataTypeReader.parse_type_name(row['typname']) row['type'] = self._cltype_formatter(type_name) row['hasSqrBracket'] = self.hasSqrBracket row = self.convert_length_precision_to_string(row) composite_lst.append({ - 'attnum': row['attnum'], 'member_name': row['attname'], 'type': type_name, + 'attnum': row['attnum'], 'member_name': row['attname'], + 'type': type_name, 'collation': full_collate, 'cltype': row['type'], 'tlength': t_len, 'precision': t_prec, 'is_tlength': is_tlength, 'is_precision': is_precision, - 'hasSqrBracket': row['hasSqrBracket'], 'fulltype': row['fulltype']}) + 'hasSqrBracket': row['hasSqrBracket'], + 'fulltype': row['fulltype']}) # Adding both results res['member_list'] = ', '.join(properties_list) @@ -494,7 +519,8 @@ class TypeView(PGChildNodeView, DataTypeReader): res['enum_list'] = ', '.join(properties_list) res['enum'] = enum_list - # If type is of Range then we need to add collation,subtype etc in our output + # If type is of Range then we need to add collation,subtype etc in our + # output if of_type == 'r': SQL = render_template("/".join([self.template_path, 'additional_properties.sql']), @@ -535,18 +561,20 @@ class TypeView(PGChildNodeView, DataTypeReader): JSON of selected type node """ - SQL = render_template("/".join([self.template_path, - 'properties.sql']), - scid=scid, tid=tid, - datlastsysoid=self.datlastsysoid, - show_system_objects=self.blueprint.show_system_objects - ) + SQL = render_template( + "/".join([self.template_path, + 'properties.sql']), + scid=scid, tid=tid, + datlastsysoid=self.datlastsysoid, + show_system_objects=self.blueprint.show_system_objects + ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: - return gone(gettext("""Could not find the type in the database.""")) + return gone( + gettext("""Could not find the type in the database.""")) # Making copy of output for future use copy_dict = dict(res['rows'][0]) @@ -925,15 +953,18 @@ class TypeView(PGChildNodeView, DataTypeReader): # If type is external then check if input/output # conversion function is defined if data and data[arg] == 'b': - if 'typinput' not in data or \ - 'typoutput' not in data or \ - data['typinput'] is None or \ - data['typoutput'] is None: + if ( + 'typinput' not in data or + 'typoutput' not in data or + data['typinput'] is None or + data['typoutput'] is None + ): return make_json_response( status=410, success=0, errormsg=gettext( - 'External types require both input and output conversion functions.' + 'External types require both input and output ' + 'conversion functions.' ) ) @@ -946,8 +977,10 @@ class TypeView(PGChildNodeView, DataTypeReader): try: if 'composite' in data and len(data['composite']) > 0: for each_type in data['composite']: - each_type = self.convert_length_precision_to_string(each_type) - each_type['cltype'] = self._cltype_formatter(each_type['type']) + each_type = self.convert_length_precision_to_string( + each_type) + each_type['cltype'] = self._cltype_formatter( + each_type['type']) each_type['hasSqrBracket'] = self.hasSqrBracket SQL = render_template("/".join([self.template_path, 'create.sql']), @@ -959,7 +992,8 @@ class TypeView(PGChildNodeView, DataTypeReader): if 'schema' in data: # we need scid to update in browser tree SQL = render_template("/".join([self.template_path, - 'get_scid.sql']), schema=data['schema']) + 'get_scid.sql']), + schema=data['schema']) status, scid = self.conn.execute_scalar(SQL) if not status: return internal_server_error(errormsg=scid) @@ -1010,7 +1044,7 @@ class TypeView(PGChildNodeView, DataTypeReader): return internal_server_error(errormsg=res) SQL = render_template("/".join([self.template_path, - 'get_scid.sql']), tid=tid) + 'get_scid.sql']), tid=tid) # Get updated schema oid status, scid = self.conn.execute_scalar(SQL) @@ -1050,12 +1084,13 @@ class TypeView(PGChildNodeView, DataTypeReader): try: - SQL = render_template("/".join([self.template_path, - 'properties.sql']), - scid=scid, tid=tid, - datlastsysoid=self.datlastsysoid, - show_system_objects=self.blueprint.show_system_objects - ) + SQL = render_template( + "/".join([self.template_path, + 'properties.sql']), + scid=scid, tid=tid, + datlastsysoid=self.datlastsysoid, + show_system_objects=self.blueprint.show_system_objects + ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) @@ -1168,27 +1203,33 @@ class TypeView(PGChildNodeView, DataTypeReader): for key in ['typacl']: if key in data and data[key] is not None: if 'added' in data[key]: - data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl) + data[key]['added'] = parse_priv_to_db( + data[key]['added'], self.acl) if 'changed' in data[key]: - data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl) + data[key]['changed'] = parse_priv_to_db( + data[key]['changed'], self.acl) if 'deleted' in data[key]: - data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl) + data[key]['deleted'] = parse_priv_to_db( + data[key]['deleted'], self.acl) if 'composite' in data and len(data['composite']) > 0: for key in ['added', 'changed', 'deleted']: if key in data['composite']: for each_type in data['composite'][key]: - each_type = self.convert_length_precision_to_string(each_type) + each_type = self. \ + convert_length_precision_to_string(each_type) if 'type' in each_type: - each_type['cltype'] = self._cltype_formatter(each_type['type']) + each_type['cltype'] = self._cltype_formatter( + each_type['type']) each_type['hasSqrBracket'] = self.hasSqrBracket - SQL = render_template("/".join([self.template_path, - 'properties.sql']), - scid=scid, tid=tid, - datlastsysoid=self.datlastsysoid, - show_system_objects=self.blueprint.show_system_objects - ) + SQL = render_template( + "/".join([self.template_path, + 'properties.sql']), + scid=scid, tid=tid, + datlastsysoid=self.datlastsysoid, + show_system_objects=self.blueprint.show_system_objects + ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) @@ -1249,10 +1290,12 @@ class TypeView(PGChildNodeView, DataTypeReader): # If type is external then check if input/output # conversion function is defined if data and data[arg] == 'b': - if 'typinput' not in data or \ - 'typoutput' not in data or \ - data['typinput'] is None or \ - data['typoutput'] is None: + if ( + 'typinput' not in data or + 'typoutput' not in data or + data['typinput'] is None or + data['typoutput'] is None + ): return "-- definition incomplete" # Privileges @@ -1263,8 +1306,10 @@ class TypeView(PGChildNodeView, DataTypeReader): if 'composite' in data and len(data['composite']) > 0: for each_type in data['composite']: - each_type = self.convert_length_precision_to_string(each_type) - each_type['cltype'] = self._cltype_formatter(each_type['type']) + each_type = self.convert_length_precision_to_string( + each_type) + each_type['cltype'] = self._cltype_formatter( + each_type['type']) each_type['hasSqrBracket'] = self.hasSqrBracket SQL = render_template("/".join([self.template_path, @@ -1285,12 +1330,13 @@ class TypeView(PGChildNodeView, DataTypeReader): scid: Schema ID tid: Type ID """ - SQL = render_template("/".join([self.template_path, - 'properties.sql']), - scid=scid, tid=tid, - datlastsysoid=self.datlastsysoid, - show_system_objects=self.blueprint.show_system_objects - ) + SQL = render_template( + "/".join([self.template_path, + 'properties.sql']), + scid=scid, tid=tid, + datlastsysoid=self.datlastsysoid, + show_system_objects=self.blueprint.show_system_objects + ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/test_types_delete.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/test_types_delete.py index b7ce167d..0c887e3d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/test_types_delete.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/test_types_delete.py @@ -51,7 +51,7 @@ class TypesDeleteTestCase(BaseTestGenerator): type_response = types_utils.verify_type(self.server, self.db_name, self.type_name) if not type_response: - raise Exception("Could not find the type to delete.") + raise Exception("Could not find the type to delete.") response = self.tester.delete( "{0}{1}/{2}/{3}/{4}/{5}".format(self.url, utils.SERVER_GROUP, self.server_id, self.db_id, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py index ddebd5ed..f330ed96 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py @@ -12,6 +12,7 @@ import json from flask import render_template + from pgadmin.browser.collection import CollectionNodeModule from pgadmin.utils.ajax import internal_server_error @@ -43,23 +44,30 @@ class SchemaChildModule(CollectionNodeModule): def BackendSupported(self, manager, **kwargs): return ( - ( - kwargs['is_catalog'] and (( - self.CATALOG_DB_SUPPORTED and kwargs['db_support'] - ) or ( - not self.CATALOG_DB_SUPPORTED and - not kwargs['db_support'] and - ( - self.SUPPORTED_SCHEMAS is None or ( - kwargs['schema_name'] in self.SUPPORTED_SCHEMAS - ) - ) - )) - ) or ( - not kwargs['is_catalog'] and self.CATALOG_DB_SUPPORTED - ) - ) and CollectionNodeModule.BackendSupported( - self, manager, **kwargs + ( + ( + kwargs['is_catalog'] and + ( + ( + self.CATALOG_DB_SUPPORTED and + kwargs['db_support'] + ) or ( + not self.CATALOG_DB_SUPPORTED and + not kwargs[ + 'db_support'] and + ( + self.SUPPORTED_SCHEMAS is None or + kwargs[ + 'schema_name'] in self.SUPPORTED_SCHEMAS + ) + ) + ) + ) or + ( + not kwargs['is_catalog'] and self.CATALOG_DB_SUPPORTED + ) + ) and + CollectionNodeModule.BackendSupported(self, manager, **kwargs) ) @property @@ -83,7 +91,7 @@ class DataTypeReader: - Returns data-types on the basis of the condition provided. """ - def get_types(self, conn, condition, add_serials=False, schema_oid = ''): + def get_types(self, conn, condition, add_serials=False, schema_oid=''): """ Returns data-types including calculation for Length and Precision. @@ -106,7 +114,7 @@ class DataTypeReader: '#{0}#'.format(self.manager.version) ) SQL = render_template( - "/".join([self.data_type_template_path,'get_types.sql']), + "/".join([self.data_type_template_path, 'get_types.sql']), condition=condition, add_serials=add_serials, schema_oid=schema_oid @@ -125,7 +133,8 @@ class DataTypeReader: # Check if the type will have length and precision or not if row['elemoid']: - length, precision, typeval = self.get_length_precision(row['elemoid']) + length, precision, typeval = self.get_length_precision( + row['elemoid']) if length: min_val = 0 if typeval == 'D' else 1 @@ -167,11 +176,16 @@ class DataTypeReader: 1015, 'varchar[]', 'character varying[]'): typeval = 'L' elif elemoid_or_name in (1083, 'time', 'time without time zone', - 1114, 'timestamp', 'timestamp without time zone', - 1115, 'timestamp[]', 'timestamp without time zone[]', - 1183, 'time[]', 'time without time zone[]', - 1184, 'timestamptz', 'timestamp with time zone', - 1185, 'timestamptz[]', 'timestamp with time zone[]', + 1114, 'timestamp', + 'timestamp without time zone', + 1115, 'timestamp[]', + 'timestamp without time zone[]', + 1183, 'time[]', + 'time without time zone[]', + 1184, 'timestamptz', + 'timestamp with time zone', + 1185, 'timestamptz[]', + 'timestamp with time zone[]', 1186, 'interval', 1187, 'interval[]', 'interval[]', 1266, 'timetz', 'time with time zone', @@ -205,8 +219,8 @@ class DataTypeReader: array = '' length = '' - # Above 7.4, format_type also sends the schema name if it's not included - # in the search_path, so we need to skip it in the typname + # Above 7.4, format_type also sends the schema name if it's not + # included in the search_path, so we need to skip it in the typname if typname.find(schema + '".') >= 0: name = typname[len(schema) + 3] elif typname.find(schema + '.') >= 0: @@ -235,22 +249,24 @@ class DataTypeReader: if typmod != -1: length = '(' if name == 'numeric': - _len = (typmod - 4) >> 16; - _prec = (typmod - 4) & 0xffff; + _len = (typmod - 4) >> 16 + _prec = (typmod - 4) & 0xffff length += str(_len) if _prec is not None: length += ',' + str(_prec) - elif name == 'time' or \ - name == 'timetz' or \ - name == 'time without time zone' or \ - name == 'time with time zone' or \ - name == 'timestamp' or \ - name == 'timestamptz' or \ - name == 'timestamp without time zone' or \ - name == 'timestamp with time zone' or \ - name == 'bit' or \ - name == 'bit varying' or \ - name == 'varbit': + elif ( + name == 'time' or + name == 'timetz' or + name == 'time without time zone' or + name == 'time with time zone' or + name == 'timestamp' or + name == 'timestamptz' or + name == 'timestamp without time zone' or + name == 'timestamp with time zone' or + name == 'bit' or + name == 'bit varying' or + name == 'varbit' + ): _prec = 0 _len = typmod length += str(_len) @@ -567,7 +583,8 @@ class VacuumSettings: elif type is 'toast': for row in res['rows']: row_old_name = row['name'] - row_name = 'toast_{0}'.format(vacuum_fields[type][row_old_name][0]) + row_name = 'toast_{0}'.format( + vacuum_fields[type][row_old_name][0]) row['name'] = vacuum_fields[type][row_old_name][0] row['label'] = vacuum_fields[type][row_old_name][1] row['column_type'] = vacuum_fields[type][row_old_name][2] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py index 2c51f143..15b9559c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py @@ -11,19 +11,20 @@ from functools import wraps -import pgadmin.browser.server_groups.servers.databases as databases import simplejson as json from flask import render_template, request, jsonify, current_app from flask_babel import gettext + +import pgadmin.browser.server_groups.servers.databases as databases +from config import PG_DEFAULT_DRIVER from pgadmin.browser.server_groups.servers.databases.schemas.utils import \ SchemaChildModule, parse_rule_definition, VacuumSettings +from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ + parse_priv_to_db from pgadmin.browser.utils import PGChildNodeView from pgadmin.utils.ajax import make_json_response, internal_server_error, \ - make_response as ajax_response, bad_request, gone + make_response as ajax_response, gone from pgadmin.utils.driver import get_driver -from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db,\ - parse_priv_to_db -from config import PG_DEFAULT_DRIVER """ This module is responsible for generating two nodes @@ -171,10 +172,13 @@ def check_precondition(f): kwargs['sid'] ) self.conn = self.manager.connection(did=kwargs['did']) - self.datlastsysoid = self.manager.db_info[ - kwargs['did'] - ]['datlastsysoid'] if self.manager.db_info is not None and \ - kwargs['did'] in self.manager.db_info else 0 + self.datlastsysoid = 0 + if ( + self.manager.db_info is not None and + kwargs['did'] in self.manager.db_info + ): + self.datlastsysoid = self.manager.db_info[kwargs['did']][ + 'datlastsysoid'] # Set template path for sql scripts if self.manager.server_type == 'gpdb': @@ -185,7 +189,8 @@ def check_precondition(f): _temp = self.pg_template_path(self.manager.version) self.template_path = self.template_initial + '/' + _temp - self.column_template_path = 'column/sql/#{0}#'.format(self.manager.version) + self.column_template_path = 'column/sql/#{0}#'.format( + self.manager.version) return f(*args, **kwargs) @@ -355,11 +360,11 @@ class ViewNode(PGChildNodeView, VacuumSettings): return gone(gettext("""Could not find the view.""")) res = self.blueprint.generate_browser_node( - rset['rows'][0]['oid'], - scid, - rset['rows'][0]['name'], - icon="icon-view" - ) + rset['rows'][0]['oid'], + scid, + rset['rows'][0]['name'], + icon="icon-view" + ) return make_json_response( data=res, @@ -763,7 +768,8 @@ class ViewNode(PGChildNodeView, VacuumSettings): self.index_temp_path = 'index' SQL = render_template("/".join([self.index_temp_path, - 'sql/#{0}#/column_details.sql'.format(self.manager.version)]), idx=idx) + 'sql/#{0}#/column_details.sql'.format( + self.manager.version)]), idx=idx) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) @@ -880,7 +886,8 @@ class ViewNode(PGChildNodeView, VacuumSettings): SQL_data = '' SQL = render_template("/".join( - [self.trigger_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]), + [self.trigger_temp_path, + 'sql/#{0}#/properties.sql'.format(self.manager.version)]), tid=vid) status, data = self.conn.execute_dict(SQL) @@ -889,7 +896,8 @@ class ViewNode(PGChildNodeView, VacuumSettings): for trigger in data['rows']: SQL = render_template("/".join( - [self.trigger_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]), + [self.trigger_temp_path, + 'sql/#{0}#/properties.sql'.format(self.manager.version)]), tid=vid, trid=trigger['oid'] ) @@ -917,27 +925,33 @@ class ViewNode(PGChildNodeView, VacuumSettings): res_rows['schema'] = self.view_schema # Get trigger function with its schema name - SQL = render_template("/".join([self.trigger_temp_path, - 'sql/#{0}#/get_triggerfunctions.sql'.format(self.manager.version)]), - tgfoid=res_rows['tgfoid'], - show_system_objects=self.blueprint.show_system_objects) + SQL = render_template("/".join([ + self.trigger_temp_path, + 'sql/#{0}#/get_triggerfunctions.sql'.format( + self.manager.version)]), + tgfoid=res_rows['tgfoid'], + show_system_objects=self.blueprint.show_system_objects) status, result = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=result) - # Update the trigger function which we have fetched with schema name - if 'rows' in result and len(result['rows']) > 0 and \ - 'tfunctions' in result['rows'][0]: + # Update the trigger function which we have fetched with schemaname + if ( + 'rows' in result and len(result['rows']) > 0 and + 'tfunctions' in result['rows'][0] + ): res_rows['tfunction'] = result['rows'][0]['tfunctions'] # Format arguments if len(res_rows['custom_tgargs']) > 1: - formatted_args = ["{0}".format(arg) for arg in res_rows['custom_tgargs']] + formatted_args = ["{0}".format(arg) for arg in + res_rows['custom_tgargs']] res_rows['tgargs'] = ', '.join(formatted_args) SQL = render_template("/".join( - [self.trigger_temp_path, 'sql/#{0}#/create.sql'.format(self.manager.version)]), + [self.trigger_temp_path, + 'sql/#{0}#/create.sql'.format(self.manager.version)]), data=res_rows, display_comments=True) SQL_data += '\n' SQL_data += SQL @@ -954,7 +968,8 @@ class ViewNode(PGChildNodeView, VacuumSettings): self.index_temp_path = 'index' SQL_data = '' SQL = render_template("/".join( - [self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]), + [self.index_temp_path, + 'sql/#{0}#/properties.sql'.format(self.manager.version)]), did=did, tid=vid) status, data = self.conn.execute_dict(SQL) @@ -964,7 +979,8 @@ class ViewNode(PGChildNodeView, VacuumSettings): for index in data['rows']: res = [] SQL = render_template("/".join( - [self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]), + [self.index_temp_path, + 'sql/#{0}#/properties.sql'.format(self.manager.version)]), idx=index['oid'], did=did, tid=vid @@ -980,7 +996,8 @@ class ViewNode(PGChildNodeView, VacuumSettings): data = self.get_index_column_details(index['oid'], data) SQL = render_template("/".join( - [self.index_temp_path, 'sql/#{0}#/create.sql'.format(self.manager.version)]), + [self.index_temp_path, + 'sql/#{0}#/create.sql'.format(self.manager.version)]), data=data, display_comments=True) SQL_data += '\n' SQL_data += SQL @@ -1335,7 +1352,8 @@ class MViewNode(ViewNode, VacuumSettings): return None, internal_server_error(errormsg=res) if len(res['rows']) == 0: return None, gone( - gettext("Could not find the materialized view on the server.") + gettext( + "Could not find the materialized view on the server.") ) old_data = res['rows'][0] @@ -1360,18 +1378,26 @@ class MViewNode(ViewNode, VacuumSettings): data['vacuum_data']['reset'].append(item) else: if (old_data[item['name']] is None or - (float(old_data[item['name']]) != float(item['value']))): + (float(old_data[item['name']]) != float( + item['value']))): data['vacuum_data']['changed'].append(item) - if ('autovacuum_enabled' in data and - old_data['autovacuum_enabled'] is not None): - if (data['autovacuum_enabled'] != - old_data['autovacuum_enabled']): + if ( + 'autovacuum_enabled' in data and + old_data['autovacuum_enabled'] is not None + ): + if ( + data['autovacuum_enabled'] != + old_data['autovacuum_enabled'] + ): data['vacuum_data']['changed'].append( {'name': 'autovacuum_enabled', 'value': data['autovacuum_enabled']}) - elif ('autovacuum_enabled' in data and 'autovacuum_custom' in data and - old_data['autovacuum_enabled'] is None and data['autovacuum_custom']): + elif ( + 'autovacuum_enabled' in data and + 'autovacuum_custom' in data and + old_data['autovacuum_enabled'] is None and data[ + 'autovacuum_custom']): data['vacuum_data']['changed'].append( {'name': 'autovacuum_enabled', 'value': data['autovacuum_enabled']}) @@ -1388,18 +1414,27 @@ class MViewNode(ViewNode, VacuumSettings): data['vacuum_data']['reset'].append(item) else: if (old_data[toast_key] is None or - (float(old_data[toast_key]) != float(item['value']))): + (float(old_data[toast_key]) != float( + item['value']))): data['vacuum_data']['changed'].append(item) - if ('toast_autovacuum_enabled' in data and - old_data['toast_autovacuum_enabled'] is not None): - if (data['toast_autovacuum_enabled'] != - old_data['toast_autovacuum_enabled']): + if ( + 'toast_autovacuum_enabled' in data and + old_data['toast_autovacuum_enabled'] is not None + ): + if ( + data['toast_autovacuum_enabled'] != + old_data['toast_autovacuum_enabled'] + ): data['vacuum_data']['changed'].append( {'name': 'toast.autovacuum_enabled', 'value': data['toast_autovacuum_enabled']}) - elif ('toast_autovacuum_enabled' in data and 'toast_autovacuum' in data and - old_data['toast_autovacuum_enabled'] is None and data['toast_autovacuum']): + elif ( + 'toast_autovacuum_enabled' in data and + 'toast_autovacuum' in data and + old_data['toast_autovacuum_enabled'] is None and + data['toast_autovacuum'] + ): data['vacuum_data']['changed'].append( {'name': 'toast.autovacuum_enabled', 'value': data['toast_autovacuum_enabled']}) @@ -1475,14 +1510,17 @@ class MViewNode(ViewNode, VacuumSettings): # add vacuum_toast dict to vacuum_data only if # table & toast's custom autovacuum is enabled - data['vacuum_data'] = (vacuum_table if ( + data['vacuum_data'] = [] + if ( 'autovacuum_custom' in data and data['autovacuum_custom'] is True - ) else []) + ( - vacuum_toast if ( - 'toast_autovacuum' in data and - data['toast_autovacuum'] is True - ) else []) + ): + data['vacuum_data'] = vacuum_table + if ( + 'toast_autovacuum' in data and + data['toast_autovacuum'] is True + ): + data['vacuum_data'] += vacuum_toast acls = [] try: @@ -1545,15 +1583,19 @@ class MViewNode(ViewNode, VacuumSettings): # merge vacuum lists into one vacuum_table = [item for item in result['vacuum_table'] - if 'value' in item.keys() and item['value'] is not None] + if + 'value' in item.keys() and item['value'] is not None] vacuum_toast = [ {'name': 'toast.' + item['name'], 'value': item['value']} - for item in result['vacuum_toast'] if 'value' in item.keys() and item['value'] is not None] + for item in result['vacuum_toast'] if + 'value' in item.keys() and item['value'] is not None] # add vacuum_toast dict to vacuum_data only if # toast's autovacuum is enabled - if ('toast_autovacuum_enabled' in result and - result['toast_autovacuum_enabled'] is True): + if ( + 'toast_autovacuum_enabled' in result and + result['toast_autovacuum_enabled'] is True + ): result['vacuum_data'] = vacuum_table + vacuum_toast else: result['vacuum_data'] = vacuum_table diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/children/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/children/__init__.py index eae1fe8e..0b5500a3 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/children/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/children/__init__.py @@ -6,10 +6,10 @@ Do not remove these imports as they will be automatically imported by the view module as its children """ from pgadmin.browser.server_groups.servers.databases.schemas.tables.column \ - import blueprint as columns_module + import blueprint as columns_module from pgadmin.browser.server_groups.servers.databases.schemas.tables.indexes \ - import blueprint as indexes_modules + import blueprint as indexes_modules from pgadmin.browser.server_groups.servers.databases.schemas.tables.triggers \ - import blueprint as triggers_modules + import blueprint as triggers_modules from pgadmin.browser.server_groups.servers.databases.schemas.tables.rules \ - import blueprint as rules_modules + import blueprint as rules_modules diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_add.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_add.py index 3f438e16..fb577638 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_add.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_add.py @@ -93,8 +93,8 @@ class ViewsAddTestCase(BaseTestGenerator): self.data["schema"] = self.schema_name self.data["owner"] = db_user response = self.tester.post( - self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) - + '/' + str(self.db_id) + '/' + str(self.schema_id) + '/', + self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) + + '/' + str(self.db_id) + '/' + str(self.schema_id) + '/', data=json.dumps(self.data), content_type='html/json') self.assertEquals(response.status_code, 200) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_delete.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_delete.py index 9d463c27..b968048d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_delete.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_delete.py @@ -28,11 +28,10 @@ class ViewsDeleteTestCase(BaseTestGenerator): "SELECT 'test_pgadmin' WITH NO DATA;ALTER TABLE %s.%s OWNER" \ " TO %s" scenarios = [ - ('Delete view under schema node', dict(url='/browser/view/obj/', - view_name= - "test_view_delete_%s" % - (str(uuid.uuid4())[1:8]), - sql_query=view_sql)), + ('Delete view under schema node', dict( + url='/browser/view/obj/', + view_name="test_view_delete_%s" % (str(uuid.uuid4())[1:8]), + sql_query=view_sql)), ('Delete materialized view under schema node', dict(url='/browser/mview/obj/', view_name="test_mview_delete_%s" % (str(uuid.uuid4())[1:8]), diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py index 944f37ba..14c08bf9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_get.py @@ -28,11 +28,10 @@ class ViewsGetTestCase(BaseTestGenerator): "SELECT 'test_pgadmin' WITH NO DATA;ALTER TABLE %s.%s OWNER" \ " TO %s" scenarios = [ - ('Get view under schema node', dict(url='/browser/view/obj/', - view_name= - "test_view_get_%s" % - (str(uuid.uuid4())[1:8]), - sql_query=view_sql)), + ('Get view under schema node', dict( + url='/browser/view/obj/', + view_name="test_view_get_%s" % (str(uuid.uuid4())[1:8]), + sql_query=view_sql)), ('Get materialized view under schema node', dict(url='/browser/mview/obj/', view_name="test_mview_get_%s" % (str(uuid.uuid4())[1:8]), diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_put.py index 05a25346..c6351b6b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_put.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/tests/test_views_put.py @@ -29,11 +29,10 @@ class ViewsUpdateTestCase(BaseTestGenerator): "SELECT 'test_pgadmin' WITH NO DATA;ALTER TABLE %s.%s OWNER" \ " TO %s" scenarios = [ - ('Update view under schema node', dict(url='/browser/view/obj/', - view_name= - "test_view_put_%s" % - (str(uuid.uuid4())[1:8]), - sql_query=view_sql)), + ('Update view under schema node', dict( + url='/browser/view/obj/', + view_name="test_view_put_%s" % (str(uuid.uuid4())[1:8]), + sql_query=view_sql)), ('Update materialized view under schema node', dict(url='/browser/mview/obj/', view_name="test_mview_put_%s" % (str(uuid.uuid4())[1:8]), diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_check_ssl_connection.py b/web/pgadmin/browser/server_groups/servers/tests/test_check_ssl_connection.py index 455420b6..bcc32a31 100644 --- a/web/pgadmin/browser/server_groups/servers/tests/test_check_ssl_connection.py +++ b/web/pgadmin/browser/server_groups/servers/tests/test_check_ssl_connection.py @@ -14,16 +14,16 @@ from regression.python_test_utils import test_utils class TestSSLConnection(BaseTestGenerator): """This will check if SSL is used in our database connection""" scenarios = [ - ("Test for SSL connection", dict()) + ('Test for SSL connection', dict()) ] def runTest(self): - if hasattr(self, "ignore_test"): + if hasattr(self, 'ignore_test'): return supported_modes = ['require', 'verify-ca', 'verify-full'] if self.server['sslmode'] in supported_modes: with test_utils.Database(self.server) as ( - connection, database_name + connection, database_name ): cursor = connection.cursor() @@ -33,7 +33,6 @@ class TestSSLConnection(BaseTestGenerator): is_ssl_used = cursor.fetchone()[0] self.assertEquals(True, is_ssl_used) else: - self.skipTest("Cannot run SSL connection check test " - "with '{0}' sslmode".format( - self.server['sslmode'] - )) + self.skipTest( + 'Cannot run SSL connection check test ' + 'with \'{0}\' sslmode'.format(self.server['sslmode'])) diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_dependencies_sql.py b/web/pgadmin/browser/server_groups/servers/tests/test_dependencies_sql.py index e2164eca..824fc441 100644 --- a/web/pgadmin/browser/server_groups/servers/tests/test_dependencies_sql.py +++ b/web/pgadmin/browser/server_groups/servers/tests/test_dependencies_sql.py @@ -9,7 +9,8 @@ import os -from regression.python_test_utils.sql_template_test_base import SQLTemplateTestBase +from regression.python_test_utils.sql_template_test_base import \ + SQLTemplateTestBase from regression.python_test_utils.template_helper import file_as_template @@ -32,7 +33,8 @@ class TestDependenciesSql(SQLTemplateTestBase): def generate_sql(self, version): template_file = self.get_template_file(version, "dependencies.sql") template = file_as_template(template_file) - sql = template.render(where_clause="WHERE dep.objid=%s::oid" % self.table_id) + sql = template.render( + where_clause="WHERE dep.objid=%s::oid" % self.table_id) return sql @@ -48,4 +50,5 @@ class TestDependenciesSql(SQLTemplateTestBase): @staticmethod def get_template_file(version, filename): - return os.path.join(os.path.dirname(__file__), "..", "templates", "depends", "sql", version, filename) + return os.path.join(os.path.dirname(__file__), "..", "templates", + "depends", "sql", version, filename) diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_dependents_sql.py b/web/pgadmin/browser/server_groups/servers/tests/test_dependents_sql.py index a0c8c39e..9d6259f5 100644 --- a/web/pgadmin/browser/server_groups/servers/tests/test_dependents_sql.py +++ b/web/pgadmin/browser/server_groups/servers/tests/test_dependents_sql.py @@ -9,7 +9,8 @@ import os -from regression.python_test_utils.sql_template_test_base import SQLTemplateTestBase +from regression.python_test_utils.sql_template_test_base import \ + SQLTemplateTestBase from regression.python_test_utils.template_helper import file_as_template @@ -32,7 +33,8 @@ class TestDependentsSql(SQLTemplateTestBase): def generate_sql(self, version): template_file = self.get_template_file(version, "dependents.sql") template = file_as_template(template_file) - sql = template.render(where_clause="WHERE dep.objid=%s::oid" % self.table_id) + sql = template.render( + where_clause="WHERE dep.objid=%s::oid" % self.table_id) return sql @@ -48,4 +50,5 @@ class TestDependentsSql(SQLTemplateTestBase): @staticmethod def get_template_file(version, filename): - return os.path.join(os.path.dirname(__file__), "..", "templates", "depends", "sql", version, filename) + return os.path.join(os.path.dirname(__file__), "..", "templates", + "depends", "sql", version, filename) diff --git a/web/pgadmin/browser/server_groups/servers/tests/test_role_dependencies_sql.py b/web/pgadmin/browser/server_groups/servers/tests/test_role_dependencies_sql.py index ac22b5ba..9efe4d6a 100644 --- a/web/pgadmin/browser/server_groups/servers/tests/test_role_dependencies_sql.py +++ b/web/pgadmin/browser/server_groups/servers/tests/test_role_dependencies_sql.py @@ -6,14 +6,11 @@ # This software is released under the PostgreSQL Licence # ########################################################################## -from pgadmin.browser.server_groups.servers.roles.tests.utils import create_role, delete_role -from pgadmin.utils.route import BaseTestGenerator import os +from pgadmin.utils.route import BaseTestGenerator from regression.python_test_utils import test_utils -from regression.python_test_utils.sql_template_test_base import SQLTemplateTestBase from regression.python_test_utils.template_helper import file_as_template -from regression.python_test_utils.test_utils import create_database class TestRoleDependenciesSql(BaseTestGenerator): @@ -45,7 +42,8 @@ class TestRoleDependenciesSql(BaseTestGenerator): return with test_utils.Database(self.server) as (connection, database_name): - test_utils.create_table(self.server_with_modified_user, database_name, "test_new_role_table") + test_utils.create_table(self.server_with_modified_user, + database_name, "test_new_role_table") cursor = connection.cursor() cursor.execute("SELECT pg_class.oid AS table_id " "FROM pg_class " @@ -65,9 +63,11 @@ class TestRoleDependenciesSql(BaseTestGenerator): connection.commit() def generate_sql(self, version): - template_file = self.get_template_file(version, "role_dependencies.sql") + template_file = self.get_template_file(version, + "role_dependencies.sql") template = file_as_template(template_file) - sql = template.render(where_clause="WHERE dep.objid=%s::oid" % self.table_id) + sql = template.render( + where_clause="WHERE dep.objid=%s::oid" % self.table_id) return sql @@ -82,4 +82,5 @@ class TestRoleDependenciesSql(BaseTestGenerator): @staticmethod def get_template_file(version, filename): - return os.path.join(os.path.dirname(__file__), "..", "templates", "depends", "sql", version, filename) + return os.path.join(os.path.dirname(__file__), "..", "templates", + "depends", "sql", version, filename) diff --git a/web/pgadmin/browser/tests/test_change_password.py b/web/pgadmin/browser/tests/test_change_password.py index e34e1c02..5b337db7 100644 --- a/web/pgadmin/browser/tests/test_change_password.py +++ b/web/pgadmin/browser/tests/test_change_password.py @@ -26,34 +26,39 @@ class ChangePasswordTestCase(BaseTestGenerator): scenarios = [ # This testcase validates invalid confirmation password ('TestCase for Validating Incorrect_New_Password', dict( - password=(config_data['pgAdmin4_login_credentials'] - ['login_password']), - new_password=(config_data['pgAdmin4_login_credentials'] - ['new_password']), + password=( + config_data['pgAdmin4_login_credentials'] + ['login_password']), + new_password=( + config_data['pgAdmin4_login_credentials'] + ['new_password']), new_password_confirm=str(uuid.uuid4())[4:8], respdata='Passwords do not match')), # This testcase validates if confirmation password is less than # minimum length ('TestCase for Validating New_Password_Less_Than_Min_Length', - dict(password=(config_data['pgAdmin4_login_credentials'] - ['login_password']), - new_password=str(uuid.uuid4())[4:8], - new_password_confirm=str(uuid.uuid4())[4:8], - respdata='Password must be at least 6 characters')), + dict(password=( + config_data['pgAdmin4_login_credentials'] + ['login_password']), + new_password=str(uuid.uuid4())[4:8], + new_password_confirm=str(uuid.uuid4())[4:8], + respdata='Password must be at least 6 characters')), # This testcase validates if both password fields are left blank ('TestCase for Validating Empty_New_Password', dict( - password=(config_data['pgAdmin4_login_credentials'] - ['login_password']), + password=( + config_data['pgAdmin4_login_credentials'] + ['login_password']), new_password='', new_password_confirm='', respdata='Password not provided')), # This testcase validates if current entered password is incorrect ('TestCase for Validating Incorrect_Current_Password', dict( password=str(uuid.uuid4())[4:8], - new_password=(config_data['pgAdmin4_login_credentials'] - ['new_password']), + new_password=( + config_data['pgAdmin4_login_credentials'] + ['new_password']), new_password_confirm=( config_data['pgAdmin4_login_credentials'] ['new_password']), @@ -62,12 +67,15 @@ class ChangePasswordTestCase(BaseTestGenerator): # This test case checks for valid password ('TestCase for Changing Valid_Password', dict( valid_password='reassigning_password', - username=(config_data['pgAdmin4_test_user_credentials'] - ['login_username']), - password=(config_data['pgAdmin4_test_user_credentials'] - ['login_password']), - new_password=(config_data['pgAdmin4_test_user_credentials'] - ['new_password']), + username=( + config_data['pgAdmin4_test_user_credentials'] + ['login_username']), + password=( + config_data['pgAdmin4_test_user_credentials'] + ['login_password']), + new_password=( + config_data['pgAdmin4_test_user_credentials'] + ['new_password']), new_password_confirm=( config_data['pgAdmin4_test_user_credentials'] ['new_password']), diff --git a/web/pgadmin/browser/tests/test_login.py b/web/pgadmin/browser/tests/test_login.py index 0f0a30ed..d830dfbc 100644 --- a/web/pgadmin/browser/tests/test_login.py +++ b/web/pgadmin/browser/tests/test_login.py @@ -24,21 +24,24 @@ class LoginTestCase(BaseTestGenerator): scenarios = [ # This test case validates the invalid/incorrect password ('TestCase for Checking Invalid_Password', dict( - email=(config_data['pgAdmin4_login_credentials'] - ['login_username']), + email=( + config_data['pgAdmin4_login_credentials'] + ['login_username']), password=str(uuid.uuid4())[4:8], respdata='Invalid password')), # This test case validates the empty password field ('Empty_Password', dict( - email=(config_data['pgAdmin4_login_credentials'] - ['login_username']), password='', + email=( + config_data['pgAdmin4_login_credentials'] + ['login_username']), password='', respdata='Password not provided')), # This test case validates blank email field ('Empty_Email', dict( - email='', password=(config_data['pgAdmin4_login_credentials'] - ['login_password']), + email='', password=( + config_data['pgAdmin4_login_credentials'] + ['login_password']), respdata='Email not provided')), # This test case validates empty email and password @@ -49,8 +52,9 @@ class LoginTestCase(BaseTestGenerator): # This test case validates the invalid/incorrect email id ('Invalid_Email', dict( email=str(uuid.uuid4())[1:8] + '@xyz.com', - password=(config_data['pgAdmin4_login_credentials'] - ['login_password']), + password=( + config_data['pgAdmin4_login_credentials'] + ['login_password']), respdata='Specified user does not exist')), # This test case validates invalid email and password @@ -62,15 +66,15 @@ class LoginTestCase(BaseTestGenerator): # This test case validates the valid/correct credentials and allow user # to login pgAdmin 4 ('Valid_Credentials', dict( - email=(config_data[ - 'pgAdmin4_login_credentials' - ]['login_username']), - password=(config_data[ - 'pgAdmin4_login_credentials' - ]['login_password']), - respdata='%s' % config_data['pgAdmin4_login_credentials'] - ['login_username']) - ) + email=( + config_data['pgAdmin4_login_credentials'] + ['login_username']), + password=( + config_data['pgAdmin4_login_credentials'] + ['login_password']), + respdata='Gravatar image for %s' % + config_data['pgAdmin4_login_credentials'] + ['login_username'])) ] @classmethod diff --git a/web/pgadmin/browser/tests/test_version_in_range.py b/web/pgadmin/browser/tests/test_version_in_range.py index 548b2a0a..4d9ca76d 100644 --- a/web/pgadmin/browser/tests/test_version_in_range.py +++ b/web/pgadmin/browser/tests/test_version_in_range.py @@ -21,43 +21,36 @@ class VersionInRangeTestCase(BaseTestGenerator): scenarios = [ ( 'TestCase for Validating pgversion 8.23 and min_version is 91000, ' - 'should not show', - dict( + 'it should not show', dict( sversion=82300, min_version=90100, max_version=1000000000, scenario=2 - ) - ), + )), ( - 'TestCase for Validating pgversion 9.2 and should show by default', - dict( + 'TestCase for Validating pgversion 9.2, ' + 'it should show by default', dict( sversion=90200, min_version=0, max_version=1000000000, scenario=1 - ) - ), + )), ( 'TestCase for Validating pgversion 9.2 and min/max are None, ' - 'should show by default', - dict( + 'it should show by default', dict( sversion=90200, min_version=None, max_version=None, scenario=1 - ) - ), + )), ( - 'TestCase for Validating pgversion 9.6 and max is lower, should ' - 'not show', - dict( + 'TestCase for Validating pgversion 9.6 and max is lower, ' + 'it should not show', dict( sversion=90600, min_version=None, max_version=90400, scenario=2 - ) - ) + )) ] @classmethod @@ -74,13 +67,17 @@ class VersionInRangeTestCase(BaseTestGenerator): def test_result_is_true(self): self.assertTrue( is_version_in_range( - self.sversion, self.min_version, self.max_version + self.sversion, + self.min_version, + self.max_version ) ) def test_result_is_false(self): self.assertFalse( is_version_in_range( - self.sversion, self.min_version, self.max_version + self.sversion, + self.min_version, + self.max_version ) ) diff --git a/web/pgadmin/browser/utils.py b/web/pgadmin/browser/utils.py index 7448a8a5..df6758d5 100644 --- a/web/pgadmin/browser/utils.py +++ b/web/pgadmin/browser/utils.py @@ -13,11 +13,11 @@ from abc import abstractmethod import flask from flask import render_template, current_app -from flask_babel import gettext from flask.views import View, MethodViewType, with_metaclass -from pgadmin.utils.ajax import make_json_response, precondition_required +from flask_babel import gettext from config import PG_DEFAULT_DRIVER +from pgadmin.utils.ajax import make_json_response, precondition_required def is_version_in_range(sversion, min_ver, max_ver): @@ -64,18 +64,19 @@ class PGChildModule(object): return False sversion = getattr(manager, 'sversion', None) - if (sversion is None or not isinstance(sversion, int)): + if sversion is None or not isinstance(sversion, int): return False assert (self.server_type is None or isinstance(self.server_type, list)) if self.server_type is None or manager.server_type in self.server_type: - return is_version_in_range(sversion, self.min_gpdbver - if manager.server_type == 'gpdb' - else self.min_ver, - self.max_gpdbver - if manager.server_type == 'gpdb' - else self.max_ver) + min_server_version = self.min_ver + max_server_version = self.max_ver + if manager.server_type == 'gpdb': + min_server_version = self.min_gpdbver + max_server_version = self.max_gpdbver + return is_version_in_range(sversion, min_server_version, + max_server_version) return False @@ -205,35 +206,38 @@ class NodeView(with_metaclass(MethodViewType, View)): return has_args, has_id and has_args def dispatch_request(self, *args, **kwargs): - meth = flask.request.method.lower() - if meth == 'head': - meth = 'get' + http_method = flask.request.method.lower() + if http_method == 'head': + http_method = 'get' assert self.cmd in self.operations, \ - "Unimplemented command ({0}) for {1}".format( + 'Unimplemented command ({0}) for {1}'.format( self.cmd, str(self.__class__.__name__) ) has_args, has_id = self.check_args(**kwargs) - assert (self.cmd in self.operations and - (has_id and len(self.operations[self.cmd]) > 0 and - meth in self.operations[self.cmd][0]) or - (not has_id and len(self.operations[self.cmd]) > 1 and - meth in self.operations[self.cmd][1]) or - (len(self.operations[self.cmd]) > 2 and - meth in self.operations[self.cmd][2])), \ - "Unimplemented method ({0}) for command ({1}), which {2} an id"\ - .format( - meth, self.cmd, - 'requires' if has_id else 'does not require' - ) - - meth = self.operations[self.cmd][0][meth] if has_id else \ - self.operations[self.cmd][1][meth] \ - if has_args and meth in self.operations[self.cmd][1] \ - else self.operations[self.cmd][2][meth] + assert ( + self.cmd in self.operations and + (has_id and len(self.operations[self.cmd]) > 0 and + http_method in self.operations[self.cmd][0]) or + (not has_id and len(self.operations[self.cmd]) > 1 and + http_method in self.operations[self.cmd][1]) or + (len(self.operations[self.cmd]) > 2 and + http_method in self.operations[self.cmd][2]) + ), \ + 'Unimplemented method ({0}) for command ({1}), which {2} ' \ + 'an id'.format(http_method, + self.cmd, + 'requires' if has_id else 'does not require') + meth = None + if has_id: + meth = self.operations[self.cmd][0][http_method] + elif has_args and http_method in self.operations[self.cmd][1]: + meth = self.operations[self.cmd][1][http_method] + else: + meth = self.operations[self.cmd][2][http_method] method = getattr(self, meth, None) @@ -242,7 +246,7 @@ class NodeView(with_metaclass(MethodViewType, View)): status=406, success=0, errormsg=gettext( - "Unimplemented method ({0}) for this url ({1})".format( + 'Unimplemented method ({0}) for this url ({1})'.format( meth, flask.request.path) ) ) @@ -335,8 +339,10 @@ class PGChildNodeView(NodeView): nodes = [] for module in self.blueprint.submodules: if isinstance(module, PGChildModule): - if manager is not None and \ - module.BackendSupported(manager, **kwargs): + if ( + manager is not None and + module.BackendSupported(manager, **kwargs) + ): nodes.extend(module.get_nodes(**kwargs)) else: nodes.extend(module.get_nodes(**kwargs))