PEP8 changes for the FDW modules.

This commit is contained in:
Khushboo Vashi 2018-03-02 14:46:13 +00:00 committed by Dave Page
parent 0c48b79ce7
commit 905cdafe90
14 changed files with 351 additions and 211 deletions

View File

@ -33,19 +33,21 @@ class ForeignDataWrapperModule(CollectionNodeModule):
"""
class ForeignDataWrapperModule(CollectionNodeModule)
A module class for foreign data wrapper node derived from CollectionNodeModule.
A module class for foreign data wrapper node derived
from CollectionNodeModule.
Methods:
-------
* __init__(*args, **kwargs)
- Method is used to initialize the Foreign data wrapper module and it's base module.
- Method is used to initialize the Foreign data wrapper
module and it's base module.
* get_nodes(gid, sid, did)
- Method is used to generate the browser collection node.
* script_load()
- Load the module script for foreign data wrapper, when any of the database node is
initialized.
- Load the module script for foreign data wrapper,
when any of the database node is initialized.
"""
NODE_TYPE = 'foreign_data_wrapper'
@ -53,7 +55,8 @@ class ForeignDataWrapperModule(CollectionNodeModule):
def __init__(self, *args, **kwargs):
"""
Method is used to initialize the Foreign data wrapper module and it's base module.
Method is used to initialize the Foreign data wrapper module
and it's base module.
Args:
*args:
@ -80,7 +83,8 @@ class ForeignDataWrapperModule(CollectionNodeModule):
@property
def script_load(self):
"""
Load the module script for foreign data wrapper, when any of the database node is initialized.
Load the module script for foreign data wrapper,
when any of the database node is initialized.
Returns: node type of the databse module.
"""
@ -89,8 +93,8 @@ class ForeignDataWrapperModule(CollectionNodeModule):
@property
def module_use_template_javascript(self):
"""
Returns whether Jinja2 template is used for generating the javascript
module.
Returns whether Jinja2 template is used for
generating the javascript module.
"""
return False
@ -102,14 +106,16 @@ class ForeignDataWrapperView(PGChildNodeView):
"""
class ForeignDataWrapperView(PGChildNodeView)
A view class for foreign data wrapper node derived from PGChildNodeView. This class is
responsible for all the stuff related to view like updating foreign data wrapper
A view class for foreign data wrapper node derived
from PGChildNodeView. This class is responsible for all the
stuff related to view like updating foreign data wrapper
node, showing properties, showing sql in sql pane.
Methods:
-------
* __init__(**kwargs)
- Method is used to initialize the ForeignDataWrapperView and it's base view.
- Method is used to initialize the ForeignDataWrapperView
and it's base view.
* check_precondition()
- This function will behave as a decorator which will checks
@ -117,14 +123,16 @@ class ForeignDataWrapperView(PGChildNodeView):
manager,conn & template_path properties to self
* list(gid, sid, did)
- This function is used to list all the foreign data wrapper nodes within that collection.
- This function is used to list all the foreign data wrapper nodes
within that collection.
* nodes(gid, sid, did)
- This function will used to create all the child node within that collection.
Here it will create all the foreign data wrapper node.
- This function will used to create all the child node within that
collection. Here it will create all the foreign data wrapper node.
* properties(gid, sid, did, fid)
- This function will show the properties of the selected foreign data wrapper node
- This function will show the properties of the selected
foreign data wrapper node
* create(gid, sid, did)
- This function will create the new foreign data wrapper node
@ -133,28 +141,35 @@ class ForeignDataWrapperView(PGChildNodeView):
- This function will delete the selected foreign data wrapper node
* update(gid, sid, did, fid)
- This function will update the data for the selected foreign data wrapper node
- This function will update the data for the selected
foreign data wrapper node
* msql(gid, sid, did, fid)
- This function is used to return modified SQL for the selected foreign data wrapper node
- This function is used to return modified SQL for the selected
foreign data wrapper node
* get_sql(data, fid)
- This function will generate sql from model data
* get_validators(gid, sid, did)
- This function returns the validators for the selected foreign data wrapper node
- This function returns the validators for the selected
foreign data wrapper node
* get_handlers(gid, sid, did)
- This function returns the handlers for the selected foreign data wrapper node
- This function returns the handlers for the selected
foreign data wrapper node
* sql(gid, sid, did, fid):
- This function will generate sql to show it in sql pane for the selected foreign data wrapper node.
- This function will generate sql to show it in sql pane for
the selected foreign data wrapper node.
* dependents(gid, sid, did, fid):
- This function get the dependents and return ajax response for the foreign data wrapper node.
- This function get the dependents and return ajax response for the
foreign data wrapper node.
* dependencies(self, gid, sid, did, fid):
- This function get the dependencies and return ajax response for the foreign data wrapper node.
- This function get the dependencies and return ajax response for the
foreign data wrapper node.
"""
node_type = blueprint.node_type
@ -244,8 +259,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition
def nodes(self, gid, sid, did):
"""
This function will used to create all the child node within that collection.
Here it will create all the foreign data wrapper node.
This function will used to create all the child node within that
collection. Here it will create all the foreign data wrapper node.
Args:
gid: Server Group ID
@ -302,12 +317,14 @@ class ForeignDataWrapperView(PGChildNodeView):
status=200
)
return gone(gettext("Could not find the specified foreign data wrapper."))
return gone(gettext("Could not find the specified"
" foreign data wrapper."))
@check_precondition
def properties(self, gid, sid, did, fid):
"""
This function will show the properties of the selected foreign data wrapper node.
This function will show the properties of the
selected foreign data wrapper node.
Args:
gid: Server Group ID
@ -315,7 +332,8 @@ class ForeignDataWrapperView(PGChildNodeView):
did: Database ID
fid: foreign data wrapper ID
"""
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fid=fid, conn=self.conn
)
status, res = self.conn.execute_dict(sql)
@ -325,7 +343,8 @@ class ForeignDataWrapperView(PGChildNodeView):
if len(res['rows']) == 0:
return gone(
gettext("Could not find the foreign data wrapper information.")
gettext("Could not find the foreign data"
" wrapper information.")
)
if res['rows'][0]['fdwoptions'] is not None:
@ -334,7 +353,9 @@ class ForeignDataWrapperView(PGChildNodeView):
'fdwoption', 'fdwvalue'
)
sql = render_template("/".join([self.template_path, 'acl.sql']), fid=fid)
sql = render_template("/".join([self.template_path, 'acl.sql']),
fid=fid
)
status, fdw_acl_res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=fdw_acl_res)
@ -389,15 +410,18 @@ class ForeignDataWrapperView(PGChildNodeView):
)
sql = render_template("/".join([self.template_path, 'create.sql']),
data=data, conn=self.conn,
data=data,
conn=self.conn,
is_valid_options=is_valid_options
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'properties.sql']),
fname=data['name'], conn=self.conn
sql = render_template("/".join([self.template_path,
'properties.sql']),
fname=data['name'],
conn=self.conn
)
status, r_set = self.conn.execute_dict(sql)
@ -420,7 +444,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition
def update(self, gid, sid, did, fid):
"""
This function will update the data for the selected foreign data wrapper node.
This function will update the data for the selected
foreign data wrapper node.
Args:
gid: Server Group ID
@ -486,12 +511,15 @@ class ForeignDataWrapperView(PGChildNodeView):
'Error: Object not found.'
),
info=gettext(
'The specified foreign data wrapper could not be found.\n'
'The specified foreign data'
' wrapper could not be found.\n'
)
)
# drop foreign data wrapper node
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,
conn=self.conn)
status, res = self.conn.execute_scalar(sql)
if not status:
@ -514,7 +542,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition
def msql(self, gid, sid, did, fid=None):
"""
This function is used to return modified SQL for the selected foreign data wrapper node.
This function is used to return modified SQL for the
selected foreign data wrapper node.
Args:
gid: Server Group ID
@ -551,7 +580,8 @@ class ForeignDataWrapperView(PGChildNodeView):
gid: Server Group ID
sid: Server ID
did: Database ID
data: Contains the data of the selected foreign data wrapper node
data: Contains the data of the selected
foreign data wrapper node
fid: foreign data wrapper ID
"""
required_args = [
@ -559,8 +589,10 @@ class ForeignDataWrapperView(PGChildNodeView):
]
if fid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']),
fid=fid, conn=self.conn
sql = render_template("/".join([self.template_path,
'properties.sql']),
fid=fid,
conn=self.conn
)
status, res = self.conn.execute_dict(sql)
if not status:
@ -568,7 +600,8 @@ class ForeignDataWrapperView(PGChildNodeView):
if len(res['rows']) == 0:
return gone(
gettext("Could not find the foreign data wrapper information.")
gettext("Could not find the foreign"
" data wrapper information.")
)
if res['rows'][0]['fdwoptions'] is not None:
@ -580,33 +613,49 @@ class ForeignDataWrapperView(PGChildNodeView):
for key in ['fdwacl']:
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]
# Allow user to set the blank value in fdwvalue field in option model
# Allow user to set the blank value in fdwvalue
# field in option model
is_valid_added_options = is_valid_changed_options = False
if 'fdwoptions' in data and 'added' in data['fdwoptions']:
is_valid_added_options, data['fdwoptions']['added'] = validate_options(
data['fdwoptions']['added'], 'fdwoption', 'fdwvalue'
)
is_valid_added_options, data['fdwoptions']['added'] = \
validate_options(
data['fdwoptions']['added'],
'fdwoption',
'fdwvalue')
if 'fdwoptions' in data and 'changed' in data['fdwoptions']:
is_valid_changed_options, data['fdwoptions']['changed'] = validate_options(
data['fdwoptions']['changed'], 'fdwoption', 'fdwvalue'
)
is_valid_changed_options, data['fdwoptions']['changed'] = \
validate_options(
data['fdwoptions']['changed'],
'fdwoption',
'fdwvalue')
sql = render_template("/".join([self.template_path, 'update.sql']),
data=data, o_data=old_data,
is_valid_added_options=is_valid_added_options,
is_valid_changed_options=is_valid_changed_options,
conn=self.conn
sql = render_template(
"/".join([self.template_path, 'update.sql']),
data=data,
o_data=old_data,
is_valid_added_options=is_valid_added_options,
is_valid_changed_options=is_valid_changed_options,
conn=self.conn
)
return sql, data['name'] if 'name' in data else old_data['name']
else:
@ -614,25 +663,27 @@ class ForeignDataWrapperView(PGChildNodeView):
if key in data and data[key] is not None:
data[key] = parse_priv_to_db(data[key], ['U'])
# Allow user to set the blank value in fdwvalue field in option model
# Allow user to set the blank value in
# fdwvalue field in option model
is_valid_options = False
if 'fdwoptions' in data:
is_valid_options, data['fdwoptions'] = validate_options(
data['fdwoptions'], 'fdwoption', 'fdwvalue'
)
sql = render_template("/".join([self.template_path, 'create.sql']),
sql = render_template("/".join([self.template_path,
'create.sql']),
data=data, conn=self.conn,
is_valid_options=is_valid_options
)
return sql, data['name']
@check_precondition
def sql(self, gid, sid, did, fid):
"""
This function will generate sql to show it in sql pane for the selected foreign data wrapper node.
This function will generate sql to show it in sql pane
for the selected foreign data wrapper node.
Args:
gid: Server Group ID
@ -660,7 +711,8 @@ class ForeignDataWrapperView(PGChildNodeView):
if len(res['rows'][0]['fdwoptions']) > 0:
is_valid_options = True
sql = render_template("/".join([self.template_path, 'acl.sql']), fid=fid)
sql = render_template("/".join([self.template_path, 'acl.sql']),
fid=fid)
status, fdw_acl_res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=fdw_acl_res)
@ -674,7 +726,10 @@ class ForeignDataWrapperView(PGChildNodeView):
# To format privileges
if 'fdwacl' in res['rows'][0]:
res['rows'][0]['fdwacl'] = parse_priv_to_db(res['rows'][0]['fdwacl'], ['U'])
res['rows'][0]['fdwacl'] = parse_priv_to_db(
res['rows'][0]['fdwacl'],
['U']
)
sql = ''
sql = render_template("/".join([self.template_path, 'create.sql']),
@ -696,7 +751,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition
def get_validators(self, gid, sid, did):
"""
This function returns the validators for the selected foreign data wrapper node.
This function returns the validators for the selected
foreign data wrapper node.
Args:
gid: Server Group ID
@ -705,7 +761,8 @@ class ForeignDataWrapperView(PGChildNodeView):
"""
res = [{'label': '', 'value': ''}]
try:
sql = render_template("/".join([self.template_path, 'validators.sql']),
sql = render_template("/".join([self.template_path,
'validators.sql']),
conn=self.conn)
status, r_set = self.conn.execute_2darray(sql)
@ -724,7 +781,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition
def get_handlers(self, gid, sid, did):
"""
This function returns the handlers for the selected foreign data wrapper node.
This function returns the handlers for the selected
foreign data wrapper node.
Args:
gid: Server Group ID
@ -733,7 +791,8 @@ class ForeignDataWrapperView(PGChildNodeView):
"""
res = [{'label': '', 'value': ''}]
try:
sql = render_template("/".join([self.template_path, 'handlers.sql']),
sql = render_template("/".join([self.template_path,
'handlers.sql']),
conn=self.conn)
status, r_set = self.conn.execute_2darray(sql)

View File

@ -33,19 +33,21 @@ class ForeignServerModule(CollectionNodeModule):
"""
class ForeignServerModule(CollectionNodeModule)
A module class for foreign server node derived from CollectionNodeModule.
A module class for foreign server node derived from
CollectionNodeModule.
Methods:
-------
* __init__(*args, **kwargs)
- Method is used to initialize the Foreign server module and it's base module.
- Method is used to initialize the Foreign server module and
it's base module.
* get_nodes(gid, sid, did)
- Method is used to generate the browser collection node.
* script_load(self)
- Load the module script for foreign server, when any of the database node is
initialized.
- Load the module script for foreign server, when any of
the database node is initialized.
"""
NODE_TYPE = 'foreign_server'
@ -53,7 +55,8 @@ class ForeignServerModule(CollectionNodeModule):
def __init__(self, *args, **kwargs):
"""
Method is used to initialize the Foreign server module and it's base module.
Method is used to initialize the Foreign server module and
it's base module.
Args:
*args:
@ -80,7 +83,8 @@ class ForeignServerModule(CollectionNodeModule):
@property
def script_load(self):
"""
Load the module script for foreign server, when any of the foreign data wrapper node is initialized.
Load the module script for foreign server, when any of the
foreign data wrapper node is initialized.
Returns: node type of the server module.
"""
@ -102,9 +106,10 @@ class ForeignServerView(PGChildNodeView):
"""
class ForeignServerView(PGChildNodeView)
A view class for foreign server node derived from PGChildNodeView. This class is
responsible for all the stuff related to view like updating foreign server
node, showing properties, showing sql in sql pane.
A view class for foreign server node derived from PGChildNodeView.
This class is responsible for all the stuff related to view like
updating foreign server node, showing properties,
showing sql in sql pane.
Methods:
-------
@ -121,17 +126,21 @@ class ForeignServerView(PGChildNodeView):
manager,conn & template_path properties to self
* list(gid, sid, did, fid)
- This function is used to list all the foreign server nodes within that collection.
- This function is used to list all the foreign server nodes within
that collection.
* nodes(gid, sid, did, fid)
- 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 foreign server node.
* properties(gid, sid, did, fid, fsid)
- This function will show the properties of the selected foreign server node
- This function will show the properties of the selected
foreign server node
* update(gid, sid, did, fid, fsid)
- This function will update the data for the selected foreign server node
- This function will update the data for the selected
foreign server node
* create(gid, sid, did, fid)
- This function will create the new foreign server node
@ -140,19 +149,23 @@ class ForeignServerView(PGChildNodeView):
- This function will delete the selected foreign server node
* msql(gid, sid, did, fid, fsid)
- This function is used to return modified SQL for the selected foreign server node
- This function is used to return modified SQL for the selected
foreign server node
* get_sql(data, fid, fsid)
- This function will generate sql from model data
* sql(gid, sid, did, fid, fsid):
- This function will generate sql to show it in sql pane for the selected foreign server node.
- This function will generate sql to show it in sql pane for the
selected foreign server node.
* dependents(gid, sid, did, fid, fsid):
- This function get the dependents and return ajax response for the foreign server node.
- This function get the dependents and return ajax response for the
foreign server node.
* dependencies(self, gid, sid, did, fid, fsid):
- This function get the dependencies and return ajax response for the foreign server node.
- This function get the dependencies and return ajax response for the
foreign server node.
"""
node_type = blueprint.node_type
@ -226,7 +239,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition
def list(self, gid, sid, did, fid):
"""
This function is used to list all the foreign server nodes within that collection.
This function is used to list all the foreign server nodes
within that collection.
Args:
gid: Server Group ID
@ -250,7 +264,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition
def nodes(self, gid, sid, did, fid):
"""
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 foreign server node.
Args:
@ -320,7 +335,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition
def properties(self, gid, sid, did, fid, fsid):
"""
This function will show the properties of the selected foreign server node.
This function will show the properties of the selected
foreign server node.
Args:
gid: Server Group ID
@ -347,7 +363,9 @@ class ForeignServerView(PGChildNodeView):
res['rows'][0]['fsrvoptions'], 'fsrvoption', 'fsrvvalue'
)
sql = render_template("/".join([self.template_path, 'acl.sql']), fsid=fsid)
sql = render_template("/".join([self.template_path, 'acl.sql']),
fsid=fsid
)
status, fs_rv_acl_res = self.conn.execute_dict(sql)
if not status:
@ -397,7 +415,8 @@ class ForeignServerView(PGChildNodeView):
if 'fsrvacl' in data:
data['fsrvacl'] = parse_priv_to_db(data['fsrvacl'], ['U'])
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fdwid=fid, conn=self.conn)
status, res1 = self.conn.execute_dict(sql)
if not status:
@ -419,7 +438,8 @@ class ForeignServerView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
data=data, fdwdata=fdw_data,
conn=self.conn)
status, r_set = self.conn.execute_dict(sql)
@ -440,7 +460,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition
def update(self, gid, sid, did, fid, fsid):
"""
This function will update the data for the selected foreign server node.
This function will update the data for the selected
foreign server node.
Args:
gid: Server Group ID
@ -541,7 +562,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition
def msql(self, gid, sid, did, fid, fsid=None):
"""
This function is used to return modified SQL for the selected foreign server node.
This function is used to return modified SQL for the selected foreign
server node.
Args:
gid: Server Group ID
@ -567,8 +589,7 @@ class ForeignServerView(PGChildNodeView):
return make_json_response(
data=sql.strip('\n'),
status=200
)
status=200)
except Exception as e:
return internal_server_error(errormsg=str(e))
@ -591,7 +612,8 @@ class ForeignServerView(PGChildNodeView):
]
if fsid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fsid=fsid, conn=self.conn)
status, res = self.conn.execute_dict(sql)
if not status:
@ -609,11 +631,20 @@ class ForeignServerView(PGChildNodeView):
for key in ['fsrvacl']:
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:
@ -622,22 +653,31 @@ class ForeignServerView(PGChildNodeView):
is_valid_added_options = is_valid_changed_options = False
if 'fsrvoptions' in data and 'added' in data['fsrvoptions']:
is_valid_added_options, data['fsrvoptions']['added'] = validate_options(
data['fsrvoptions']['added'], 'fsrvoption', 'fsrvvalue'
)
if 'fsrvoptions' in data and 'changed' in data['fsrvoptions']:
is_valid_changed_options, data['fsrvoptions']['changed'] = validate_options(
data['fsrvoptions']['changed'], 'fsrvoption', 'fsrvvalue'
)
is_valid_added_options, data['fsrvoptions']['added'] =\
validate_options(
data['fsrvoptions']['added'],
'fsrvoption',
'fsrvvalue')
sql = render_template("/".join([self.template_path, 'update.sql']),
data=data, o_data=old_data,
is_valid_added_options=is_valid_added_options,
is_valid_changed_options=is_valid_changed_options,
conn=self.conn)
if 'fsrvoptions' in data and 'changed' in data['fsrvoptions']:
is_valid_changed_options, data['fsrvoptions']['changed'] =\
validate_options(
data['fsrvoptions']['changed'],
'fsrvoption',
'fsrvvalue')
sql = render_template(
"/".join([self.template_path, 'update.sql']),
data=data,
o_data=old_data,
is_valid_added_options=is_valid_added_options,
is_valid_changed_options=is_valid_changed_options,
conn=self.conn
)
return sql, data['name'] if 'name' in data else old_data['name']
else:
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fdwid=fid, conn=self.conn)
status, res = self.conn.execute_dict(sql)
if not status:
@ -649,7 +689,6 @@ class ForeignServerView(PGChildNodeView):
if key in data and data[key] is not None:
data[key] = parse_priv_to_db(data[key], ['U'])
is_valid_options = False
if 'fsrvoptions' in data:
is_valid_options, data['fsrvoptions'] = validate_options(
@ -663,11 +702,11 @@ class ForeignServerView(PGChildNodeView):
sql += "\n"
return sql, data['name']
@check_precondition
def sql(self, gid, sid, did, fid, fsid):
"""
This function will generate sql to show it in sql pane for the selected foreign server node.
This function will generate sql to show it in sql pane for the
selected foreign server node.
Args:
gid: Server Group ID
@ -696,7 +735,8 @@ class ForeignServerView(PGChildNodeView):
if len(res['rows'][0]['fsrvoptions']) > 0:
is_valid_options = True
sql = render_template("/".join([self.template_path, 'acl.sql']), fsid=fsid)
sql = render_template("/".join([self.template_path, 'acl.sql']),
fsid=fsid)
status, fs_rv_acl_res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=fs_rv_acl_res)
@ -710,7 +750,10 @@ class ForeignServerView(PGChildNodeView):
# To format privileges
if 'fsrvacl' in res['rows'][0]:
res['rows'][0]['fsrvacl'] = parse_priv_to_db(res['rows'][0]['fsrvacl'], ['U'])
res['rows'][0]['fsrvacl'] = parse_priv_to_db(
res['rows'][0]['fsrvacl'],
['U']
)
sql = render_template("/".join([self.template_path, 'properties.sql']),
fdwid=fid, conn=self.conn)
@ -753,7 +796,8 @@ class ForeignServerView(PGChildNodeView):
dependents_result = self.get_dependents(self.conn, fsid)
# Fetching dependents of foreign servers
query = render_template("/".join([self.template_path, 'dependents.sql']),
query = render_template("/".join([self.template_path,
'dependents.sql']),
fsid=fsid)
status, result = self.conn.execute_dict(query)
if not status:

View File

@ -14,8 +14,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests \
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator
@ -94,8 +94,9 @@ class ForeignServerAddTestCase(BaseTestGenerator):
}
response = self.tester.post(
self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.db_id) + '/'
+ str(self.fdw_id) + '/', data=json.dumps(data),
str(self.server_id) + '/' + str(self.db_id) +
'/' + str(self.fdw_id) + '/',
data=json.dumps(data),
content_type='html/json')
self.assertEquals(response.status_code, 200)

View File

@ -13,8 +13,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests \
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator

View File

@ -13,8 +13,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests\
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator
@ -62,8 +62,8 @@ class ForeignServerGetTestCase(BaseTestGenerator):
raise Exception("Could not find FDW.")
fsrv_response = self.tester.get(
self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.db_id) + '/'
+ str(self.fdw_id) + '/' + str(self.fsrv_id),
str(self.server_id) + '/' + str(self.db_id) +
'/' + str(self.fdw_id) + '/' + str(self.fsrv_id),
content_type='html/json')
self.assertEquals(fsrv_response.status_code, 200)

View File

@ -14,8 +14,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests\
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator
@ -65,10 +65,8 @@ class ForeignServerPutTestCase(BaseTestGenerator):
self.fsrv_name)
if not fsrv_response:
raise Exception("Could not find FSRV.")
data = {
"description": "This is foreign server update comment",
"id": self.fsrv_id
}
data = {"description": "This is foreign server update comment",
"id": self.fsrv_id}
put_response = self.tester.put(
self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.db_id) +

View File

@ -60,16 +60,16 @@ def create_fsrv(server, db_name, fsrv_name, fdw_name):
print(exception, file=sys.stderr)
def verify_fsrv(server, db_name , fsrv_name):
def verify_fsrv(server, db_name, fsrv_name):
""" This function will verify current foreign server."""
try:
connection = get_db_connection(db_name,
server['username'],
server['db_password'],
server['host'],
server['port'],
server['sslmode'])
server['username'],
server['db_password'],
server['host'],
server['port'],
server['sslmode'])
pg_cursor = connection.cursor()
pg_cursor.execute(

View File

@ -33,22 +33,25 @@ class UserMappingModule(CollectionNodeModule):
"""
class UserMappingModule(CollectionNodeModule)
A module class for user mapping node derived from CollectionNodeModule.
A module class for user mapping node derived
from CollectionNodeModule.
Methods:
-------
* __init__(*args, **kwargs)
- Method is used to initialize the user mapping module and it's base module.
- Method is used to initialize the user mapping module and
it's base module.
* get_nodes(gid, sid, did, fid, fsid)
- Method is used to generate the browser collection node.
* node_inode()
- Method is overridden from its base class to make the node as leaf node.
- Method is overridden from its base class to make the node
as leaf node.
* script_load(self)
- Load the module script for user mapping, when any of the foreign server node is
initialized.
- Load the module script for user mapping, when any of the
foreign server node is initialized.
"""
NODE_TYPE = 'user_mapping'
@ -56,7 +59,8 @@ class UserMappingModule(CollectionNodeModule):
def __init__(self, *args, **kwargs):
"""
Method is used to initialize the User mapping module and it's base module.
Method is used to initialize the User mapping module and
it's base module.
Args:
*args:
@ -94,7 +98,8 @@ class UserMappingModule(CollectionNodeModule):
@property
def script_load(self):
"""
Load the module script for user mapping, when any of the foreign server node is initialized.
Load the module script for user mapping, when any of the
foreign server node is initialized.
Returns: node type of the server module.
"""
@ -117,9 +122,10 @@ class UserMappingView(PGChildNodeView):
"""
class UserMappingView(PGChildNodeView)
A view class for user mapping node derived from PGChildNodeView. This class is
responsible for all the stuff related to view like updating user mapping
node, showing properties, showing sql in sql pane.
A view class for user mapping node derived from PGChildNodeView.
This class is responsible for all the stuff related to view like
updating user mapping node, showing properties,
showing sql in sql pane.
Methods:
-------
@ -136,17 +142,21 @@ class UserMappingView(PGChildNodeView):
manager,conn & template_path properties to self
* list(gid, sid, did, fid, fsid)
- This function is used to list all the user mapping nodes within that collection.
- This function is used to list all the user mapping nodes
within that collection.
* nodes(gid, sid, did, fid, fsid)
- 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 user mapping node.
* properties(gid, sid, did, fid, fsid, umid)
- This function will show the properties of the selected user mapping node
- This function will show the properties of the selected
user mapping node
* update(gid, sid, did, fid, fsid, umid)
- This function will update the data for the selected user mapping node
- This function will update the data for the selected
user mapping node
* create(gid, sid, did, fid, fsid)
- This function will create the new user mapping node
@ -155,19 +165,23 @@ class UserMappingView(PGChildNodeView):
- This function will delete the selected user mapping node
* msql(gid, sid, did, fid, fsid, umid)
- This function is used to return modified SQL for the selected user mapping node
- This function is used to return modified SQL for the
selected user mapping node
* get_sql(data, fid, fsid, umid)
- This function will generate sql from model data
* sql(gid, sid, did, fid, fsid, umid):
- This function will generate sql to show it in sql pane for the selected user mapping node.
- This function will generate sql to show it in sql pane for the
selected user mapping node.
* dependents(gid, sid, did, fid, fsid, umid):
- This function get the dependents and return ajax response for the user mapping node.
- This function get the dependents and return ajax response for the
user mapping node.
* dependencies(self, gid, sid, did, fid, fsid, umid):
- This function get the dependencies and return ajax response for the user mapping node.
- This function get the dependencies and return ajax response for the
user mapping node.
"""
node_type = blueprint.node_type
@ -242,7 +256,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition
def list(self, gid, sid, did, fid, fsid):
"""
This function is used to list all the user mapping nodes within that collection.
This function is used to list all the user mapping nodes
within that collection.
Args:
gid: Server Group ID
@ -252,7 +267,8 @@ class UserMappingView(PGChildNodeView):
fsid: Foreign server ID
"""
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fsid=fsid, conn=self.conn)
status, res = self.conn.execute_dict(sql)
@ -267,7 +283,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition
def nodes(self, gid, sid, did, fid, fsid):
"""
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 user mapping node.
Args:
@ -279,7 +296,8 @@ class UserMappingView(PGChildNodeView):
"""
res = []
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fsid=fsid, conn=self.conn)
status, r_set = self.conn.execute_2darray(sql)
@ -313,7 +331,8 @@ class UserMappingView(PGChildNodeView):
fsid: Foreign server ID
umid: User mapping ID
"""
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
conn=self.conn, umid=umid)
status, r_set = self.conn.execute_2darray(sql)
@ -336,7 +355,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition
def properties(self, gid, sid, did, fid, fsid, umid):
"""
This function will show the properties of the selected user mapping node.
This function will show the properties of the
selected user mapping node.
Args:
gid: Server Group ID
@ -347,7 +367,8 @@ class UserMappingView(PGChildNodeView):
umid: User mapping ID
"""
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
umid=umid, conn=self.conn)
status, res = self.conn.execute_dict(sql)
@ -400,7 +421,8 @@ class UserMappingView(PGChildNodeView):
)
try:
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fserid=fsid, conn=self.conn)
status, res1 = self.conn.execute_dict(sql)
@ -423,7 +445,8 @@ class UserMappingView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fsid=fsid, data=data,
conn=self.conn)
status, r_set = self.conn.execute_dict(sql)
@ -522,7 +545,8 @@ class UserMappingView(PGChildNodeView):
)
)
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
umid=umid, conn=self.conn)
status, res = self.conn.execute_dict(sql)
if not status:
@ -566,7 +590,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition
def msql(self, gid, sid, did, fid, fsid, umid=None):
"""
This function is used to return modified SQL for the selected user mapping node.
This function is used to return modified SQL for the
selected user mapping node.
Args:
gid: Server Group ID
@ -593,8 +618,7 @@ class UserMappingView(PGChildNodeView):
return make_json_response(
data=sql,
status=200
)
status=200)
except Exception as e:
return internal_server_error(errormsg=str(e))
@ -617,7 +641,8 @@ class UserMappingView(PGChildNodeView):
]
if umid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
umid=umid, conn=self.conn)
status, res = self.conn.execute_dict(sql)
if not status:
@ -634,7 +659,8 @@ class UserMappingView(PGChildNodeView):
)
old_data = res['rows'][0]
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fserid=fsid, conn=self.conn)
status, res1 = self.conn.execute_dict(sql)
if not status:
@ -646,25 +672,35 @@ class UserMappingView(PGChildNodeView):
if arg not in data:
data[arg] = old_data[arg]
# Allow user to set the blank value in fdwvalue field in option model
# Allow user to set the blank value in fdwvalue
# field in option model
is_valid_added_options = is_valid_changed_options = False
if 'umoptions' in data and 'added' in data['umoptions']:
is_valid_added_options, data['umoptions']['added'] = validate_options(
data['umoptions']['added'], 'umoption', 'umvalue'
)
is_valid_added_options, data['umoptions']['added'] =\
validate_options(
data['umoptions']['added'],
'umoption',
'umvalue')
if 'umoptions' in data and 'changed' in data['umoptions']:
is_valid_changed_options, data['umoptions']['changed'] = validate_options(
data['umoptions']['changed'], 'umoption', 'umvalue'
)
is_valid_changed_options, data['umoptions']['changed'] =\
validate_options(
data['umoptions']['changed'],
'umoption',
'umvalue')
sql = render_template("/".join([self.template_path, 'update.sql']),
data=data, o_data=old_data,
is_valid_added_options=is_valid_added_options,
is_valid_changed_options=is_valid_changed_options,
fdwdata=fdw_data, conn=self.conn)
sql = render_template(
"/".join([self.template_path, 'update.sql']),
data=data,
o_data=old_data,
is_valid_added_options=is_valid_added_options,
is_valid_changed_options=is_valid_changed_options,
fdwdata=fdw_data,
conn=self.conn
)
return sql, data['name'] if 'name' in data else old_data['name']
else:
sql = render_template("/".join([self.template_path, 'properties.sql']),
sql = render_template("/".join([self.template_path,
'properties.sql']),
fserid=fsid, conn=self.conn)
status, res = self.conn.execute_dict(sql)
if not status:
@ -687,7 +723,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition
def sql(self, gid, sid, did, fid, fsid, umid):
"""
This function will generate sql to show it in sql pane for the selected user mapping node.
This function will generate sql to show it in sql pane for
the selected user mapping node.
Args:
gid: Server Group ID

View File

@ -16,8 +16,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
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.tests\
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator
@ -68,8 +68,7 @@ class UserMappingAddTestCase(BaseTestGenerator):
if not fsrv_response:
raise Exception("Could not find FSRV.")
db_user = self.server["username"]
data = {
"name": db_user,
data = {"name": db_user,
"um_options": [],
"umoptions": [
{
@ -80,8 +79,7 @@ class UserMappingAddTestCase(BaseTestGenerator):
"umoption": "password",
"umvalue": self.server["db_password"]
}
]
}
]}
response = self.tester.post(
self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(

View File

@ -15,8 +15,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
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.tests \
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator

View File

@ -15,8 +15,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
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.tests \
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator
@ -70,8 +70,7 @@ class UserMappingGetTestCase(BaseTestGenerator):
raise Exception("Could not find FSRV.")
response = self.tester.get(self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(
self.db_id) +
'/' + str(self.fdw_id) + '/' + str(
self.db_id) + '/' + str(self.fdw_id) + '/' + str(
self.fsrv_id) + '/' + str(
self.um_id), content_type='html/json')
self.assertEquals(response.status_code, 200)

View File

@ -16,8 +16,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils
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.tests \
import utils as fdw_utils
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
from pgadmin.utils.route import BaseTestGenerator
@ -65,7 +65,8 @@ class UserMappingPutTestCase(BaseTestGenerator):
self.fdw_name)
if not fdw_response:
raise Exception("Could not find FDW.")
fsrv_response = fsrv_utils.verify_fsrv(self.server, self.db_name,
fsrv_response = fsrv_utils.verify_fsrv(self.server,
self.db_name,
self.fsrv_name)
if not fsrv_response:
raise Exception("Could not find FSRV.")

View File

@ -39,7 +39,11 @@ def create_user_mapping(server, db_name, fsrv_name):
connection.set_isolation_level(0)
pg_cursor = connection.cursor()
query = "CREATE USER MAPPING FOR %s SERVER %s OPTIONS" \
" (user '%s', password '%s')" % (server['username'], fsrv_name, server['username'], server['db_password'])
" (user '%s', password '%s')" % (server['username'],
fsrv_name,
server['username'],
server['db_password']
)
pg_cursor.execute(query)
connection.set_isolation_level(old_isolation_level)
connection.commit()

View File

@ -21,11 +21,9 @@ from . import utils as fdw_utils
class FDWDDeleteTestCase(BaseTestGenerator):
"""This class will delete foreign data wrappers under test database."""
scenarios = [
# Fetching default URL for foreign_data_wrapper node.
('Check FDW Node',
dict(url='/browser/foreign_data_wrapper/obj/'))
]
scenarios = [ # Fetching default URL for foreign_data_wrapper node.
('Check FDW Node',
dict(url='/browser/foreign_data_wrapper/obj/'))]
def setUp(self):
""" This function will create extension and foreign data wrapper."""
@ -51,11 +49,12 @@ class FDWDDeleteTestCase(BaseTestGenerator):
self.fdw_name)
if not fdw_response:
raise Exception("Could not find FDW.")
delete_response = self.tester.delete(
self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' +
str(self.db_id) + '/' + str(self.fdw_id),
follow_redirects=True)
delete_response = self.tester.delete(self.url +
str(utils.SERVER_GROUP) +
'/' + str(self.server_id) + '/' +
str(self.db_id) +
'/' + str(self.fdw_id),
follow_redirects=True)
self.assertEquals(delete_response.status_code, 200)
def tearDown(self):