| 
									
										
										
										
											2017-03-16 14:27:55 +00:00
										 |  |  | ########################################################################## | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # pgAdmin 4 - PostgreSQL Tools | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Copyright (C) 2013 - 2017, The pgAdmin Development Team | 
					
						
							|  |  |  | # This software is released under the PostgreSQL Licence | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | ########################################################################## | 
					
						
							| 
									
										
										
										
											2017-02-22 12:41:28 +00:00
										 |  |  | import os | 
					
						
							|  |  |  | import subprocess | 
					
						
							|  |  |  | import signal | 
					
						
							|  |  |  | import random | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 09:50:41 +01:00
										 |  |  | import time | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 12:41:28 +00:00
										 |  |  | class AppStarter: | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  |     """ Helper for starting the full pgadmin4 app and loading the page via
 | 
					
						
							|  |  |  |     selenium | 
					
						
							| 
									
										
										
										
											2017-02-22 12:41:28 +00:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, driver, app_config): | 
					
						
							|  |  |  |         self.driver = driver | 
					
						
							|  |  |  |         self.app_config = app_config | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def start_app(self): | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  |         """ This function start the subprocess to start pgAdmin app """ | 
					
						
							| 
									
										
										
										
											2017-02-22 12:41:28 +00:00
										 |  |  |         random_server_port = str(random.randint(10000, 65535)) | 
					
						
							| 
									
										
										
										
											2017-02-28 17:09:23 +00:00
										 |  |  |         env = { | 
					
						
							|  |  |  |             "PGADMIN_PORT": random_server_port, | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  |             "SQLITE_PATH": str(self.app_config.TEST_SQLITE_PATH) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-02-22 12:41:28 +00:00
										 |  |  |         env.update(os.environ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  |         # 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 | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-02-22 12:41:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-21 10:57:29 +01:00
										 |  |  |         self.driver.set_window_size(1280, 1024) | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  |         self.driver.get( | 
					
						
							|  |  |  |             "http://" + self.app_config.DEFAULT_SERVER + ":" + | 
					
						
							|  |  |  |             random_server_port) | 
					
						
							| 
									
										
										
										
											2017-02-22 12:41:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def stop_app(self): | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  |         """ This function stop the started app by killing process """ | 
					
						
							| 
									
										
										
										
											2017-03-07 13:49:52 +00:00
										 |  |  |         self.driver.quit() | 
					
						
							| 
									
										
										
										
											2017-05-08 09:25:05 +01:00
										 |  |  |         # 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) |