pgadmin4/web/pgadmin/tools/erd/tests/test_close.py
2024-01-01 14:13:48 +05:30

57 lines
2.2 KiB
Python

##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2024, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import uuid
import secrets
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils import test_utils as utils
from regression import parent_node_dict
from regression.test_setup import config_data
from pgadmin.browser.server_groups.servers.databases.tests import utils as \
database_utils
class ERDClose(BaseTestGenerator):
def setUp(self):
self.db_name = "erdtestdb_{0}".format(str(uuid.uuid4())[1:8])
self.sid = parent_node_dict["server"][-1]["server_id"]
self.did = utils.create_database(self.server, self.db_name)
self.sgid = config_data["server_group"]
def runTest(self):
db_con = database_utils.connect_database(self,
self.sgid,
self.sid,
self.did)
if not db_con["info"] == "Database connected.":
raise Exception("Could not connect to database to add the schema.")
trans_id = secrets.choice(range(1, 9999999))
url = '/erd/initialize/{trans_id}/{sgid}/{sid}/{did}'.format(
trans_id=trans_id, sgid=self.sgid, sid=self.sid, did=self.did)
response = self.tester.post(url)
self.assertEqual(response.status_code, 200)
url = '/erd/close/{trans_id}/{sgid}/{sid}/{did}'.format(
trans_id=trans_id, sgid=self.sgid, sid=self.sid, did=self.did)
response = self.tester.delete(url)
self.assertEqual(response.status_code, 200)
def tearDown(self):
connection = utils.get_db_connection(self.server['db'],
self.server['username'],
self.server['db_password'],
self.server['host'],
self.server['port'])
utils.drop_database(connection, self.db_name)