PEP8 fixes for the Casts, Event triggers, Extensions and Languages modules. Fixes #3161

pull/8/head
Murtuza Zabuawala 2018-03-02 11:59:11 +00:00 committed by Dave Page
parent 7cdb489a47
commit 8964e511bf
7 changed files with 254 additions and 124 deletions

View File

@ -26,6 +26,7 @@ from pgadmin.utils import IS_PY2
if not IS_PY2:
unicode = str
class CastModule(CollectionNodeModule):
"""
class CastModule(CollectionNodeModule)
@ -96,8 +97,9 @@ class CastView(PGChildNodeView):
class CastView(PGChildNodeView)
A view class for cast node derived from PGChildNodeView. This class is
responsible for all the stuff related to view like create/update/delete cast,
showing properties of cast node, showing sql in sql pane.
responsible for all the stuff related to view like
create/update/delete cast, showing properties of cast node,
showing sql in sql pane.
Methods:
-------
@ -110,11 +112,12 @@ class CastView(PGChildNodeView):
manager,conn & template_path properties to self
* list()
- This function is used to list all the cast nodes within that collection.
- This function is used to list all the cast nodes within that
collection.
* nodes()
- This function will used to create all the child node within that collection.
Here it will create all the cast nodes.
- This function will used to create all the child node within that
collection. Here it will create all the cast nodes.
* properties(gid, sid, did, rg_id)
- This function will show the properties of the selected cast node
@ -135,14 +138,16 @@ class CastView(PGChildNodeView):
- This function will generate sql from model data
* sql(gid, sid, did, rg_id):
- This function will generate sql to show in sql pane for the selected cast node.
- This function will generate sql to show in sql pane for the selected
cast 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.
* get_functions():
- This function will fetch associated functions list depending on selected source
and target types while creating a new cast node.
- This function will fetch associated functions list depending on
selected source and target types while creating a new cast node.
"""
node_type = blueprint.node_type
@ -171,8 +176,14 @@ class CastView(PGChildNodeView):
'stats': [{'get': 'statistics'}],
'dependency': [{'get': 'dependencies'}],
'dependent': [{'get': 'dependents'}],
'get_type': [{'get': 'get_src_and_trg_type'}, {'get': 'get_src_and_trg_type'}],
'get_functions': [{'post': 'get_functions'}, {'post': 'get_functions'}]
'get_type': [
{'get': 'get_src_and_trg_type'},
{'get': 'get_src_and_trg_type'}
],
'get_functions': [
{'post': 'get_functions'},
{'post': 'get_functions'}
]
})
def _init_(self, **kwargs):
@ -192,7 +203,9 @@ class CastView(PGChildNodeView):
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'])
# Set template path for the SQL scripts
self.template_path = 'cast/sql/#{0}#'.format(self.manager.version)
@ -225,7 +238,8 @@ class CastView(PGChildNodeView):
return internal_server_error(errormsg=res)
for row in res['rows']:
row['castcontext'] = True if row['castcontext'] == 'IMPLICIT' else False
row['castcontext'] = True if row['castcontext'] == 'IMPLICIT' \
else False
return ajax_response(
response=res['rows'],
@ -235,8 +249,8 @@ class CastView(PGChildNodeView):
@check_precondition
def nodes(self, gid, sid, did):
"""
This function will used to create all the child nodes within the collection.
Here it will create all the cast nodes.
This function will used to create all the child nodes within the
collection. Here it will create all the cast nodes.
:param gid: group id
:param sid: server id
:param did: database id
@ -366,17 +380,19 @@ class CastView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
# we need oid to to add object in tree at browser, below sql will gives the same
# we need oid to to add object in tree at browser, below sql will
# gives the same
last_system_oid = 0 if self.blueprint.show_system_objects else \
(self.manager.db_info[did])['datlastsysoid'] \
if self.manager.db_info is not None and \
did in self.manager.db_info else 0
sql = render_template("/".join([self.template_path, 'properties.sql']),
srctyp=data['srctyp'],
trgtyp=data['trgtyp'],
datlastsysoid=last_system_oid,
showsysobj=self.blueprint.show_system_objects
)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
srctyp=data['srctyp'],
trgtyp=data['trgtyp'],
datlastsysoid=last_system_oid,
showsysobj=self.blueprint.show_system_objects
)
status, cid = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=cid)
@ -527,10 +543,12 @@ class CastView(PGChildNodeView):
(self.manager.db_info[did])['datlastsysoid'] \
if self.manager.db_info is not None and \
did in self.manager.db_info else 0
sql = render_template("/".join([self.template_path, 'properties.sql']),
cid=cid,
datlastsysoid=last_system_oid,
showsysobj=self.blueprint.show_system_objects)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
cid=cid,
datlastsysoid=last_system_oid,
showsysobj=self.blueprint.show_system_objects
)
status, res = self.conn.execute_dict(sql)
if not status:
@ -549,7 +567,10 @@ class CastView(PGChildNodeView):
return sql, data['name'] if 'name' in data else old_data['name']
else:
if 'srctyp' in data and 'trgtyp' in data:
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
)
else:
return u"-- definition incomplete", None
return sql, data['srctyp'] + "->" + data["trgtyp"]
@ -638,14 +659,14 @@ class CastView(PGChildNodeView):
status, res = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(
_("Could not generate reversed engineered SQL for the cast.\n\n{0}").format(
res
)
_("Could not generate reversed engineered SQL for the "
"cast.\n\n{0}").format(res)
)
if res is None:
return gone(
_("Could not generate reversed engineered SQL for the cast node.\n")
_("Could not generate reversed engineered SQL for the "
"cast node.\n")
)
return ajax_response(response=res)

View File

@ -56,7 +56,8 @@ def create_cast(server, source_type, target_type):
# Get 'oid' from newly created cast
pg_cursor.execute(
"SELECT ca.oid FROM pg_cast ca WHERE ca.castsource = "
"(SELECT t.oid FROM pg_type t WHERE format_type(t.oid, NULL)='%s') "
"(SELECT t.oid FROM pg_type t "
"WHERE format_type(t.oid, NULL)='%s') "
"AND ca.casttarget = (SELECT t.oid FROM pg_type t WHERE "
"format_type(t.oid, NULL) = '%s')" % (source_type, target_type))
oid = pg_cursor.fetchone()
@ -75,7 +76,8 @@ def verify_cast(connection, source_type, target_type):
pg_cursor = connection.cursor()
pg_cursor.execute(
"SELECT * FROM pg_cast ca WHERE ca.castsource = "
"(SELECT t.oid FROM pg_type t WHERE format_type(t.oid, NULL)='%s') "
"(SELECT t.oid FROM pg_type t "
"WHERE format_type(t.oid, NULL)='%s') "
"AND ca.casttarget = (SELECT t.oid FROM pg_type t WHERE "
"format_type(t.oid, NULL) = '%s')" % (source_type, target_type))
casts = pg_cursor.fetchall()
@ -92,7 +94,8 @@ def drop_cast(connection, source_type, target_type):
pg_cursor = connection.cursor()
pg_cursor.execute(
"SELECT * FROM pg_cast ca WHERE ca.castsource = "
"(SELECT t.oid FROM pg_type t WHERE format_type(t.oid, NULL)='%s') "
"(SELECT t.oid FROM pg_type t "
"WHERE format_type(t.oid, NULL)='%s') "
"AND ca.casttarget = (SELECT t.oid FROM pg_type t WHERE "
"format_type(t.oid, NULL) = '%s')" % (source_type, target_type))
if pg_cursor.fetchall():

View File

@ -30,7 +30,8 @@ class EventTriggerModule(CollectionNodeModule):
"""
class EventTriggerModule(CollectionNodeModule)
A module class for Event trigger node derived from CollectionNodeModule.
A module class for Event trigger node derived from
CollectionNodeModule.
Methods:
-------
@ -51,7 +52,8 @@ class EventTriggerModule(CollectionNodeModule):
def __init__(self, *args, **kwargs):
"""
Method is used to initialize the EventTriggerModule and it's base module.
Method is used to initialize the EventTriggerModule and it's base
module.
Args:
*args:
@ -184,9 +186,12 @@ class EventTriggerView(PGChildNodeView):
@wraps(f)
def wrap(*args, **kwargs):
# Here - args[0] will always hold self & kwargs will hold gid, sid, did
# Here - args[0] will always 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'])
self.template_path = 'event_triggers/sql/9.3_plus'
@ -222,8 +227,8 @@ class EventTriggerView(PGChildNodeView):
@check_precondition
def nodes(self, gid, sid, did):
"""
This function is used to create all the child nodes within the collection.
Here it will create all the event trigger nodes.
This function is used to create all the child nodes within the
collection. Here it will create all the event trigger nodes.
Args:
gid: Server Group ID
@ -318,7 +323,10 @@ class EventTriggerView(PGChildNodeView):
Returns:
"""
sql = render_template("/".join([self.template_path, 'properties.sql']), etid=etid, conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
etid=etid, conn=self.conn
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@ -374,18 +382,27 @@ class EventTriggerView(PGChildNodeView):
)
)
try:
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
)
status, res = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'grant.sql']), data=data, conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'grant.sql']),
data=data, conn=self.conn
)
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'get_oid.sql']), data=data)
sql = render_template(
"/".join([self.template_path, 'get_oid.sql']),
data=data
)
status, etid = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=etid)
@ -431,7 +448,10 @@ class EventTriggerView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'get_oid.sql']), data=data)
sql = render_template(
"/".join([self.template_path, 'get_oid.sql']),
data=data
)
status, etid = self.conn.execute_scalar(sql)
return jsonify(
@ -478,7 +498,10 @@ class EventTriggerView(PGChildNodeView):
else:
cascade = False
try:
sql = render_template("/".join([self.template_path, 'delete.sql']), etid=etid)
sql = render_template(
"/".join([self.template_path, 'delete.sql']),
etid=etid
)
status, name = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=name)
@ -495,7 +518,10 @@ class EventTriggerView(PGChildNodeView):
)
)
sql = render_template("/".join([self.template_path, 'delete.sql']), name=name, cascade=cascade)
sql = render_template(
"/".join([self.template_path, 'delete.sql']),
name=name, cascade=cascade
)
status, res = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=res)
@ -568,7 +594,10 @@ class EventTriggerView(PGChildNodeView):
]
if etid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']), etid=etid)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
etid=etid
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@ -584,7 +613,10 @@ class EventTriggerView(PGChildNodeView):
for arg in required_args:
if arg not in data:
data[arg] = old_data[arg]
sql = render_template("/".join([self.template_path, 'update.sql']), data=data, o_data=old_data)
sql = render_template(
"/".join([self.template_path, 'update.sql']),
data=data, o_data=old_data
)
else:
required_args = {
'name': 'Name',
@ -605,16 +637,22 @@ class EventTriggerView(PGChildNodeView):
"Could not find the required parameter %s." % err
)
)
sql = render_template("/".join([self.template_path, 'create.sql']), data=data)
sql = render_template(
"/".join([self.template_path, 'create.sql']),
data=data
)
sql += "\n"
sql += render_template("/".join([self.template_path, 'grant.sql']), data=data)
sql += render_template(
"/".join([self.template_path, 'grant.sql']),
data=data
)
return sql
@check_precondition
def sql(self, gid, sid, did, etid):
"""
This function will generate sql to show in the sql pane for the selected
event trigger node.
This function will generate sql to show in the sql pane for the
selected event trigger node.
Args:
gid: Server Group ID
@ -625,7 +663,10 @@ class EventTriggerView(PGChildNodeView):
Returns:
"""
sql = render_template("/".join([self.template_path, 'properties.sql']), etid=etid)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
etid=etid
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@ -638,16 +679,27 @@ class EventTriggerView(PGChildNodeView):
result = res['rows'][0]
result = self._formatter(result)
sql = render_template("/".join([self.template_path, 'create.sql']), data=result, conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'create.sql']),
data=result, conn=self.conn
)
sql += "\n\n"
sql += render_template("/".join([self.template_path, 'grant.sql']), data=result, conn=self.conn)
sql += render_template(
"/".join([self.template_path, 'grant.sql']),
data=result, conn=self.conn
)
db_sql = render_template("/".join([self.template_path, 'get_db.sql']), did=did)
db_sql = render_template(
"/".join([self.template_path, 'get_db.sql']),
did=did
)
status, db_name = self.conn.execute_scalar(db_sql)
if not status:
return internal_server_error(errormsg=db_name)
sql_header = u"-- Event Trigger: {0} on database {1}\n\n-- ".format(result['name'], db_name)
sql_header = u"-- Event Trigger: {0} on database {1}\n\n-- ".format(
result['name'], db_name
)
sql_header += render_template(
"/".join([self.template_path, 'delete.sql']),
@ -675,7 +727,9 @@ class EventTriggerView(PGChildNodeView):
"""
res = [{'label': '', 'value': ''}]
sql = render_template("/".join([self.template_path, 'eventfunctions.sql']))
sql = render_template(
"/".join([self.template_path, 'eventfunctions.sql'])
)
status, rest = self.conn.execute_2darray(sql)
if not status:
return internal_server_error(errormsg=rest)

View File

@ -77,10 +77,11 @@ class EventTriggerGetTestCase(BaseTestGenerator):
if not func_response:
raise Exception("Could not find the trigger function.")
response = self.tester.get(
self.url + str(utils.SERVER_GROUP) + '/'
+ str(self.server_id) + '/' + str(self.db_id) + '/' +
str(self.event_trigger_id),
content_type='html/json')
self.url +
str(utils.SERVER_GROUP) + '/' + str(self.server_id) + '/' +
str(self.db_id) + '/' + str(self.event_trigger_id),
content_type='html/json'
)
self.assertEquals(response.status_code, 200)
def tearDown(self):

