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
@@ -33,19 +33,21 @@ class ForeignDataWrapperModule(CollectionNodeModule):
""" """
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: Methods:
------- -------
* __init__(*args, **kwargs) * __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) * get_nodes(gid, sid, did)
- Method is used to generate the browser collection node. - Method is used to generate the browser collection node.
* script_load() * script_load()
- Load the module script for foreign data wrapper, when any of the database node is - Load the module script for foreign data wrapper,
initialized. when any of the database node is initialized.
""" """
NODE_TYPE = 'foreign_data_wrapper' NODE_TYPE = 'foreign_data_wrapper'
@@ -53,7 +55,8 @@ class ForeignDataWrapperModule(CollectionNodeModule):
def __init__(self, *args, **kwargs): 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:
*args: *args:
@@ -80,7 +83,8 @@ class ForeignDataWrapperModule(CollectionNodeModule):
@property @property
def script_load(self): 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. Returns: node type of the databse module.
""" """
@@ -89,8 +93,8 @@ class ForeignDataWrapperModule(CollectionNodeModule):
@property @property
def module_use_template_javascript(self): def module_use_template_javascript(self):
""" """
Returns whether Jinja2 template is used for generating the javascript Returns whether Jinja2 template is used for
module. generating the javascript module.
""" """
return False return False
@@ -102,14 +106,16 @@ class ForeignDataWrapperView(PGChildNodeView):
""" """
class ForeignDataWrapperView(PGChildNodeView) class ForeignDataWrapperView(PGChildNodeView)
A view class for foreign data wrapper node derived from PGChildNodeView. This class is A view class for foreign data wrapper node derived
responsible for all the stuff related to view like updating foreign data wrapper 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. node, showing properties, showing sql in sql pane.
Methods: Methods:
------- -------
* __init__(**kwargs) * __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() * check_precondition()
- This function will behave as a decorator which will checks - This function will behave as a decorator which will checks
@@ -117,14 +123,16 @@ class ForeignDataWrapperView(PGChildNodeView):
manager,conn & template_path properties to self manager,conn & template_path properties to self
* list(gid, sid, did) * 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) * nodes(gid, sid, did)
- 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
Here it will create all the foreign data wrapper node. collection. Here it will create all the foreign data wrapper node.
* properties(gid, sid, did, fid) * 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) * create(gid, sid, did)
- This function will create the new foreign data wrapper node - 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 - This function will delete the selected foreign data wrapper node
* update(gid, sid, did, fid) * 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) * 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) * get_sql(data, fid)
- This function will generate sql from model data - This function will generate sql from model data
* get_validators(gid, sid, did) * 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) * 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): * 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): * 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): * 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 node_type = blueprint.node_type
@@ -244,8 +259,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition @check_precondition
def nodes(self, gid, sid, did): def nodes(self, gid, sid, did):
""" """
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
Here it will create all the foreign data wrapper node. collection. Here it will create all the foreign data wrapper node.
Args: Args:
gid: Server Group ID gid: Server Group ID
@@ -302,12 +317,14 @@ class ForeignDataWrapperView(PGChildNodeView):
status=200 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 @check_precondition
def properties(self, gid, sid, did, fid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -315,7 +332,8 @@ class ForeignDataWrapperView(PGChildNodeView):
did: Database ID did: Database ID
fid: foreign data wrapper 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 fid=fid, conn=self.conn
) )
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
@@ -325,7 +343,8 @@ class ForeignDataWrapperView(PGChildNodeView):
if len(res['rows']) == 0: if len(res['rows']) == 0:
return gone( 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: if res['rows'][0]['fdwoptions'] is not None:
@@ -334,7 +353,9 @@ class ForeignDataWrapperView(PGChildNodeView):
'fdwoption', 'fdwvalue' '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) status, fdw_acl_res = self.conn.execute_dict(sql)
if not status: if not status:
return internal_server_error(errormsg=fdw_acl_res) return internal_server_error(errormsg=fdw_acl_res)
@@ -389,15 +410,18 @@ class ForeignDataWrapperView(PGChildNodeView):
) )
sql = render_template("/".join([self.template_path, 'create.sql']), 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 is_valid_options=is_valid_options
) )
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path,
fname=data['name'], conn=self.conn 'properties.sql']),
fname=data['name'],
conn=self.conn
) )
status, r_set = self.conn.execute_dict(sql) status, r_set = self.conn.execute_dict(sql)
@@ -420,7 +444,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition @check_precondition
def update(self, gid, sid, did, fid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -486,12 +511,15 @@ class ForeignDataWrapperView(PGChildNodeView):
'Error: Object not found.' 'Error: Object not found.'
), ),
info=gettext( 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 # drop foreign data wrapper node
sql = render_template("/".join([self.template_path, 'delete.sql']), sql = render_template("/".join([self.template_path,
name=name, cascade=cascade, 'delete.sql']),
name=name,
cascade=cascade,
conn=self.conn) conn=self.conn)
status, res = self.conn.execute_scalar(sql) status, res = self.conn.execute_scalar(sql)
if not status: if not status:
@@ -514,7 +542,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition @check_precondition
def msql(self, gid, sid, did, fid=None): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -551,7 +580,8 @@ class ForeignDataWrapperView(PGChildNodeView):
gid: Server Group ID gid: Server Group ID
sid: Server ID sid: Server ID
did: Database 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 fid: foreign data wrapper ID
""" """
required_args = [ required_args = [
@@ -559,8 +589,10 @@ class ForeignDataWrapperView(PGChildNodeView):
] ]
if fid is not None: if fid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path,
fid=fid, conn=self.conn 'properties.sql']),
fid=fid,
conn=self.conn
) )
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
if not status: if not status:
@@ -568,7 +600,8 @@ class ForeignDataWrapperView(PGChildNodeView):
if len(res['rows']) == 0: if len(res['rows']) == 0:
return gone( 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: if res['rows'][0]['fdwoptions'] is not None:
@@ -580,33 +613,49 @@ class ForeignDataWrapperView(PGChildNodeView):
for key in ['fdwacl']: for key in ['fdwacl']:
if key in data and data[key] is not None: if key in data and data[key] is not None:
if 'added' in data[key]: 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]: 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]: 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] old_data = res['rows'][0]
for arg in required_args: for arg in required_args:
if arg not in data: if arg not in data:
data[arg] = old_data[arg] 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 is_valid_added_options = is_valid_changed_options = False
if 'fdwoptions' in data and 'added' in data['fdwoptions']: if 'fdwoptions' in data and 'added' in data['fdwoptions']:
is_valid_added_options, data['fdwoptions']['added'] = validate_options( is_valid_added_options, data['fdwoptions']['added'] = \
data['fdwoptions']['added'], 'fdwoption', 'fdwvalue' validate_options(
) data['fdwoptions']['added'],
'fdwoption',
'fdwvalue')
if 'fdwoptions' in data and 'changed' in data['fdwoptions']: if 'fdwoptions' in data and 'changed' in data['fdwoptions']:
is_valid_changed_options, data['fdwoptions']['changed'] = validate_options( is_valid_changed_options, data['fdwoptions']['changed'] = \
data['fdwoptions']['changed'], 'fdwoption', 'fdwvalue' validate_options(
) data['fdwoptions']['changed'],
'fdwoption',
'fdwvalue')
sql = render_template("/".join([self.template_path, 'update.sql']), sql = render_template(
data=data, o_data=old_data, "/".join([self.template_path, 'update.sql']),
is_valid_added_options=is_valid_added_options, data=data,
is_valid_changed_options=is_valid_changed_options, o_data=old_data,
conn=self.conn 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'] return sql, data['name'] if 'name' in data else old_data['name']
else: else:
@@ -614,25 +663,27 @@ class ForeignDataWrapperView(PGChildNodeView):
if key in data and data[key] is not None: if key in data and data[key] is not None:
data[key] = parse_priv_to_db(data[key], ['U']) 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 is_valid_options = False
if 'fdwoptions' in data: if 'fdwoptions' in data:
is_valid_options, data['fdwoptions'] = validate_options( is_valid_options, data['fdwoptions'] = validate_options(
data['fdwoptions'], 'fdwoption', 'fdwvalue' 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, data=data, conn=self.conn,
is_valid_options=is_valid_options is_valid_options=is_valid_options
) )
return sql, data['name'] return sql, data['name']
@check_precondition @check_precondition
def sql(self, gid, sid, did, fid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -660,7 +711,8 @@ class ForeignDataWrapperView(PGChildNodeView):
if len(res['rows'][0]['fdwoptions']) > 0: if len(res['rows'][0]['fdwoptions']) > 0:
is_valid_options = True 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) status, fdw_acl_res = self.conn.execute_dict(sql)
if not status: if not status:
return internal_server_error(errormsg=fdw_acl_res) return internal_server_error(errormsg=fdw_acl_res)
@@ -674,7 +726,10 @@ class ForeignDataWrapperView(PGChildNodeView):
# To format privileges # To format privileges
if 'fdwacl' in res['rows'][0]: 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 = ''
sql = render_template("/".join([self.template_path, 'create.sql']), sql = render_template("/".join([self.template_path, 'create.sql']),
@@ -696,7 +751,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition @check_precondition
def get_validators(self, gid, sid, did): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -705,7 +761,8 @@ class ForeignDataWrapperView(PGChildNodeView):
""" """
res = [{'label': '', 'value': ''}] res = [{'label': '', 'value': ''}]
try: try:
sql = render_template("/".join([self.template_path, 'validators.sql']), sql = render_template("/".join([self.template_path,
'validators.sql']),
conn=self.conn) conn=self.conn)
status, r_set = self.conn.execute_2darray(sql) status, r_set = self.conn.execute_2darray(sql)
@@ -724,7 +781,8 @@ class ForeignDataWrapperView(PGChildNodeView):
@check_precondition @check_precondition
def get_handlers(self, gid, sid, did): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -733,7 +791,8 @@ class ForeignDataWrapperView(PGChildNodeView):
""" """
res = [{'label': '', 'value': ''}] res = [{'label': '', 'value': ''}]
try: try:
sql = render_template("/".join([self.template_path, 'handlers.sql']), sql = render_template("/".join([self.template_path,
'handlers.sql']),
conn=self.conn) conn=self.conn)
status, r_set = self.conn.execute_2darray(sql) status, r_set = self.conn.execute_2darray(sql)
@@ -33,19 +33,21 @@ class ForeignServerModule(CollectionNodeModule):
""" """
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: Methods:
------- -------
* __init__(*args, **kwargs) * __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) * get_nodes(gid, sid, did)
- Method is used to generate the browser collection node. - Method is used to generate the browser collection node.
* script_load(self) * script_load(self)
- Load the module script for foreign server, when any of the database node is - Load the module script for foreign server, when any of
initialized. the database node is initialized.
""" """
NODE_TYPE = 'foreign_server' NODE_TYPE = 'foreign_server'
@@ -53,7 +55,8 @@ class ForeignServerModule(CollectionNodeModule):
def __init__(self, *args, **kwargs): 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:
*args: *args:
@@ -80,7 +83,8 @@ class ForeignServerModule(CollectionNodeModule):
@property @property
def script_load(self): 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. Returns: node type of the server module.
""" """
@@ -102,9 +106,10 @@ class ForeignServerView(PGChildNodeView):
""" """
class ForeignServerView(PGChildNodeView) class ForeignServerView(PGChildNodeView)
A view class for foreign server node derived from PGChildNodeView. This class is A view class for foreign server node derived from PGChildNodeView.
responsible for all the stuff related to view like updating foreign server This class is responsible for all the stuff related to view like
node, showing properties, showing sql in sql pane. updating foreign server node, showing properties,
showing sql in sql pane.
Methods: Methods:
------- -------
@@ -121,17 +126,21 @@ class ForeignServerView(PGChildNodeView):
manager,conn & template_path properties to self manager,conn & template_path properties to self
* list(gid, sid, did, fid) * 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) * 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. Here it will create all the foreign server node.
* properties(gid, sid, did, fid, fsid) * 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) * 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) * create(gid, sid, did, fid)
- This function will create the new foreign server node - 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 - This function will delete the selected foreign server node
* msql(gid, sid, did, fid, fsid) * 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) * get_sql(data, fid, fsid)
- This function will generate sql from model data - This function will generate sql from model data
* sql(gid, sid, did, fid, fsid): * 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): * 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): * 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 node_type = blueprint.node_type
@@ -226,7 +239,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition @check_precondition
def list(self, gid, sid, did, fid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -250,7 +264,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition @check_precondition
def nodes(self, gid, sid, did, fid): 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. Here it will create all the foreign server node.
Args: Args:
@@ -320,7 +335,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition @check_precondition
def properties(self, gid, sid, did, fid, fsid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -347,7 +363,9 @@ class ForeignServerView(PGChildNodeView):
res['rows'][0]['fsrvoptions'], 'fsrvoption', 'fsrvvalue' 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) status, fs_rv_acl_res = self.conn.execute_dict(sql)
if not status: if not status:
@@ -397,7 +415,8 @@ class ForeignServerView(PGChildNodeView):
if 'fsrvacl' in data: if 'fsrvacl' in data:
data['fsrvacl'] = parse_priv_to_db(data['fsrvacl'], ['U']) 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) fdwid=fid, conn=self.conn)
status, res1 = self.conn.execute_dict(sql) status, res1 = self.conn.execute_dict(sql)
if not status: if not status:
@@ -419,7 +438,8 @@ class ForeignServerView(PGChildNodeView):
if not status: if not status:
return internal_server_error(errormsg=res) 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, data=data, fdwdata=fdw_data,
conn=self.conn) conn=self.conn)
status, r_set = self.conn.execute_dict(sql) status, r_set = self.conn.execute_dict(sql)
@@ -440,7 +460,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition @check_precondition
def update(self, gid, sid, did, fid, fsid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -541,7 +562,8 @@ class ForeignServerView(PGChildNodeView):
@check_precondition @check_precondition
def msql(self, gid, sid, did, fid, fsid=None): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -567,8 +589,7 @@ class ForeignServerView(PGChildNodeView):
return make_json_response( return make_json_response(
data=sql.strip('\n'), data=sql.strip('\n'),
status=200 status=200)
)
except Exception as e: except Exception as e:
return internal_server_error(errormsg=str(e)) return internal_server_error(errormsg=str(e))
@@ -591,7 +612,8 @@ class ForeignServerView(PGChildNodeView):
] ]
if fsid is not None: 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) fsid=fsid, conn=self.conn)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
if not status: if not status:
@@ -609,11 +631,20 @@ class ForeignServerView(PGChildNodeView):
for key in ['fsrvacl']: for key in ['fsrvacl']:
if key in data and data[key] is not None: if key in data and data[key] is not None:
if 'added' in data[key]: 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]: 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]: 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] old_data = res['rows'][0]
for arg in required_args: for arg in required_args:
@@ -622,22 +653,31 @@ class ForeignServerView(PGChildNodeView):
is_valid_added_options = is_valid_changed_options = False is_valid_added_options = is_valid_changed_options = False
if 'fsrvoptions' in data and 'added' in data['fsrvoptions']: if 'fsrvoptions' in data and 'added' in data['fsrvoptions']:
is_valid_added_options, data['fsrvoptions']['added'] = validate_options( is_valid_added_options, data['fsrvoptions']['added'] =\
data['fsrvoptions']['added'], 'fsrvoption', 'fsrvvalue' validate_options(
) data['fsrvoptions']['added'],
if 'fsrvoptions' in data and 'changed' in data['fsrvoptions']: 'fsrvoption',
is_valid_changed_options, data['fsrvoptions']['changed'] = validate_options( 'fsrvvalue')
data['fsrvoptions']['changed'], 'fsrvoption', 'fsrvvalue'
)
sql = render_template("/".join([self.template_path, 'update.sql']), if 'fsrvoptions' in data and 'changed' in data['fsrvoptions']:
data=data, o_data=old_data, is_valid_changed_options, data['fsrvoptions']['changed'] =\
is_valid_added_options=is_valid_added_options, validate_options(
is_valid_changed_options=is_valid_changed_options, data['fsrvoptions']['changed'],
conn=self.conn) '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'] return sql, data['name'] if 'name' in data else old_data['name']
else: else:
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path,
'properties.sql']),
fdwid=fid, conn=self.conn) fdwid=fid, conn=self.conn)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
if not status: if not status:
@@ -649,7 +689,6 @@ class ForeignServerView(PGChildNodeView):
if key in data and data[key] is not None: if key in data and data[key] is not None:
data[key] = parse_priv_to_db(data[key], ['U']) data[key] = parse_priv_to_db(data[key], ['U'])
is_valid_options = False is_valid_options = False
if 'fsrvoptions' in data: if 'fsrvoptions' in data:
is_valid_options, data['fsrvoptions'] = validate_options( is_valid_options, data['fsrvoptions'] = validate_options(
@@ -663,11 +702,11 @@ class ForeignServerView(PGChildNodeView):
sql += "\n" sql += "\n"
return sql, data['name'] return sql, data['name']
@check_precondition @check_precondition
def sql(self, gid, sid, did, fid, fsid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -696,7 +735,8 @@ class ForeignServerView(PGChildNodeView):
if len(res['rows'][0]['fsrvoptions']) > 0: if len(res['rows'][0]['fsrvoptions']) > 0:
is_valid_options = True 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) status, fs_rv_acl_res = self.conn.execute_dict(sql)
if not status: if not status:
return internal_server_error(errormsg=fs_rv_acl_res) return internal_server_error(errormsg=fs_rv_acl_res)
@@ -710,7 +750,10 @@ class ForeignServerView(PGChildNodeView):
# To format privileges # To format privileges
if 'fsrvacl' in res['rows'][0]: 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']), sql = render_template("/".join([self.template_path, 'properties.sql']),
fdwid=fid, conn=self.conn) fdwid=fid, conn=self.conn)
@@ -753,7 +796,8 @@ class ForeignServerView(PGChildNodeView):
dependents_result = self.get_dependents(self.conn, fsid) dependents_result = self.get_dependents(self.conn, fsid)
# Fetching dependents of foreign servers # 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) fsid=fsid)
status, result = self.conn.execute_dict(query) status, result = self.conn.execute_dict(query)
if not status: if not status:
@@ -14,8 +14,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests \ from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\
import utils as fdw_utils tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -94,8 +94,9 @@ class ForeignServerAddTestCase(BaseTestGenerator):
} }
response = self.tester.post( response = self.tester.post(
self.url + str(utils.SERVER_GROUP) + '/' + self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.db_id) + '/' str(self.server_id) + '/' + str(self.db_id) +
+ str(self.fdw_id) + '/', data=json.dumps(data), '/' + str(self.fdw_id) + '/',
data=json.dumps(data),
content_type='html/json') content_type='html/json')
self.assertEquals(response.status_code, 200) self.assertEquals(response.status_code, 200)
@@ -13,8 +13,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests \ from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\
import utils as fdw_utils tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -13,8 +13,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests\ from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\
import utils as fdw_utils tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -62,8 +62,8 @@ class ForeignServerGetTestCase(BaseTestGenerator):
raise Exception("Could not find FDW.") raise Exception("Could not find FDW.")
fsrv_response = self.tester.get( fsrv_response = self.tester.get(
self.url + str(utils.SERVER_GROUP) + '/' + self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.db_id) + '/' str(self.server_id) + '/' + str(self.db_id) +
+ str(self.fdw_id) + '/' + str(self.fsrv_id), '/' + str(self.fdw_id) + '/' + str(self.fsrv_id),
content_type='html/json') content_type='html/json')
self.assertEquals(fsrv_response.status_code, 200) self.assertEquals(fsrv_response.status_code, 200)
@@ -14,8 +14,8 @@ import uuid
from pgadmin.browser.server_groups.servers.databases.extensions.tests import \ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests\ from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\
import utils as fdw_utils tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -65,10 +65,8 @@ class ForeignServerPutTestCase(BaseTestGenerator):
self.fsrv_name) self.fsrv_name)
if not fsrv_response: if not fsrv_response:
raise Exception("Could not find FSRV.") raise Exception("Could not find FSRV.")
data = { data = {"description": "This is foreign server update comment",
"description": "This is foreign server update comment", "id": self.fsrv_id}
"id": self.fsrv_id
}
put_response = self.tester.put( put_response = self.tester.put(
self.url + str(utils.SERVER_GROUP) + '/' + self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.db_id) + str(self.server_id) + '/' + str(self.db_id) +
@@ -60,16 +60,16 @@ def create_fsrv(server, db_name, fsrv_name, fdw_name):
print(exception, file=sys.stderr) 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.""" """ This function will verify current foreign server."""
try: try:
connection = get_db_connection(db_name, connection = get_db_connection(db_name,
server['username'], server['username'],
server['db_password'], server['db_password'],
server['host'], server['host'],
server['port'], server['port'],
server['sslmode']) server['sslmode'])
pg_cursor = connection.cursor() pg_cursor = connection.cursor()
pg_cursor.execute( pg_cursor.execute(
@@ -33,22 +33,25 @@ class UserMappingModule(CollectionNodeModule):
""" """
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: Methods:
------- -------
* __init__(*args, **kwargs) * __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) * get_nodes(gid, sid, did, fid, fsid)
- Method is used to generate the browser collection node. - Method is used to generate the browser collection node.
* node_inode() * 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) * script_load(self)
- Load the module script for user mapping, when any of the foreign server node is - Load the module script for user mapping, when any of the
initialized. foreign server node is initialized.
""" """
NODE_TYPE = 'user_mapping' NODE_TYPE = 'user_mapping'
@@ -56,7 +59,8 @@ class UserMappingModule(CollectionNodeModule):
def __init__(self, *args, **kwargs): 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:
*args: *args:
@@ -94,7 +98,8 @@ class UserMappingModule(CollectionNodeModule):
@property @property
def script_load(self): 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. Returns: node type of the server module.
""" """
@@ -117,9 +122,10 @@ class UserMappingView(PGChildNodeView):
""" """
class UserMappingView(PGChildNodeView) class UserMappingView(PGChildNodeView)
A view class for user mapping node derived from PGChildNodeView. This class is A view class for user mapping node derived from PGChildNodeView.
responsible for all the stuff related to view like updating user mapping This class is responsible for all the stuff related to view like
node, showing properties, showing sql in sql pane. updating user mapping node, showing properties,
showing sql in sql pane.
Methods: Methods:
------- -------
@@ -136,17 +142,21 @@ class UserMappingView(PGChildNodeView):
manager,conn & template_path properties to self manager,conn & template_path properties to self
* list(gid, sid, did, fid, fsid) * 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) * 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. Here it will create all the user mapping node.
* properties(gid, sid, did, fid, fsid, umid) * 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) * 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) * create(gid, sid, did, fid, fsid)
- This function will create the new user mapping node - 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 - This function will delete the selected user mapping node
* msql(gid, sid, did, fid, fsid, umid) * 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) * get_sql(data, fid, fsid, umid)
- This function will generate sql from model data - This function will generate sql from model data
* sql(gid, sid, did, fid, fsid, umid): * 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): * 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): * 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 node_type = blueprint.node_type
@@ -242,7 +256,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition @check_precondition
def list(self, gid, sid, did, fid, fsid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -252,7 +267,8 @@ class UserMappingView(PGChildNodeView):
fsid: Foreign server ID 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) fsid=fsid, conn=self.conn)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
@@ -267,7 +283,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition @check_precondition
def nodes(self, gid, sid, did, fid, fsid): 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. Here it will create all the user mapping node.
Args: Args:
@@ -279,7 +296,8 @@ class UserMappingView(PGChildNodeView):
""" """
res = [] res = []
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path,
'properties.sql']),
fsid=fsid, conn=self.conn) fsid=fsid, conn=self.conn)
status, r_set = self.conn.execute_2darray(sql) status, r_set = self.conn.execute_2darray(sql)
@@ -313,7 +331,8 @@ class UserMappingView(PGChildNodeView):
fsid: Foreign server ID fsid: Foreign server ID
umid: User mapping 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) conn=self.conn, umid=umid)
status, r_set = self.conn.execute_2darray(sql) status, r_set = self.conn.execute_2darray(sql)
@@ -336,7 +355,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition @check_precondition
def properties(self, gid, sid, did, fid, fsid, umid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -347,7 +367,8 @@ class UserMappingView(PGChildNodeView):
umid: User mapping ID 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) umid=umid, conn=self.conn)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
@@ -400,7 +421,8 @@ class UserMappingView(PGChildNodeView):
) )
try: try:
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path,
'properties.sql']),
fserid=fsid, conn=self.conn) fserid=fsid, conn=self.conn)
status, res1 = self.conn.execute_dict(sql) status, res1 = self.conn.execute_dict(sql)
@@ -423,7 +445,8 @@ class UserMappingView(PGChildNodeView):
if not status: if not status:
return internal_server_error(errormsg=res) 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, fsid=fsid, data=data,
conn=self.conn) conn=self.conn)
status, r_set = self.conn.execute_dict(sql) 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) umid=umid, conn=self.conn)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
if not status: if not status:
@@ -566,7 +590,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition @check_precondition
def msql(self, gid, sid, did, fid, fsid, umid=None): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -593,8 +618,7 @@ class UserMappingView(PGChildNodeView):
return make_json_response( return make_json_response(
data=sql, data=sql,
status=200 status=200)
)
except Exception as e: except Exception as e:
return internal_server_error(errormsg=str(e)) return internal_server_error(errormsg=str(e))
@@ -617,7 +641,8 @@ class UserMappingView(PGChildNodeView):
] ]
if umid is not None: 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) umid=umid, conn=self.conn)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
if not status: if not status:
@@ -634,7 +659,8 @@ class UserMappingView(PGChildNodeView):
) )
old_data = res['rows'][0] 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) fserid=fsid, conn=self.conn)
status, res1 = self.conn.execute_dict(sql) status, res1 = self.conn.execute_dict(sql)
if not status: if not status:
@@ -646,25 +672,35 @@ class UserMappingView(PGChildNodeView):
if arg not in data: if arg not in data:
data[arg] = old_data[arg] 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 is_valid_added_options = is_valid_changed_options = False
if 'umoptions' in data and 'added' in data['umoptions']: if 'umoptions' in data and 'added' in data['umoptions']:
is_valid_added_options, data['umoptions']['added'] = validate_options( is_valid_added_options, data['umoptions']['added'] =\
data['umoptions']['added'], 'umoption', 'umvalue' validate_options(
) data['umoptions']['added'],
'umoption',
'umvalue')
if 'umoptions' in data and 'changed' in data['umoptions']: if 'umoptions' in data and 'changed' in data['umoptions']:
is_valid_changed_options, data['umoptions']['changed'] = validate_options( is_valid_changed_options, data['umoptions']['changed'] =\
data['umoptions']['changed'], 'umoption', 'umvalue' validate_options(
) data['umoptions']['changed'],
'umoption',
'umvalue')
sql = render_template("/".join([self.template_path, 'update.sql']), sql = render_template(
data=data, o_data=old_data, "/".join([self.template_path, 'update.sql']),
is_valid_added_options=is_valid_added_options, data=data,
is_valid_changed_options=is_valid_changed_options, o_data=old_data,
fdwdata=fdw_data, conn=self.conn) 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'] return sql, data['name'] if 'name' in data else old_data['name']
else: else:
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path,
'properties.sql']),
fserid=fsid, conn=self.conn) fserid=fsid, conn=self.conn)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
if not status: if not status:
@@ -687,7 +723,8 @@ class UserMappingView(PGChildNodeView):
@check_precondition @check_precondition
def sql(self, gid, sid, did, fid, fsid, umid): 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: Args:
gid: Server Group ID gid: Server Group ID
@@ -16,8 +16,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
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 foreign_servers.tests import utils as fsrv_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests\ from pgadmin.browser.server_groups.servers.databases.\
import utils as fdw_utils foreign_data_wrappers.tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -68,8 +68,7 @@ class UserMappingAddTestCase(BaseTestGenerator):
if not fsrv_response: if not fsrv_response:
raise Exception("Could not find FSRV.") raise Exception("Could not find FSRV.")
db_user = self.server["username"] db_user = self.server["username"]
data = { data = {"name": db_user,
"name": db_user,
"um_options": [], "um_options": [],
"umoptions": [ "umoptions": [
{ {
@@ -80,8 +79,7 @@ class UserMappingAddTestCase(BaseTestGenerator):
"umoption": "password", "umoption": "password",
"umvalue": self.server["db_password"] "umvalue": self.server["db_password"]
} }
] ]}
}
response = self.tester.post( response = self.tester.post(
self.url + str(utils.SERVER_GROUP) + '/' + self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str( str(self.server_id) + '/' + str(
@@ -15,8 +15,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
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 foreign_servers.tests import utils as fsrv_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests \ from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\
import utils as fdw_utils tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -15,8 +15,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
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 foreign_servers.tests import utils as fsrv_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests \ from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\
import utils as fdw_utils tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -70,8 +70,7 @@ class UserMappingGetTestCase(BaseTestGenerator):
raise Exception("Could not find FSRV.") raise Exception("Could not find FSRV.")
response = self.tester.get(self.url + str(utils.SERVER_GROUP) + '/' + response = self.tester.get(self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str( str(self.server_id) + '/' + str(
self.db_id) + self.db_id) + '/' + str(self.fdw_id) + '/' + str(
'/' + str(self.fdw_id) + '/' + str(
self.fsrv_id) + '/' + str( self.fsrv_id) + '/' + str(
self.um_id), content_type='html/json') self.um_id), content_type='html/json')
self.assertEquals(response.status_code, 200) self.assertEquals(response.status_code, 200)
@@ -16,8 +16,8 @@ from pgadmin.browser.server_groups.servers.databases.extensions.tests import \
utils as extension_utils utils as extension_utils
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 foreign_servers.tests import utils as fsrv_utils
from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.tests \ from pgadmin.browser.server_groups.servers.databases.foreign_data_wrappers.\
import utils as fdw_utils tests import utils as fdw_utils
from pgadmin.browser.server_groups.servers.databases.tests import \ from pgadmin.browser.server_groups.servers.databases.tests import \
utils as database_utils utils as database_utils
from pgadmin.utils.route import BaseTestGenerator from pgadmin.utils.route import BaseTestGenerator
@@ -65,7 +65,8 @@ class UserMappingPutTestCase(BaseTestGenerator):
self.fdw_name) self.fdw_name)
if not fdw_response: if not fdw_response:
raise Exception("Could not find FDW.") 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) self.fsrv_name)
if not fsrv_response: if not fsrv_response:
raise Exception("Could not find FSRV.") raise Exception("Could not find FSRV.")
@@ -39,7 +39,11 @@ def create_user_mapping(server, db_name, fsrv_name):
connection.set_isolation_level(0) connection.set_isolation_level(0)
pg_cursor = connection.cursor() pg_cursor = connection.cursor()
query = "CREATE USER MAPPING FOR %s SERVER %s OPTIONS" \ 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) pg_cursor.execute(query)
connection.set_isolation_level(old_isolation_level) connection.set_isolation_level(old_isolation_level)
connection.commit() connection.commit()
@@ -21,11 +21,9 @@ from . import utils as fdw_utils
class FDWDDeleteTestCase(BaseTestGenerator): class FDWDDeleteTestCase(BaseTestGenerator):
"""This class will delete foreign data wrappers under test database.""" """This class will delete foreign data wrappers under test database."""
scenarios = [ scenarios = [ # Fetching default URL for foreign_data_wrapper node.
# Fetching default URL for foreign_data_wrapper node. ('Check FDW Node',
('Check FDW Node', dict(url='/browser/foreign_data_wrapper/obj/'))]
dict(url='/browser/foreign_data_wrapper/obj/'))
]
def setUp(self): def setUp(self):
""" This function will create extension and foreign data wrapper.""" """ This function will create extension and foreign data wrapper."""
@@ -51,11 +49,12 @@ class FDWDDeleteTestCase(BaseTestGenerator):
self.fdw_name) self.fdw_name)
if not fdw_response: if not fdw_response:
raise Exception("Could not find FDW.") raise Exception("Could not find FDW.")
delete_response = self.tester.delete( delete_response = self.tester.delete(self.url +
self.url + str(utils.SERVER_GROUP) + '/' + str(utils.SERVER_GROUP) +
str(self.server_id) + '/' + '/' + str(self.server_id) + '/' +
str(self.db_id) + '/' + str(self.fdw_id), str(self.db_id) +
follow_redirects=True) '/' + str(self.fdw_id),
follow_redirects=True)
self.assertEquals(delete_response.status_code, 200) self.assertEquals(delete_response.status_code, 200)
def tearDown(self): def tearDown(self):