Test suite enhancements:

1. The user will specify the tablespace path in test_config.json.in
2.  If tablespace path not found, skip the test cases for that server(Only tablespace test cases)
3.  Add the skipped test summary in the test result. (Now it's showing on console + in log file, but need to update in a final enhanced test summary report. Which is research point we will work on that after finishing all nodes API test cases)
4.  Removed the test_ prefix from the values in the config files.
5. Add tablespace and roles tests
This commit is contained in:
Navnath Gadakh
2016-08-09 16:05:40 +01:00
committed by Dave Page
parent 2b13d55016
commit 81e2bc1e80
34 changed files with 1685 additions and 625 deletions

View File

@@ -0,0 +1,16 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
from pgadmin.utils.route import BaseTestGenerator
class TblspaceGeneratorTestCase(BaseTestGenerator):
def runTest(self):
return

View File

@@ -0,0 +1,55 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
from pgadmin.utils.route import BaseTestGenerator
from regression import test_utils as utils
from pgadmin.browser.server_groups.servers.tests import utils as server_utils
from . import utils as tablespace_utils
class TableSpaceAddTestCase(BaseTestGenerator):
"""This class will add tablespace node under server"""
scenarios = [
# Fetching default URL for tablespace node.
('Check Tablespace Node', dict(url='/browser/tablespace/obj/'))
]
@classmethod
def setUpClass(cls):
"""
This function used to add the sever
:return: None
"""
# Add the server
server_utils.add_server(cls.tester)
# Connect to server
cls.server_connect_response, cls.server_group, cls.server_ids = \
server_utils.connect_server(cls.tester)
if len(cls.server_connect_response) == 0:
raise Exception("No Server(s) connected to add the roles!!!")
def runTest(self):
"""This function test the add tablespace scenario"""
tablespace_status = tablespace_utils.add_table_space(
self.tester, self.server_connect_response, self.server_group,
self.server_ids)
@classmethod
def tearDownClass(cls):
"""This function deletes the tablespaces,server and parent_id file"""
tablespace_utils.delete_table_space(cls.tester)
server_utils.delete_server(cls.tester)
utils.delete_parent_id_file()

View File

@@ -0,0 +1,58 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
from pgadmin.utils.route import BaseTestGenerator
from regression import test_utils as utils
from pgadmin.browser.server_groups.servers.tests import utils as server_utils
from . import utils as tablespace_utils
class TableSpaceDeleteTestCase(BaseTestGenerator):
"""This class has delete table space scenario"""
scenarios = [
# Fetching default URL for tablespace node.
('Check Tablespace Node', dict(url='/browser/tablespace/obj/'))
]
@classmethod
def setUpClass(cls):
"""
This function used to add the sever
:return: None
"""
# Add the server
server_utils.add_server(cls.tester)
# Connect to server
cls.server_connect_response, cls.server_group, cls.server_ids = \
server_utils.connect_server(cls.tester)
if len(cls.server_connect_response) == 0:
raise Exception("No Server(s) connected to add the roles!!!")
# Add tablespace
tablespace_utils.add_table_space(cls.tester,
cls.server_connect_response,
cls.server_group, cls.server_ids)
def runTest(self):
"""This function tests the delete table space scenario"""
tablespace_utils.delete_table_space(self.tester)
@classmethod
def tearDownClass(cls):
"""This function deletes the server and parent id file"""
server_utils.delete_server(cls.tester)
utils.delete_parent_id_file()

View File

@@ -0,0 +1,78 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
from pgadmin.utils.route import BaseTestGenerator
from regression import test_utils as utils
from pgadmin.browser.server_groups.servers.tests import utils as server_utils
from . import utils as tablespace_utils
class TablespaceGetTestCase(BaseTestGenerator):
"""This class tests the get table space scenario"""
scenarios = [
# Fetching default URL for roles node.
('Check Tablespace Node', dict(url='/browser/tablespace/obj/'))
]
@classmethod
def setUpClass(cls):
"""
This function used to add the sever
:return: None
"""
# Add the server
server_utils.add_server(cls.tester)
# Connect to server
cls.server_connect_response, cls.server_group, cls.server_ids = \
server_utils.connect_server(cls.tester)
if len(cls.server_connect_response) == 0:
raise Exception("No Server(s) connected to add the roles!!!")
# Add tablespace
tablespace_utils.add_table_space(cls.tester,
cls.server_connect_response,
cls.server_group, cls.server_ids)
def runTest(self):
"""This function test the get table space scenario"""
tablespace_ids_dict = None
all_id = utils.get_ids()
server_ids = all_id["sid"]
if "tsid" in all_id and all_id["tsid"]:
tablespace_ids_dict = all_id["tsid"][0]
if tablespace_ids_dict:
for server_id in server_ids:
tablespace_id = tablespace_ids_dict[int(server_id)]
server_response = server_utils.verify_server(self.tester,
utils.SERVER_GROUP,
server_id)
if server_response['data']['connected']:
tablespace_utils.verify_table_space(
self.tester, utils.SERVER_GROUP, server_id, tablespace_id)
response = self.tester.get(
self.url + str(utils.SERVER_GROUP) + '/' +
str(server_id) + '/' + str(
tablespace_id),
follow_redirects=True)
self.assertEquals(response.status_code, 200)
@classmethod
def tearDownClass(cls):
"""This function deletes the tablespaces,server and parent id file"""
tablespace_utils.delete_table_space(cls.tester)
server_utils.delete_server(cls.tester)
utils.delete_parent_id_file()

View File

@@ -0,0 +1,90 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
import json
from pgadmin.utils.route import BaseTestGenerator
from regression import test_utils as utils
from pgadmin.browser.server_groups.servers.tests import utils as server_utils
from test_setup import advanced_config_data
from . import utils as tablespace_utils
class TableSpaceUpdateTestCase(BaseTestGenerator):
"""This class has update tablespace scenario"""
scenarios = [
# Fetching default URL for roles node.
('Check Tablespace Node', dict(url='/browser/tablespace/obj/'))
]
@classmethod
def setUpClass(cls):
"""
This function used to add the sever
:return: None
"""
# Add the server
server_utils.add_server(cls.tester)
# Connect to server
cls.server_connect_response, cls.server_group, cls.server_ids = \
server_utils.connect_server(cls.tester)
if len(cls.server_connect_response) == 0:
raise Exception("No Server(s) connected to add the roles!!!")
# Add tablespace
tablespace_utils.add_table_space(cls.tester,
cls.server_connect_response,
cls.server_group, cls.server_ids)
def runTest(self):
"""This function tests the update tablespace data scenario"""
tablespace_ids_dict = None
all_id = utils.get_ids()
server_ids = all_id["sid"]
if "tsid" in all_id and all_id["tsid"]:
tablespace_ids_dict = all_id["tsid"][0]
if tablespace_ids_dict:
for server_id in server_ids:
tablespace_id = tablespace_ids_dict[int(server_id)]
tablespace_response = tablespace_utils.verify_table_space(
self.tester,
utils.SERVER_GROUP, server_id,
tablespace_id)
if len(tablespace_response) == 0:
raise Exception("No tablespace(s) to update!!!")
data = {
"description": advanced_config_data["tbspc_update_data"]
["comment"],
"table_space_id": tablespace_id
}
put_response = self.tester.put(
self.url + str(utils.SERVER_GROUP) + '/' +
str(server_id) + '/' + str(
tablespace_id),
data=json.dumps(data),
follow_redirects=True)
self.assertEquals(put_response.status_code, 200)
@classmethod
def tearDownClass(cls):
"""This function deletes the tablespaces,server and parent id file"""
tablespace_utils.delete_table_space(cls.tester)
server_utils.delete_server(cls.tester)
utils.delete_parent_id_file()

View File

@@ -0,0 +1,195 @@
# #################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
# ##################################################################
from __future__ import print_function
import json
import os
import pickle
import uuid
import sys
from regression.test_setup import pickle_path, config_data, \
advanced_config_data
from pgadmin.browser.server_groups.servers.tests import utils as server_utils
from regression import test_utils as utils
TABLE_SPACE_URL = '/browser/tablespace/obj/'
# Tablespace utility
def get_tablespace_data(server_connect):
"""This function returns the tablespace data from config file"""
adv_config_data = None
data = None
db_user = server_connect['data']['user']['name']
server_config_data = config_data['server_credentials']
# Get the config data of appropriate db user
for config_test_data in advanced_config_data['tablespc_credentials']:
if db_user == config_test_data['spc_user']:
# Add the tablespace path from server config
server_config = (item for item in server_config_data if
item["db_username"] == db_user).next()
if "tablespace_path" in server_config:
config_test_data['spc_location'] = server_config['tablespace_path']
adv_config_data = config_test_data
else:
config_test_data['spc_location'] = None
if adv_config_data is not None:
data = {
"name": str(uuid.uuid4())[1:8],
"seclabels": adv_config_data["spc_seclable"],
"spcacl": adv_config_data["spc_acl"],
"spclocation": adv_config_data["spc_location"],
"spcoptions": adv_config_data["spc_opts"],
"spcuser": adv_config_data["spc_user"]
}
return data
def write_tablespace_id(response_data):
"""
This function write the table space id to parent_id.pkl
:param response_data: create table space API response data
:type response_data: dict
:return: None
"""
table_space_id = response_data['node']['_id']
server_id = response_data['node']['_pid']
pickle_id_dict = utils.get_pickle_id_dict()
if os.path.isfile(pickle_path):
existing_server_id = open(pickle_path, 'rb')
tol_server_id = pickle.load(existing_server_id)
pickle_id_dict = tol_server_id
if 'tsid' in pickle_id_dict:
if pickle_id_dict['tsid']:
# Add the db_id as value in dict
pickle_id_dict["tsid"][0].update(
{server_id: table_space_id})
else:
# Create new dict with server_id and db_id
pickle_id_dict["tsid"].append(
{server_id: table_space_id})
db_output = open(pickle_path, 'wb')
pickle.dump(pickle_id_dict, db_output)
db_output.close()
def add_table_space(tester, server_connect_response, server_group, server_ids):
"""
This function is used to add the roles to server
:param tester: flask test client
:type tester: flask test client object
:param server_connect_response: server connect API response
:type server_connect_response: dict
:param server_group: server group
:type server_group: int
:param server_ids: list of server id
:type server_ids: list
:return: None
"""
total_servers_count = len(server_ids)
servers_without_tablespace_path = []
for server_connect, server_id in zip(server_connect_response,
server_ids):
tablespace_path = server_connect['tablespace_path']
# Skip the test case if tablespace_path does not exist
if not tablespace_path or tablespace_path is None:
file_name = os.path.basename(
sys._getframe().f_back.f_code.co_filename)
servers_without_tablespace_path.append(server_id)
if total_servers_count == len(servers_without_tablespace_path):
print("Skipping tablespaces test cases for the file <{0}>, "
"Tablespace path not configured for the servers: "
"{1}".format(file_name, server_ids), file=sys.stderr)
return
else:
print("Skipping tablespaces test case for the file <{0}>: "
"Tablespace path not configured for server: {1}".format(
file_name, server_id), file=sys.stderr)
continue
if server_connect['data']['connected']:
data = get_tablespace_data(server_connect)
response = tester.post(TABLE_SPACE_URL + str(server_group) + '/'
+ server_id + '/',
data=json.dumps(data),
content_type='html/json')
assert response.status_code == 200
response_data = json.loads(response.data.decode('utf-8'))
write_tablespace_id(response_data)
def verify_table_space(tester, server_group, server_id, tablespace_id):
"""
This function calls the GET API for role to verify
:param tester: test client
:type tester: flask test client object
:param server_group: server group id
:type server_group: int
:param server_id: server id
:type server_id: str
:param tablespace_id: table space id
:type tablespace_id: int
:return: dict/None
"""
srv_connect = server_utils.verify_server(tester, server_group, server_id)
if srv_connect['data']['connected']:
response = tester.get(
'{0}{1}/{2}/{3}'.format(TABLE_SPACE_URL, server_group, server_id,
tablespace_id),
content_type='html/json')
assert response.status_code == 200
temp_response = json.loads(response.data.decode('utf-8'))
return temp_response
else:
return None
def delete_table_space(tester):
"""
This function use to delete the existing tablespace in the servers
:param tester: flask test client
:type tester: flask test object
:return: None
"""
all_id = utils.get_ids()
server_ids = all_id["sid"]
if "tsid" in all_id and all_id["tsid"]:
tablespace_ids_dict = all_id["tsid"][0]
else:
tablespace_ids_dict = None
if tablespace_ids_dict is not None:
for server_id in server_ids:
tablespace_id = tablespace_ids_dict[int(server_id)]
role_response = verify_table_space(tester, utils.SERVER_GROUP,
server_id,
tablespace_id)
if len(role_response) == 0:
raise Exception("No tablespace(s) to delete!!!")
response = tester.delete(
TABLE_SPACE_URL + str(utils.SERVER_GROUP) + '/' +
str(server_id) + '/' + str(tablespace_id),
follow_redirects=True)
assert response.status_code == 200
delete_response_data = json.loads(response.data.decode('utf-8'))
assert delete_response_data['success'] == 1