View File

@ -78,8 +78,8 @@ class ExtensionModule(CollectionNodeModule):
@property
def script_load(self):
"""
Load the module script for extension, when any of the database nodes are
initialized.
Load the module script for extension, when any of the database nodes
are initialized.
"""
return databases.DatabaseModule.NODE_TYPE

View File

@ -90,7 +90,8 @@ class LanguageModule(CollectionNodeModule):
@property
def script_load(self):
"""
Load the module script for language, when any of the database nodes are initialized.
Load the module script for language, when any of the database nodes
are initialized.
Returns: node type of the server module.
"""
@ -112,9 +113,9 @@ class LanguageView(PGChildNodeView):
"""
class LanguageView(PGChildNodeView)
A view class for Language node derived from PGChildNodeView. This class is
responsible for all the stuff related to view like updating language
node, showing properties, showing sql in sql pane.
A view class for Language node derived from PGChildNodeView.
This class is responsible for all the stuff related to view like
updating language node, showing properties, showing sql in sql pane.
Methods:
-------
@ -127,11 +128,12 @@ class LanguageView(PGChildNodeView):
manager,conn & template_path properties to self
* list()
- This function is used to list all the language nodes within that collection.
- This function is used to list all the language nodes within that
collection.
* nodes()
- This function will used to create all the child node within that collection.
Here it will create all the language node.
- This function will used to create all the child node within that
collection. Here it will create all the language node.
* properties(gid, sid, did, lid)
- This function will show the properties of the selected language node
@ -146,25 +148,30 @@ class LanguageView(PGChildNodeView):
- This function will delete the selected language node
* msql(gid, sid, did, lid)
- This function is used to return modified SQL for the selected language node
- This function is used to return modified SQL for the selected
language node
* get_sql(data, lid)
- This function will generate sql from model data
* get_functions(gid, sid, did)
- This function returns the handler and inline functions for the selected language node
- This function returns the handler and inline functions for the
selected language node
* get_templates(gid, sid, did)
- This function returns language templates.
* sql(gid, sid, did, lid):
- This function will generate sql to show it in sql pane for the selected language node.
- This function will generate sql to show it in sql pane for the
selected language node.
* dependents(gid, sid, did, lid):
- This function get the dependents and return ajax response for the language node.
- This function get the dependents and return ajax response for the
language node.
* dependencies(self, gid, sid, did, lid):
- This function get the dependencies and return ajax response for the language node.
- This function get the dependencies and return ajax response for the
language node.
"""
node_type = blueprint.node_type
@ -197,7 +204,8 @@ class LanguageView(PGChildNodeView):
def _init_(self, **kwargs):
"""
Method is used to initialize the LanguageView and its base view.
Initialize all the variables create/used dynamically like conn, template_path.
Initialize all the variables create/used dynamically like conn,
template_path.
Args:
**kwargs:
@ -223,9 +231,11 @@ class LanguageView(PGChildNodeView):
self.manager = self.driver.connection_manager(kwargs['sid'])
self.conn = self.manager.connection(did=kwargs['did'])
# Set the template path for the SQL scripts
self.template_path = ("languages/sql/#gpdb#{0}#".format(self.manager.version)
if self.manager.server_type == 'gpdb'
else "languages/sql/#{0}#".format(self.manager.version))
self.template_path = (
"languages/sql/#gpdb#{0}#".format(self.manager.version) if
self.manager.server_type == 'gpdb' else
"languages/sql/#{0}#".format(self.manager.version)
)
return f(*args, **kwargs)
@ -234,7 +244,8 @@ class LanguageView(PGChildNodeView):
@check_precondition
def list(self, gid, sid, did):
"""
This function is used to list all the language nodes within that collection.
This function is used to list all the language nodes within that
collection.
Args:
gid: Server Group ID
@ -254,8 +265,8 @@ class LanguageView(PGChildNodeView):
@check_precondition
def nodes(self, gid, sid, did):
"""
This function is used to create all the child nodes within the collection.
Here it will create all the language nodes.
This function is used to create all the child nodes within the
collection. Here it will create all the language nodes.
Args:
gid: Server Group ID
@ -323,7 +334,10 @@ class LanguageView(PGChildNodeView):
did: Database ID
lid: Language ID
"""
sql = render_template("/".join([self.template_path, 'properties.sql']), lid=lid)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
lid=lid
)
status, res = self.conn.execute_dict(sql)
if not status:
@ -334,7 +348,10 @@ class LanguageView(PGChildNodeView):
gettext("Could not find the language information.")
)
sql = render_template("/".join([self.template_path, 'acl.sql']), lid=lid)
sql = render_template(
"/".join([self.template_path, 'acl.sql']),
lid=lid
)
status, result = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=result)
@ -344,7 +361,13 @@ class LanguageView(PGChildNodeView):
res['rows'][0]['lanacl'] = dict()
res['rows'][0]['lanacl']['grantee'] = 'PUBLIC'
res['rows'][0]['lanacl']['grantor'] = res['rows'][0]['lanowner']
res['rows'][0]['lanacl']['privileges'] = [{'privilege_type': 'U', 'privilege': True, 'with_grant': False}]
res['rows'][0]['lanacl']['privileges'] = [
{
'privilege_type': 'U',
'privilege': True,
'with_grant': False
}
]
else:
for row in result['rows']:
priv = parse_priv_from_db(row)
@ -354,7 +377,8 @@ class LanguageView(PGChildNodeView):
res['rows'][0][row['deftype']] = [priv]
seclabels = []
if 'seclabels' in res['rows'][0] and res['rows'][0]['seclabels'] is not None:
if 'seclabels' in res['rows'][0] and \
res['rows'][0]['seclabels'] is not None:
import re
for sec in res['rows'][0]['seclabels']:
sec = re.search(r'([^=]+)=(.*$)', sec)
@ -443,8 +467,10 @@ class LanguageView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'properties.sql']),
lanname=data['name'], conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
lanname=data['name'], conn=self.conn
)
status, r_set = self.conn.execute_dict(sql)
if not status:
@ -482,15 +508,20 @@ class LanguageView(PGChildNodeView):
try:
# Get name for language from lid
sql = render_template("/".join([self.template_path, 'delete.sql']), lid=lid, conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'delete.sql']),
lid=lid, conn=self.conn
)
status, lname = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=lname)
# drop language
sql = render_template("/".join([self.template_path, 'delete.sql']), lname=lname,
cascade=cascade, conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'delete.sql']),
lname=lname, cascade=cascade, conn=self.conn
)
status, res = self.conn.execute_scalar(sql)
if not status:
@ -513,7 +544,8 @@ class LanguageView(PGChildNodeView):
@check_precondition
def msql(self, gid, sid, did, lid=None):
"""
This function is used to return modified SQL for the selected language node.
This function is used to return modified SQL for the selected
language node.
Args:
gid: Server Group ID
@ -538,7 +570,7 @@ class LanguageView(PGChildNodeView):
return make_json_response(
data=sql,
status=200
)
)
except Exception as e:
return internal_server_error(errormsg=str(e))
@ -555,7 +587,9 @@ class LanguageView(PGChildNodeView):
]
if lid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']), lid=lid)
sql = render_template(
"/".join([self.template_path, 'properties.sql']), lid=lid
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@ -568,19 +602,28 @@ class LanguageView(PGChildNodeView):
for key in ['lanacl']:
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'], ["U"])
data[key]['added'] = parse_priv_to_db(
data[key]['added'], ["U"]
)
if 'changed' in data[key]:
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], ["U"])
data[key]['changed'] = parse_priv_to_db(
data[key]['changed'], ["U"]
)
if 'deleted' in data[key]:
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], ["U"])
data[key]['deleted'] = parse_priv_to_db(
data[key]['deleted'], ["U"]
)
old_data = res['rows'][0]
for arg in required_args:
if arg not in data:
data[arg] = old_data[arg]
sql = render_template("/".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']
sql = render_template(
"/".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']
else:
if 'lanacl' in data:
@ -590,11 +633,11 @@ class LanguageView(PGChildNodeView):
data=data, conn=self.conn)
return sql.strip('\n'), data['name']
@check_precondition
def get_functions(self, gid, sid, did):
"""
This function returns the handler and inline functions for the selected language node.
This function returns the handler and inline functions for the
selected language node.
Args:
gid: Server Group ID
@ -632,7 +675,8 @@ class LanguageView(PGChildNodeView):
@check_precondition
def sql(self, gid, sid, did, lid):
"""
This function will generate sql to show in the sql pane for the selected language node.
This function will generate sql to show in the sql pane for the
selected language node.
Args:
gid: Server Group ID
@ -640,7 +684,10 @@ class LanguageView(PGChildNodeView):
did: Database ID
lid: Language ID
"""
sql = render_template("/".join([self.template_path, 'properties.sql']), lid=lid)
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
lid=lid
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@ -653,7 +700,10 @@ class LanguageView(PGChildNodeView):
# Making copy of output for future use
old_data = dict(res['rows'][0])
sql = render_template("/".join([self.template_path, 'acl.sql']), lid=lid)
sql = render_template(
"/".join([self.template_path, 'acl.sql']),
lid=lid
)
status, result = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=result)
@ -676,7 +726,10 @@ class LanguageView(PGChildNodeView):
})
old_data['seclabels'] = seclabels
sql = render_template("/".join([self.template_path, 'sqlpane.sql']), data=old_data, conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'sqlpane.sql']),
data=old_data, conn=self.conn
)
return ajax_response(response=sql.strip('\n'))

View File

@ -50,23 +50,21 @@ class LanguagesAddTestCase(BaseTestGenerator):
"lanval": "fmgr_c_validator",
"name": "language_%s" % str(uuid.uuid4())[1:8],
"seclabels": [],
"template_list":
[
"plperl",
"plperlu",
"plpython2u",
"plpython3u",
"plpythonu",
"pltcl",
"pltclu"
],
"template_list": [
"plperl",
"plperlu",
"plpython2u",
"plpython3u",
"plpythonu",
"pltcl",
"pltclu"
],
"trusted": "true"
}
}
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) + '/',
data=json.dumps(self.data),
content_type='html/json')
@ -76,7 +74,7 @@ class LanguagesAddTestCase(BaseTestGenerator):
"""This function delete added language and
disconnect the test database."""
language_utils.delete_language(self.server, self.db_name,
self.data['name'])
language_utils.delete_language(
self.server, self.db_name, self.data['name']
)
database_utils.disconnect_database(self, self.server_id, self.db_id)