mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Add the ability to import and export server definitions from a config database. Fixes #3772
This commit is contained in:
8
web/pgadmin/setup/tests/__init__.py
Normal file
8
web/pgadmin/setup/tests/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
41
web/pgadmin/setup/tests/servers.json
Normal file
41
web/pgadmin/setup/tests/servers.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"Servers": {
|
||||
"1": {
|
||||
"Name": "Minimally Defined Server",
|
||||
"Group": "Server Group 1",
|
||||
"Port": 5432,
|
||||
"Username": "postgres",
|
||||
"Host": "localhost",
|
||||
"SSLMode": "prefer",
|
||||
"MaintenanceDB": "postgres"
|
||||
},
|
||||
"2": {
|
||||
"Name": "Fully Defined Server",
|
||||
"Group": "Server Group 2",
|
||||
"Host": "host.domain.com",
|
||||
"HostAddr": "192.168.1.2",
|
||||
"Port": 5432,
|
||||
"MaintenanceDB": "postgres",
|
||||
"Username": "postgres",
|
||||
"Role": "my_role_name",
|
||||
"SSLMode": "require",
|
||||
"Comment": "This server has every option configured in the JSON",
|
||||
"DBRestriction": "live_db test_db",
|
||||
"PassFile": "/path/to/pgpassfile",
|
||||
"SSLCert": "/path/to/sslcert.crt",
|
||||
"SSLKey": "/path/to/sslcert.key",
|
||||
"SSLRootCert": "/path/to/sslroot.crt",
|
||||
"SSLCrl": "/path/to/sslcrl.crl",
|
||||
"SSLCompression": 1,
|
||||
"BGColor": "#ff9900",
|
||||
"FGColor": "#000000",
|
||||
"Service": "postgresql-10",
|
||||
"Timeout": 60,
|
||||
"UseSSHTunnel": 1,
|
||||
"TunnelHost": "192.168.1.253",
|
||||
"TunnelPort": "22",
|
||||
"TunnelUsername": "username",
|
||||
"TunnelAuthentication": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
48
web/pgadmin/setup/tests/test_export_import_servers.py
Normal file
48
web/pgadmin/setup/tests/test_export_import_servers.py
Normal file
@@ -0,0 +1,48 @@
|
||||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
import os
|
||||
import json
|
||||
import tempfile
|
||||
|
||||
|
||||
class ImportExportServersTestCase(BaseTestGenerator):
|
||||
"""
|
||||
This class validates the import/export servers functionality
|
||||
"""
|
||||
|
||||
scenarios = [
|
||||
# Fetching the default url for server group node
|
||||
('Check Server Import/Export', dict())
|
||||
]
|
||||
|
||||
def runTest(self):
|
||||
path = os.path.dirname(__file__)
|
||||
setup = os.path.realpath(os.path.join(path, "../../../setup.py"))
|
||||
|
||||
# Load the servers
|
||||
os.system("python %s --load-servers %s 2> %s" %
|
||||
(setup, os.path.join(path, "servers.json"), os.devnull))
|
||||
|
||||
# And dump them again
|
||||
tf = tempfile.NamedTemporaryFile(delete=False)
|
||||
os.system("python %s --dump-servers %s 2> %s" %
|
||||
(setup, tf.name, os.devnull))
|
||||
|
||||
# Compare the JSON files, ignoring servers that exist in our
|
||||
# generated file but not the test config (they are likely
|
||||
# auto-discovered)
|
||||
src = json.loads(open(os.path.join(path, "servers.json")).read())
|
||||
tgt = json.loads(open(tf.name).read())
|
||||
|
||||
for server in src["Servers"]:
|
||||
a = json.dumps(src["Servers"][server], sort_keys=True)
|
||||
b = json.dumps(tgt["Servers"][server], sort_keys=True)
|
||||
self.assertTrue(a, b)
|
||||
Reference in New Issue
Block a user