Skip to content

Commit

Permalink
Fixed some API test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-joshi committed Nov 15, 2023
1 parent 75a2d88 commit ea5422b
Show file tree
Hide file tree
Showing 30 changed files with 61 additions and 69 deletions.
6 changes: 4 additions & 2 deletions web/pgadmin/browser/server_groups/servers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,6 @@ def connect(self, gid, sid):
server, 428, prompt_password, prompt_tunnel_password
)

status = True
try:
status, errmsg = conn.connect(
password=password,
Expand Down Expand Up @@ -2099,10 +2098,12 @@ def get_response_for_password(self, server, status, prompt_password=False,
"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,
Expand All @@ -2118,6 +2119,7 @@ def get_response_for_password(self, server, status, prompt_password=False,
"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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,10 @@ def _fetch_properties(self, did, lid):
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]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,9 @@ def get_sql(self, gid, sid, did, scid, data, dcid=None):

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)
Expand All @@ -734,7 +734,7 @@ def get_sql(self, gid, sid, did, scid, data, dcid=None):

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()
Expand All @@ -748,7 +748,7 @@ def get_sql(self, gid, sid, did, scid, data, dcid=None):

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
Expand All @@ -769,7 +769,7 @@ def get_sql(self, gid, sid, did, scid, data, dcid=None):

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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down Expand Up @@ -97,7 +97,7 @@ def runTest(self):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,9 @@ def get_sql(self, gid, sid, did, scid, data, tid=None):

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:
Expand All @@ -641,7 +641,7 @@ def get_sql(self, gid, sid, did, scid, data, tid=None):

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()
Expand All @@ -650,7 +650,7 @@ def get_sql(self, gid, sid, did, scid, data, tid=None):
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]),
Expand All @@ -669,7 +669,7 @@ def get_sql(self, gid, sid, did, scid, data, tid=None):

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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -95,7 +96,7 @@ def runTest(self):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
Loading

0 comments on commit ea5422b

Please sign in to comment.