mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-03 12:10:55 -06:00
Fixed and improve few API test cases.
This commit is contained in:
parent
c4a5f8d707
commit
cc239149ba
@ -1587,7 +1587,6 @@ class ServerNode(PGChildNodeView):
|
||||
server, 428, prompt_password, prompt_tunnel_password
|
||||
)
|
||||
|
||||
status = True
|
||||
try:
|
||||
status, errmsg = conn.connect(
|
||||
password=password,
|
||||
@ -1596,12 +1595,10 @@ class ServerNode(PGChildNodeView):
|
||||
server_types=ServerType.types()
|
||||
)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
return self.get_response_for_password(
|
||||
server, 401, True, True, getattr(e, 'message', str(e)))
|
||||
|
||||
if not status:
|
||||
|
||||
current_app.logger.error(
|
||||
"Could not connect to server(#{0}) - '{1}'.\nError: {2}"
|
||||
.format(server.id, server.name, errmsg)
|
||||
@ -2099,10 +2096,12 @@ class ServerNode(PGChildNodeView):
|
||||
"prompt_password": prompt_password,
|
||||
"allow_save_password":
|
||||
True if config.ALLOW_SAVE_PASSWORD and
|
||||
'allow_save_password' in session and
|
||||
session['allow_save_password'] else False,
|
||||
"allow_save_tunnel_password":
|
||||
True if config.ALLOW_SAVE_TUNNEL_PASSWORD and
|
||||
session['allow_save_password'] else False
|
||||
'allow_save_tunnel_password' in session and
|
||||
session['allow_save_tunnel_password'] else False
|
||||
}
|
||||
return make_json_response(
|
||||
success=0,
|
||||
@ -2118,6 +2117,7 @@ class ServerNode(PGChildNodeView):
|
||||
"prompt_password": True,
|
||||
"allow_save_password":
|
||||
True if config.ALLOW_SAVE_PASSWORD and
|
||||
'allow_save_password' in session and
|
||||
session['allow_save_password'] else False,
|
||||
}
|
||||
return make_json_response(
|
||||
|
@ -380,9 +380,10 @@ class LanguageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
if len(res['rows']) == 0:
|
||||
return False, gone(self._NOT_FOUND_LANG_INFORMATION)
|
||||
|
||||
res['rows'][0]['is_sys_obj'] = (
|
||||
res['rows'][0]['oid'] <= self._DATABASE_LAST_SYSTEM_OID or
|
||||
self.datistemplate)
|
||||
if isinstance(res['rows'], list):
|
||||
res['rows'][0]['is_sys_obj'] = (
|
||||
res['rows'][0]['oid'] <= self._DATABASE_LAST_SYSTEM_OID or
|
||||
self.datistemplate)
|
||||
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, self._ACL_SQL]),
|
||||
|
@ -29,7 +29,7 @@ class FTSConfiguraionAddTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for fts_configuration node.
|
||||
('Fetch fts_configuration Node URL',
|
||||
('Add FTS Configuration Node',
|
||||
dict(url='/browser/fts_configuration/obj/'))
|
||||
]
|
||||
|
||||
|
@ -25,7 +25,7 @@ class FTSConfDeleteTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for fts_configuration node.
|
||||
('Fetch FTS configuration Node URL',
|
||||
('Delete FTS Configuration Node',
|
||||
dict(url='/browser/fts_configuration/obj/'))
|
||||
]
|
||||
|
||||
|
@ -26,7 +26,7 @@ class FTSConfDeleteMultipleTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for fts_configuration node.
|
||||
('Fetch FTS configuration Node URL',
|
||||
('Delete Multiple FTS Configuration Node',
|
||||
dict(url='/browser/fts_configuration/obj/'))
|
||||
]
|
||||
|
||||
|
@ -27,7 +27,7 @@ class FTSConfGetTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for fts_configuration node.
|
||||
('Fetch FTS configuration Node URL',
|
||||
('Fetch FTS configuration Node',
|
||||
dict(url='/browser/fts_configuration/obj/'))
|
||||
]
|
||||
|
||||
|
@ -30,7 +30,7 @@ class FTSConfPutTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for fts_configuration node.
|
||||
('Fetch FTS configuration Node URL',
|
||||
('Update FTS Configuration Node',
|
||||
dict(url='/browser/fts_configuration/obj/'))
|
||||
]
|
||||
|
||||
|
@ -719,9 +719,9 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return internal_server_error(errormsg=res), ''
|
||||
elif len(res['rows']) == 0:
|
||||
return gone(_("Could not find the FTS Dictionary node."))
|
||||
return gone(_("Could not find the FTS Dictionary node.")), ''
|
||||
|
||||
old_data = res['rows'][0]
|
||||
self._check_template_name_and_schema_name(data, old_data)
|
||||
@ -734,7 +734,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
status, new_schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=new_schema)
|
||||
return internal_server_error(errormsg=new_schema), ''
|
||||
|
||||
# Replace schema oid with schema name
|
||||
new_data = data.copy()
|
||||
@ -748,7 +748,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
status, old_schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=old_schema)
|
||||
return internal_server_error(errormsg=old_schema), ''
|
||||
|
||||
# Replace old schema oid with old schema name
|
||||
old_data['schema'] = old_schema
|
||||
@ -769,7 +769,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=schema)
|
||||
return internal_server_error(errormsg=schema), ''
|
||||
|
||||
sql = self._get_sql_for_create(data, schema)
|
||||
return sql.strip('\n'), data['name']
|
||||
|
@ -13,14 +13,14 @@ FROM
|
||||
LEFT OUTER JOIN pg_catalog.pg_ts_template t ON t.oid=dict.dicttemplate
|
||||
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=dict.oid AND des.classoid='pg_ts_dict'::regclass)
|
||||
WHERE
|
||||
{% if scid %}
|
||||
{% if scid is defined %}
|
||||
dict.dictnamespace = {{scid}}::OID
|
||||
{% endif %}
|
||||
{% if name %}
|
||||
{% if scid %}AND {% endif %}dict.dictname = {{name|qtLiteral(conn)}}
|
||||
{% if name is defined %}
|
||||
{% if scid is defined %}AND {% endif %}dict.dictname = {{name|qtLiteral(conn)}}
|
||||
{% endif %}
|
||||
{% if dcid %}
|
||||
{% if scid %}AND {% else %}{% if name %}AND {% endif %}{% endif %}dict.oid = {{dcid}}::OID
|
||||
{% if dcid is defined %}
|
||||
{% if scid is defined %}AND {% else %}{% if name is defined %}AND {% endif %}{% endif %}dict.oid = {{dcid}}::OID
|
||||
{% endif %}
|
||||
ORDER BY
|
||||
dict.dictname
|
||||
|
@ -27,7 +27,7 @@ class FtsDictionaryAddTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS dictionary node.
|
||||
('Fetch FTS dictionary Node URL', dict(
|
||||
('Add FTS dictionary', dict(
|
||||
url='/browser/fts_dictionary/obj/'))
|
||||
]
|
||||
|
||||
|
@ -25,7 +25,7 @@ class FtsDictionaryDeleteTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS dictionary node.
|
||||
('Fetch FTS dictionary Node URL', dict(
|
||||
('Delete FTS dictionary', dict(
|
||||
url='/browser/fts_dictionary/obj/'))
|
||||
]
|
||||
|
||||
|
@ -26,7 +26,7 @@ class FtsDictionaryDeleteMultipleTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS dictionary node.
|
||||
('Fetch FTS dictionary Node URL', dict(
|
||||
('Delete Multiple FTS dictionary Node', dict(
|
||||
url='/browser/fts_dictionary/obj/'))
|
||||
]
|
||||
|
||||
|
@ -25,7 +25,7 @@ class FtsDictionaryGetTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS dictionary node.
|
||||
('Fetch FTS dictionary Node URL', dict(
|
||||
('Get FTS dictionary', dict(
|
||||
url='/browser/fts_dictionary/obj/'))
|
||||
]
|
||||
|
||||
|
@ -26,7 +26,7 @@ class FtsDictionaryPutTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS dictionary node.
|
||||
('Fetch FTS dictionary Node URL', dict(
|
||||
('Update FTS dictionary Node', dict(
|
||||
url='/browser/fts_dictionary/obj/'))
|
||||
]
|
||||
|
||||
@ -97,7 +97,7 @@ class FtsDictionaryPutTestCase(BaseTestGenerator):
|
||||
data=json.dumps(data),
|
||||
follow_redirects=True)
|
||||
|
||||
self.assertEqual(negative_put_response.status_code, 500)
|
||||
self.assertEqual(negative_put_response.status_code, 410)
|
||||
|
||||
def tearDown(self):
|
||||
"""This function delete the fts dictionaries and disconnect the test
|
||||
|
@ -26,7 +26,7 @@ class FtsParserAddTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS parser node.
|
||||
('Fetch FTS parser Node URL', dict(url='/browser/fts_parser/obj/'))
|
||||
('Add FTS Parser Node', dict(url='/browser/fts_parser/obj/'))
|
||||
]
|
||||
|
||||
def runTest(self):
|
||||
|
@ -25,7 +25,7 @@ class FtsParserDeleteTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS parser node.
|
||||
('Fetch FTS parser Node URL', dict(url='/browser/fts_parser/obj/'))
|
||||
('Delete FTS Parser Node', dict(url='/browser/fts_parser/obj/'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -26,7 +26,8 @@ class FtsParserDeleteMultipleTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS parser node.
|
||||
('Fetch FTS parser Node URL', dict(url='/browser/fts_parser/obj/'))
|
||||
('Delete Multiple FTS Parser Nodes',
|
||||
dict(url='/browser/fts_parser/obj/'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -25,7 +25,7 @@ class FtsParserGetTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS parser node.
|
||||
('Fetch FTS parser Node URL', dict(url='/browser/fts_parser/obj/'))
|
||||
('Fetch FTS parser Node', dict(url='/browser/fts_parser/obj/'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -26,7 +26,7 @@ class FtsParserPutTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS parser node.
|
||||
('Fetch FTS parser Node URL', dict(url='/browser/fts_parser/obj/'))
|
||||
('Update FTS Parser Node', dict(url='/browser/fts_parser/obj/'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -624,9 +624,9 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
status, res = self.conn.execute_dict(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return internal_server_error(errormsg=res), ''
|
||||
elif len(res['rows']) == 0:
|
||||
return gone(self.not_found_error_msg())
|
||||
return gone(self.not_found_error_msg()), ''
|
||||
|
||||
old_data = res['rows'][0]
|
||||
if 'schema' not in data:
|
||||
@ -641,7 +641,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
status, new_schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=new_schema)
|
||||
return internal_server_error(errormsg=new_schema), ''
|
||||
|
||||
# Replace schema oid with schema name
|
||||
new_data = data.copy()
|
||||
@ -650,7 +650,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
new_data)
|
||||
if error:
|
||||
print('ERROR INSIDE UPDATE:: {0}'.format(errmsg))
|
||||
return internal_server_error(errormsg=errmsg)
|
||||
return internal_server_error(errormsg=errmsg), ''
|
||||
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, self._UPDATE_SQL]),
|
||||
@ -669,7 +669,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=schema)
|
||||
return internal_server_error(errormsg=schema), ''
|
||||
|
||||
sql = self._get_sql_for_create(data, schema)
|
||||
return sql.strip('\n'), data['name']
|
||||
|
@ -15,14 +15,14 @@ ON
|
||||
AND des.classoid='pg_ts_template'::regclass
|
||||
)
|
||||
WHERE
|
||||
{% if scid %}
|
||||
{% if scid is defined %}
|
||||
tmpl.tmplnamespace = {{scid}}::OID
|
||||
{% endif %}
|
||||
{% if name %}
|
||||
{% if scid %}AND {% endif %}tmpl.tmplname = {{name|qtLiteral(conn)}}
|
||||
{% if name is defined %}
|
||||
{% if scid is defined %}AND {% endif %}tmpl.tmplname = {{name|qtLiteral(conn)}}
|
||||
{% endif %}
|
||||
{% if tid %}
|
||||
{% if name %}AND {% else %}{% if scid %}AND {% endif %}{% endif %}tmpl.oid = {{tid}}::OID
|
||||
{% if tid is defined %}
|
||||
{% if name is defined %}AND {% else %}{% if scid is defined %}AND {% endif %}{% endif %}tmpl.oid = {{tid}}::OID
|
||||
{% endif %}
|
||||
ORDER BY
|
||||
tmpl.tmplname
|
||||
|
@ -27,7 +27,7 @@ class FtsTemplateAddTestCase(BaseTestGenerator):
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS template node.
|
||||
(
|
||||
'Fetch FTS templates Node URL',
|
||||
'Add FTS templates Node',
|
||||
dict(url='/browser/fts_template/obj/'))
|
||||
]
|
||||
|
||||
|
@ -25,7 +25,7 @@ class FtsTemplateDeleteTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS template node.
|
||||
('Fetch FTS template Node URL', dict(url='/browser/fts_template/obj/'))
|
||||
('Delete FTS template Node', dict(url='/browser/fts_template/obj/'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -26,7 +26,8 @@ class FtsTemplateDeleteMultipleTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS template node.
|
||||
('Fetch FTS template Node URL', dict(url='/browser/fts_template/obj/'))
|
||||
('Delete Multiple FTS template Nodes',
|
||||
dict(url='/browser/fts_template/obj/'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -25,7 +25,7 @@ class FtsTemplateGetTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS template node.
|
||||
('Fetch FTS templates Node URL', dict(
|
||||
('Fetch FTS templates Node', dict(
|
||||
url='/browser/fts_template/obj/')
|
||||
)
|
||||
]
|
||||
|
@ -26,7 +26,8 @@ class FtsTemplatePutTestCase(BaseTestGenerator):
|
||||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS template node.
|
||||
('Fetch FTS template Node URL', dict(url='/browser/fts_template/obj/'))
|
||||
('Update FTS template Node',
|
||||
dict(url='/browser/fts_template/obj/'))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
@ -95,7 +96,7 @@ class FtsTemplatePutTestCase(BaseTestGenerator):
|
||||
data=json.dumps(data),
|
||||
follow_redirects=True)
|
||||
|
||||
self.assertEqual(negative_put_response.status_code, 500)
|
||||
self.assertEqual(negative_put_response.status_code, 410)
|
||||
|
||||
def tearDown(self):
|
||||
"""This function delete the fts_template and disconnect the test
|
||||
|
@ -54,23 +54,6 @@
|
||||
"status_code": 500
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Check if it throws an error when no event is selected while creating a trigger",
|
||||
"url": "/browser/trigger/obj/",
|
||||
"is_positive_test": true,
|
||||
"test_data": {
|
||||
"name": "PLACE_HOLDER",
|
||||
"is_row_trigger": true,
|
||||
"fires": "AFTER",
|
||||
"columns": [],
|
||||
"tfunction": "PLACE_HOLDER"
|
||||
},
|
||||
"mocking_required": false,
|
||||
"mock_data": {},
|
||||
"expected_data": {
|
||||
"status_code": 500
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Error while adding a trigger using wrong table",
|
||||
"url": "/browser/trigger/obj/",
|
||||
|
@ -589,7 +589,7 @@
|
||||
"manager": {
|
||||
"server_type": "pg",
|
||||
"password": "my_postgres",
|
||||
"sversion": 100000,
|
||||
"sversion": 150000,
|
||||
"connection_connect_return_value": "psycopg.OperationalError()"
|
||||
}
|
||||
},
|
||||
@ -630,7 +630,7 @@
|
||||
"manager": {
|
||||
"server_type": "pg",
|
||||
"password": "my_postgres",
|
||||
"sversion": 100000,
|
||||
"sversion": 150000,
|
||||
"connection_connect_return_value": "OperationalError()"
|
||||
}
|
||||
},
|
||||
@ -1118,7 +1118,7 @@
|
||||
"manager": {
|
||||
"server_type": "pg",
|
||||
"password": "my_postgres",
|
||||
"sversion": 100000,
|
||||
"sversion": 150000,
|
||||
"connection_execute_scalar_return_value": "(True, {'rows': []})"
|
||||
}
|
||||
},
|
||||
|
@ -96,4 +96,4 @@ class ServersSSHConnectTestCase(BaseTestGenerator):
|
||||
|
||||
response = self.connect_to_server(url, self.server)
|
||||
|
||||
self.assertEqual(response.status_code, 500)
|
||||
self.assertIn(response.status_code, [401, 428])
|
||||
|
@ -264,6 +264,9 @@ def properties(sid, did, node_id, node_type):
|
||||
|
||||
res_data, msg = get_data(sid, did, node_id, node_type, server_info)
|
||||
|
||||
if res_data is None and isinstance(msg, Response):
|
||||
return msg
|
||||
|
||||
return make_json_response(
|
||||
result=res_data,
|
||||
info=msg,
|
||||
@ -292,7 +295,7 @@ def get_data(sid, did, node_id, node_type, server_data):
|
||||
status, res = conn.execute_dict(sql)
|
||||
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
return None, internal_server_error(errormsg=res)
|
||||
node_types = res['rows']
|
||||
|
||||
def _append_rows(status, res, disp_type):
|
||||
|
Loading…
Reference in New Issue
Block a user