2016-07-18 13:50:21 +00:00
|
|
|
# #################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
|
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
# ##################################################################
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pickle
|
2016-08-09 15:05:40 +00:00
|
|
|
from test_setup import config_data, pickle_path
|
2016-07-18 13:50:21 +00:00
|
|
|
|
2016-08-09 15:05:40 +00:00
|
|
|
|
|
|
|
SERVER_GROUP = config_data['server_group']
|
|
|
|
|
|
|
|
|
|
|
|
def get_pickle_id_dict():
|
|
|
|
"""This function returns the empty dict of server config data"""
|
|
|
|
|
|
|
|
pickle_id_dict = {
|
|
|
|
"sid": [], # server
|
|
|
|
"did": [], # database
|
|
|
|
"lrid": [], # role
|
|
|
|
"tsid": [], # tablespace
|
2016-08-16 11:54:02 +00:00
|
|
|
"scid": [], # schema
|
|
|
|
"tfnid": [], # trigger functions
|
2016-08-23 10:50:41 +00:00
|
|
|
"coid": [], # collation
|
|
|
|
"cid": [], # casts
|
|
|
|
"etid": [], # event_trigger
|
|
|
|
"eid": [], # extension
|
|
|
|
"fid": [], # FDW
|
|
|
|
"fsid": [], # FRS
|
|
|
|
"umid": [], # user_mapping
|
|
|
|
"seid": [] # sequence
|
2016-08-09 15:05:40 +00:00
|
|
|
}
|
|
|
|
return pickle_id_dict
|
2016-07-18 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_ids(url=pickle_path):
|
|
|
|
"""
|
|
|
|
This function read the parent node's id and return it
|
|
|
|
|
|
|
|
:param url: file path from which it will red the ids
|
|
|
|
:type url: str
|
|
|
|
:return: node ids
|
|
|
|
:rtype: dict
|
|
|
|
"""
|
|
|
|
|
|
|
|
output = open(url, 'rb')
|
|
|
|
ids = pickle.load(output)
|
|
|
|
output.close()
|
|
|
|
return ids
|
|
|
|
|
|
|
|
|
2016-08-16 11:54:02 +00:00
|
|
|
# def test_getnodes(tester=None):
|
|
|
|
# # Connect to server and database.
|
|
|
|
#
|
|
|
|
# if not tester:
|
|
|
|
# return None
|
|
|
|
#
|
|
|
|
# all_id = get_ids()
|
|
|
|
#
|
|
|
|
# server_ids = all_id["sid"]
|
|
|
|
# db_ids_dict = all_id["did"][0]
|
|
|
|
#
|
|
|
|
# db_con = []
|
|
|
|
# for server_id in server_ids:
|
|
|
|
# db_id = db_ids_dict[int(server_id)]
|
|
|
|
# db_con.append(verify_database(tester, SERVER_GROUP, server_id, db_id))
|
|
|
|
# return db_con
|
2016-07-18 13:50:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def login_tester_account(tester):
|
|
|
|
"""
|
|
|
|
This function login the test account using credentials mentioned in
|
|
|
|
config file
|
|
|
|
|
|
|
|
:param tester: test client
|
|
|
|
:type tester: flask test client object
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
email = \
|
2016-08-09 15:05:40 +00:00
|
|
|
config_data['pgAdmin4_login_credentials']['login_username']
|
2016-07-18 13:50:21 +00:00
|
|
|
password = \
|
2016-08-09 15:05:40 +00:00
|
|
|
config_data['pgAdmin4_login_credentials']['login_password']
|
2016-07-18 13:50:21 +00:00
|
|
|
response = tester.post('/login', data=dict(
|
|
|
|
email=email, password=password), follow_redirects=True)
|
|
|
|
|
|
|
|
|
|
|
|
def logout_tester_account(tester):
|
|
|
|
"""
|
|
|
|
This function logout the test account
|
|
|
|
|
|
|
|
:param tester: test client
|
|
|
|
:type tester: flask test client object
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
response = tester.get('/logout')
|
|
|
|
|
|
|
|
|
2016-08-09 15:05:40 +00:00
|
|
|
# Config data for parent_id.pkl
|
2016-07-18 13:50:21 +00:00
|
|
|
def get_config_data():
|
|
|
|
"""
|
|
|
|
This function get the data related to server group and database
|
|
|
|
like db name, host, port and username etc.
|
|
|
|
|
|
|
|
:return: server_group, db_data, pickle_id_dict
|
|
|
|
:rtype: server_group:dict, db_data:list, pickle_id_dict:dict
|
|
|
|
"""
|
|
|
|
|
|
|
|
db_data = []
|
2016-08-09 15:05:40 +00:00
|
|
|
pickle_id_dict = get_pickle_id_dict()
|
|
|
|
server_group = config_data['server_group']
|
2016-07-18 13:50:21 +00:00
|
|
|
|
2016-08-09 15:05:40 +00:00
|
|
|
for srv in config_data['server_credentials']:
|
|
|
|
data = {"name": srv['name'],
|
2016-07-18 13:50:21 +00:00
|
|
|
"comment": "",
|
2016-08-09 15:05:40 +00:00
|
|
|
"host": srv['host'],
|
|
|
|
"port": srv['db_port'],
|
|
|
|
"db": srv['maintenance_db'],
|
|
|
|
"username": srv['db_username'],
|
2016-07-18 13:50:21 +00:00
|
|
|
"role": "",
|
2016-08-09 15:05:40 +00:00
|
|
|
"sslmode": srv['sslmode']}
|
2016-07-18 13:50:21 +00:00
|
|
|
db_data.append(data)
|
|
|
|
return server_group, db_data, pickle_id_dict
|
|
|
|
|
|
|
|
|
|
|
|
def write_parent_id(response_data, pickle_id_dict):
|
|
|
|
"""
|
|
|
|
This function writes the server's details to file parent_id.pkl
|
|
|
|
|
|
|
|
:param response_data: server's data
|
|
|
|
:type response_data: list of dictionary
|
|
|
|
:param pickle_id_dict: contains ids of server,database,tables etc.
|
|
|
|
:type pickle_id_dict: dict
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
server_id = response_data['node']['_id']
|
|
|
|
if os.path.isfile(pickle_path):
|
|
|
|
existed_server_id = open(pickle_path, 'rb')
|
|
|
|
pickle_id_dict = pickle.load(existed_server_id)
|
|
|
|
|
2016-08-09 15:05:40 +00:00
|
|
|
pickle_id_dict["sid"].append(str(server_id))
|
2016-07-18 13:50:21 +00:00
|
|
|
output = open(pickle_path, 'wb')
|
|
|
|
pickle.dump(pickle_id_dict, output)
|
|
|
|
output.close()
|
|
|
|
|
|
|
|
|
|
|
|
def delete_parent_id_file():
|
|
|
|
"""
|
|
|
|
This function deletes the file parent_id.pkl which contains server and
|
|
|
|
database details
|
|
|
|
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
if os.path.isfile(pickle_path):
|
|
|
|
os.remove(pickle_path)
|
|
|
|
|