Windows compatibility fixes for the test suite.
parent
155348d712
commit
c32bf7780e
|
@ -33,34 +33,37 @@ class TestVersionedTemplateLoader(BaseTestGenerator):
|
||||||
def test_get_source_returns_a_template(self):
|
def test_get_source_returns_a_template(self):
|
||||||
expected_content = "Some SQL" \
|
expected_content = "Some SQL" \
|
||||||
"\nsome more stuff on a new line\n"
|
"\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")
|
content, filename, up_to_dateness = self.loader.get_source(None, "some_feature/sql/9.1_plus/some_action.sql")
|
||||||
|
self.assertEqual(expected_content, str(content).replace("\r",""))
|
||||||
self.assertEqual(expected_content, content)
|
self.assertIn(sql_path, filename)
|
||||||
self.assertIn("some_feature/sql/9.1_plus/some_action.sql", filename)
|
|
||||||
|
|
||||||
def test_get_source_when_the_version_is_9_1_returns_9_1_template(self):
|
def test_get_source_when_the_version_is_9_1_returns_9_1_template(self):
|
||||||
expected_content = "Some SQL" \
|
expected_content = "Some SQL" \
|
||||||
"\nsome more stuff on a new line\n"
|
"\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")
|
content, filename, up_to_dateness = self.loader.get_source(None, "some_feature/sql/#90100#/some_action.sql")
|
||||||
|
|
||||||
self.assertEqual(expected_content, content)
|
self.assertEqual(expected_content, str(content).replace("\r",""))
|
||||||
self.assertIn("some_feature/sql/9.1_plus/some_action.sql", filename)
|
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):
|
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")
|
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.assertEqual("Some 9.2 SQL", str(content).replace("\r",""))
|
||||||
self.assertIn("some_feature/sql/9.2_plus/some_action.sql", filename)
|
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):
|
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")
|
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.assertEqual("Some default SQL", str(content).replace("\r",""))
|
||||||
self.assertIn("some_feature/sql/default/some_action_with_default.sql", filename)
|
self.assertIn(sql_path, filename)
|
||||||
|
|
||||||
def test_raise_not_found_exception_when_postgres_version_less_than_all_available_sql_templates(self):
|
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
|
# This software is released under the PostgreSQL Licence
|
||||||
#
|
#
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
class AppStarter:
|
class AppStarter:
|
||||||
"""
|
""" Helper for starting the full pgadmin4 app and loading the page via
|
||||||
Helper for starting the full pgadmin4 app and loading the page via selenium
|
selenium
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, driver, app_config):
|
def __init__(self, driver, app_config):
|
||||||
|
@ -24,23 +22,35 @@ class AppStarter:
|
||||||
self.app_config = app_config
|
self.app_config = app_config
|
||||||
|
|
||||||
def start_app(self):
|
def start_app(self):
|
||||||
|
""" This function start the subprocess to start pgAdmin app """
|
||||||
random_server_port = str(random.randint(10000, 65535))
|
random_server_port = str(random.randint(10000, 65535))
|
||||||
env = {
|
env = {
|
||||||
"PGADMIN_PORT": random_server_port,
|
"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)
|
env.update(os.environ)
|
||||||
|
|
||||||
self.pgadmin_process = subprocess.Popen(["python", "pgAdmin4.py"],
|
# Add OS check for pass value for 'preexec_fn'
|
||||||
shell=False,
|
self.pgadmin_process = subprocess.Popen(
|
||||||
preexec_fn=os.setsid,
|
["python", "pgAdmin4.py"],
|
||||||
stderr=open(os.devnull, 'w'),
|
shell=False,
|
||||||
env=env)
|
preexec_fn=None if os.name == 'nt' else os.setsid,
|
||||||
|
stderr=open(os.devnull, 'w'),
|
||||||
|
env=env
|
||||||
|
)
|
||||||
|
|
||||||
self.driver.set_window_size(1024, 1024)
|
self.driver.set_window_size(1024, 1024)
|
||||||
print("opening browser")
|
self.driver.get(
|
||||||
self.driver.get("http://" + self.app_config.DEFAULT_SERVER + ":" + random_server_port)
|
"http://" + self.app_config.DEFAULT_SERVER + ":" +
|
||||||
|
random_server_port)
|
||||||
|
|
||||||
def stop_app(self):
|
def stop_app(self):
|
||||||
|
""" This function stop the started app by killing process """
|
||||||
self.driver.quit()
|
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']):
|
for item in ['login_username', 'login_password']):
|
||||||
pgadmin_credentials = pgadmin_credentials[
|
pgadmin_credentials = pgadmin_credentials[
|
||||||
'pgAdmin4_login_credentials']
|
'pgAdmin4_login_credentials']
|
||||||
os.environ['PGADMIN_SETUP_EMAIL'] = pgadmin_credentials[
|
os.environ['PGADMIN_SETUP_EMAIL'] = str(pgadmin_credentials[
|
||||||
'login_username']
|
'login_username'])
|
||||||
os.environ['PGADMIN_SETUP_PASSWORD'] = pgadmin_credentials[
|
os.environ['PGADMIN_SETUP_PASSWORD'] = str(pgadmin_credentials[
|
||||||
'login_password']
|
'login_password'])
|
||||||
|
|
||||||
# Execute the setup file
|
# Execute the setup file
|
||||||
exec (open("setup.py").read())
|
exec (open("setup.py").read())
|
||||||
|
|
Loading…
Reference in New Issue