mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Code refactoring:
- Move the duplicate code for closing the background process dialog into 'test_gui_helper.py', - Simplify the logic by removing the duplicate steps to insert/update binary paths for each server type from 'test_utils.py'.
This commit is contained in:
committed by
Dave Page
parent
528ea88dec
commit
0f1651686b
@@ -13,6 +13,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
||||||
from regression.python_test_utils import test_utils
|
from regression.python_test_utils import test_utils
|
||||||
|
from regression.python_test_utils import test_gui_helper
|
||||||
|
|
||||||
|
|
||||||
class PGUtilitiesBackupFeatureTest(BaseFeatureTest):
|
class PGUtilitiesBackupFeatureTest(BaseFeatureTest):
|
||||||
@@ -138,31 +139,7 @@ class PGUtilitiesBackupFeatureTest(BaseFeatureTest):
|
|||||||
os.remove(backup_file)
|
os.remove(backup_file)
|
||||||
|
|
||||||
def after(self):
|
def after(self):
|
||||||
self._screenshot()
|
test_gui_helper.close_bgprocess_popup(self)
|
||||||
|
|
||||||
# In cases where backup div is not closed (sometime due to some error)
|
|
||||||
try:
|
|
||||||
if self.driver.find_element_by_css_selector(
|
|
||||||
".ajs-message.ajs-bg-bgprocess.ajs-visible > div > "
|
|
||||||
"div > div > i"):
|
|
||||||
self.driver.find_element_by_css_selector(
|
|
||||||
".ajs-message.ajs-bg-bgprocess.ajs-visible >div >div "
|
|
||||||
">div>i").click()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# In cases where restore div is not closed (sometime due to some error)
|
|
||||||
try:
|
|
||||||
if self.driver.find_element_by_xpath(
|
|
||||||
"//div[contains(text(), 'Process Watcher - "
|
|
||||||
"Restoring backup')]"):
|
|
||||||
self.driver.find_element_by_xpath(
|
|
||||||
"//div[div[div[div[contains(text(), 'Process Watcher "
|
|
||||||
"- Restoring backup')]]]]"
|
|
||||||
"/following-sibling::div/div/div").click()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.page.remove_server(self.server)
|
self.page.remove_server(self.server)
|
||||||
connection = test_utils.get_db_connection(
|
connection = test_utils.get_db_connection(
|
||||||
self.server['db'],
|
self.server['db'],
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import time
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
||||||
from regression.python_test_utils import test_utils
|
from regression.python_test_utils import test_utils
|
||||||
|
from regression.python_test_utils import test_gui_helper
|
||||||
|
|
||||||
|
|
||||||
class PGUtilitiesMaintenanceFeatureTest(BaseFeatureTest):
|
class PGUtilitiesMaintenanceFeatureTest(BaseFeatureTest):
|
||||||
@@ -98,29 +99,7 @@ class PGUtilitiesMaintenanceFeatureTest(BaseFeatureTest):
|
|||||||
"div.wcFloatingFocus div.fa-close").click()
|
"div.wcFloatingFocus div.fa-close").click()
|
||||||
|
|
||||||
def after(self):
|
def after(self):
|
||||||
# In cases where backup div is not closed
|
test_gui_helper.close_bgprocess_popup(self)
|
||||||
try:
|
|
||||||
if self.driver.find_element_by_css_selector(
|
|
||||||
".ajs-message.ajs-bg-bgprocess.ajs-visible"
|
|
||||||
" >div >div >div>i"):
|
|
||||||
self.driver.find_element_by_css_selector(
|
|
||||||
".ajs-message.ajs-bg-bgprocess.ajs-visible >div >div "
|
|
||||||
">div>i").click()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# In cases where restore div is not closed (sometime due to some error)
|
|
||||||
try:
|
|
||||||
if self.driver.find_element_by_xpath(
|
|
||||||
"//div[contains(text(), 'Process Watcher - "
|
|
||||||
"Restoring backup')]"):
|
|
||||||
self.driver.find_element_by_xpath(
|
|
||||||
"//div[div[div[div[contains(text(), 'Process Watcher "
|
|
||||||
"- Restoring backup')]]]]"
|
|
||||||
"/following-sibling::div/div/div").click()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.page.remove_server(self.server)
|
self.page.remove_server(self.server)
|
||||||
connection = test_utils.get_db_connection(
|
connection = test_utils.get_db_connection(
|
||||||
self.server['db'],
|
self.server['db'],
|
||||||
|
|||||||
38
web/regression/python_test_utils/test_gui_helper.py
Normal file
38
web/regression/python_test_utils/test_gui_helper.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
##########################################################################
|
||||||
|
#
|
||||||
|
# pgAdmin 4 - PostgreSQL Tools
|
||||||
|
#
|
||||||
|
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||||
|
# This software is released under the PostgreSQL Licence
|
||||||
|
#
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def close_bgprocess_popup(tester):
|
||||||
|
"""
|
||||||
|
Allow us to close the background process popup window
|
||||||
|
"""
|
||||||
|
tester._screenshot()
|
||||||
|
|
||||||
|
# In cases where backup div is not closed (sometime due to some error)
|
||||||
|
try:
|
||||||
|
if tester.driver.find_element_by_css_selector(
|
||||||
|
".ajs-message.ajs-bg-bgprocess.ajs-visible > div > "
|
||||||
|
"div > div > i"):
|
||||||
|
tester.driver.find_element_by_css_selector(
|
||||||
|
".ajs-message.ajs-bg-bgprocess.ajs-visible >div >div "
|
||||||
|
">div>i").click()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# In cases where restore div is not closed (sometime due to some error)
|
||||||
|
try:
|
||||||
|
if tester.driver.find_element_by_xpath(
|
||||||
|
"//div[contains(text(), 'Process Watcher - "
|
||||||
|
"Restoring backup')]"):
|
||||||
|
tester.driver.find_element_by_xpath(
|
||||||
|
"//div[div[div[div[contains(text(), 'Process Watcher "
|
||||||
|
"- Restoring backup')]]]]"
|
||||||
|
"/following-sibling::div/div/div").click()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
@@ -615,57 +615,28 @@ def get_db_server(sid):
|
|||||||
def set_preference(default_binary_path):
|
def set_preference(default_binary_path):
|
||||||
conn = sqlite3.connect(config.TEST_SQLITE_PATH)
|
conn = sqlite3.connect(config.TEST_SQLITE_PATH)
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
perf = Preferences.module('paths')
|
perf = Preferences.module('paths')
|
||||||
pg_path_pref = perf.preference('pg_bin_dir')
|
server_types = default_binary_path.keys()
|
||||||
|
|
||||||
user_pref = cur.execute(
|
for server in server_types:
|
||||||
'SELECT pid, uid FROM user_preferences where pid=%s' % pg_path_pref.pid
|
path_pref = perf.preference('{0}_bin_dir'.format(server))
|
||||||
)
|
user_pref = cur.execute(
|
||||||
user_pref = user_pref.fetchone()
|
'SELECT pid, uid FROM user_preferences '
|
||||||
|
'where pid=%s' % path_pref.pid
|
||||||
|
)
|
||||||
|
|
||||||
if user_pref:
|
user_pref_data = user_pref.fetchone()
|
||||||
cur.execute('UPDATE user_preferences SET value = ? WHERE pid = ?',
|
if user_pref_data:
|
||||||
(default_binary_path['pg'], pg_path_pref.pid))
|
cur.execute(
|
||||||
else:
|
'UPDATE user_preferences SET value = ? WHERE pid = ?',
|
||||||
pg_pref_details = (pg_path_pref.pid, 1,
|
(default_binary_path[server], path_pref.pid)
|
||||||
default_binary_path['pg'])
|
)
|
||||||
cur.execute('INSERT INTO user_preferences(pid, uid, value)'
|
else:
|
||||||
' VALUES (?,?,?)', pg_pref_details)
|
params = (path_pref.pid, 1, default_binary_path[server])
|
||||||
|
cur.execute(
|
||||||
ppas_path_pref = perf.preference('ppas_bin_dir')
|
'INSERT INTO user_preferences(pid, uid, value)'
|
||||||
|
' VALUES (?,?,?)', params
|
||||||
user_pref = cur.execute(
|
)
|
||||||
'SELECT pid, uid FROM user_preferences where pid=%s' %
|
|
||||||
ppas_path_pref.pid
|
|
||||||
)
|
|
||||||
user_pref = user_pref.fetchone()
|
|
||||||
|
|
||||||
if user_pref:
|
|
||||||
cur.execute('UPDATE user_preferences SET value = ? WHERE pid = ? ',
|
|
||||||
(default_binary_path['ppas'], ppas_path_pref.pid))
|
|
||||||
else:
|
|
||||||
ppas_pref_details = (ppas_path_pref.pid, 1,
|
|
||||||
default_binary_path['ppas'])
|
|
||||||
cur.execute('INSERT INTO user_preferences(pid, uid, value)'
|
|
||||||
' VALUES (?,?,?)', ppas_pref_details)
|
|
||||||
|
|
||||||
gpdb_path_pref = perf.preference('gpdb_bin_dir')
|
|
||||||
|
|
||||||
user_pref = cur.execute(
|
|
||||||
'SELECT pid, uid FROM user_preferences where pid=%s' %
|
|
||||||
gpdb_path_pref.pid
|
|
||||||
)
|
|
||||||
user_pref = user_pref.fetchone()
|
|
||||||
|
|
||||||
if user_pref:
|
|
||||||
cur.execute('UPDATE user_preferences SET value = ? WHERE pid = ? ',
|
|
||||||
(default_binary_path['gpdb'], gpdb_path_pref.pid))
|
|
||||||
else:
|
|
||||||
gpdb_pref_details = (gpdb_path_pref.pid, 1,
|
|
||||||
default_binary_path['gpdb'])
|
|
||||||
cur.execute('INSERT INTO user_preferences(pid, uid, value)'
|
|
||||||
' VALUES (?,?,?)', gpdb_pref_details)
|
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user