mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Windows compatibility fixes for the test suite.
This commit is contained in:
parent
155348d712
commit
c32bf7780e
@ -33,34 +33,37 @@ class TestVersionedTemplateLoader(BaseTestGenerator):
|
||||
def test_get_source_returns_a_template(self):
|
||||
expected_content = "Some SQL" \
|
||||
"\nsome more stuff on a new line\n"
|
||||
|
||||
# For cross platform we join the SQL path (This solves the slashes issue)
|
||||
sql_path = os.path.join("some_feature", "sql", "9.1_plus", "some_action.sql")
|
||||
content, filename, up_to_dateness = self.loader.get_source(None, "some_feature/sql/9.1_plus/some_action.sql")
|
||||
|
||||
self.assertEqual(expected_content, content)
|
||||
self.assertIn("some_feature/sql/9.1_plus/some_action.sql", filename)
|
||||
self.assertEqual(expected_content, str(content).replace("\r",""))
|
||||
self.assertIn(sql_path, filename)
|
||||
|
||||
def test_get_source_when_the_version_is_9_1_returns_9_1_template(self):
|
||||
expected_content = "Some SQL" \
|
||||
"\nsome more stuff on a new line\n"
|
||||
|
||||
# For cross platform we join the SQL path (This solves the slashes issue)
|
||||
sql_path = os.path.join("some_feature", "sql", "9.1_plus", "some_action.sql")
|
||||
content, filename, up_to_dateness = self.loader.get_source(None, "some_feature/sql/#90100#/some_action.sql")
|
||||
|
||||
self.assertEqual(expected_content, content)
|
||||
self.assertIn("some_feature/sql/9.1_plus/some_action.sql", filename)
|
||||
self.assertEqual(expected_content, str(content).replace("\r",""))
|
||||
self.assertIn(sql_path, filename)
|
||||
|
||||
def test_get_source_when_the_version_is_9_3_and_there_are_templates_for_9_2_and_9_1_returns_9_2_template(self):
|
||||
|
||||
# For cross platform we join the SQL path (This solves the slashes issue)
|
||||
sql_path = os.path.join("some_feature", "sql", "9.2_plus", "some_action.sql")
|
||||
content, filename, up_to_dateness = self.loader.get_source(None, "some_feature/sql/#90300#/some_action.sql")
|
||||
|
||||
self.assertEqual("Some 9.2 SQL", content)
|
||||
self.assertIn("some_feature/sql/9.2_plus/some_action.sql", filename)
|
||||
self.assertEqual("Some 9.2 SQL", str(content).replace("\r",""))
|
||||
self.assertIn(sql_path, filename)
|
||||
|
||||
def test_get_source_when_the_version_is_9_0_and_there_are_templates_for_9_1_and_9_2_returns_default_template(self):
|
||||
|
||||
# For cross platform we join the SQL path (This solves the slashes issue)
|
||||
sql_path = os.path.join("some_feature", "sql", "default", "some_action_with_default.sql")
|
||||
content, filename, up_to_dateness = self.loader.get_source(None, "some_feature/sql/#90000#/some_action_with_default.sql")
|
||||
|
||||
self.assertEqual("Some default SQL", content)
|
||||
self.assertIn("some_feature/sql/default/some_action_with_default.sql", filename)
|
||||
self.assertEqual("Some default SQL", str(content).replace("\r",""))
|
||||
self.assertIn(sql_path, filename)
|
||||
|
||||
def test_raise_not_found_exception_when_postgres_version_less_than_all_available_sql_templates(self):
|
||||
|
||||
|
@ -6,17 +6,15 @@
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import signal
|
||||
|
||||
import random
|
||||
|
||||
|
||||
class AppStarter:
|
||||
"""
|
||||
Helper for starting the full pgadmin4 app and loading the page via selenium
|
||||
""" Helper for starting the full pgadmin4 app and loading the page via
|
||||
selenium
|
||||
"""
|
||||
|
||||
def __init__(self, driver, app_config):
|
||||
@ -24,23 +22,35 @@ class AppStarter:
|
||||
self.app_config = app_config
|
||||
|
||||
def start_app(self):
|
||||
""" This function start the subprocess to start pgAdmin app """
|
||||
random_server_port = str(random.randint(10000, 65535))
|
||||
env = {
|
||||
"PGADMIN_PORT": random_server_port,
|
||||
"SQLITE_PATH": self.app_config.TEST_SQLITE_PATH
|
||||
}
|
||||
"SQLITE_PATH": str(self.app_config.TEST_SQLITE_PATH)
|
||||
}
|
||||
env.update(os.environ)
|
||||
|
||||
self.pgadmin_process = subprocess.Popen(["python", "pgAdmin4.py"],
|
||||
shell=False,
|
||||
preexec_fn=os.setsid,
|
||||
stderr=open(os.devnull, 'w'),
|
||||
env=env)
|
||||
# Add OS check for pass value for 'preexec_fn'
|
||||
self.pgadmin_process = subprocess.Popen(
|
||||
["python", "pgAdmin4.py"],
|
||||
shell=False,
|
||||
preexec_fn=None if os.name == 'nt' else os.setsid,
|
||||
stderr=open(os.devnull, 'w'),
|
||||
env=env
|
||||
)
|
||||
|
||||
self.driver.set_window_size(1024, 1024)
|
||||
print("opening browser")
|
||||
self.driver.get("http://" + self.app_config.DEFAULT_SERVER + ":" + random_server_port)
|
||||
self.driver.get(
|
||||
"http://" + self.app_config.DEFAULT_SERVER + ":" +
|
||||
random_server_port)
|
||||
|
||||
def stop_app(self):
|
||||
""" This function stop the started app by killing process """
|
||||
self.driver.quit()
|
||||
os.killpg(os.getpgid(self.pgadmin_process.pid), signal.SIGTERM)
|
||||
# os.killpg supported in Mac and Unix as this function not supported in
|
||||
# Windows
|
||||
try:
|
||||
os.killpg(os.getpgid(self.pgadmin_process.pid), signal.SIGTERM)
|
||||
except AttributeError:
|
||||
# os.kill is supported by Windows
|
||||
os.kill(self.pgadmin_process.pid, signal.SIGTERM)
|
||||
|
@ -67,10 +67,10 @@ if pgadmin_credentials:
|
||||
for item in ['login_username', 'login_password']):
|
||||
pgadmin_credentials = pgadmin_credentials[
|
||||
'pgAdmin4_login_credentials']
|
||||
os.environ['PGADMIN_SETUP_EMAIL'] = pgadmin_credentials[
|
||||
'login_username']
|
||||
os.environ['PGADMIN_SETUP_PASSWORD'] = pgadmin_credentials[
|
||||
'login_password']
|
||||
os.environ['PGADMIN_SETUP_EMAIL'] = str(pgadmin_credentials[
|
||||
'login_username'])
|
||||
os.environ['PGADMIN_SETUP_PASSWORD'] = str(pgadmin_credentials[
|
||||
'login_password'])
|
||||
|
||||
# Execute the setup file
|
||||
exec (open("setup.py").read())
|
||||
|
Loading…
Reference in New Issue
Block a user