def test_get_pg_server_folder_does_not_exist(self): """Test that the get_pg_exe_path function throws an error if the server version folder being searched for does not exist""" return_value = [('/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win', ('11', '12'), ()), ('/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win/11', (), ('pg_dump', 'pg_restore')), ('/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win/12', (), ('pg_dump', 'pg_restore'))] with mock.patch('os.walk', new=mock.Mock( return_value=return_value)), self.assertRaises(ValueError): disaster_recovery_service._get_pg_exe_path('pg_dump', (9, 6))
def test_get_pg_exe_path_local(self): """Test the get_pg_exe_path function when the service is running from source code""" # Back up these values so that the test can overwrite them old_arg0 = sys.argv[0] old_platform = sys.platform try: with mock.patch('os.path.exists', new=mock.Mock(return_value=True)): # Override sys.argv[0] to simulate running the code directly from source sys.argv[0] = os.path.normpath( '/ossdbtoolsservice/ossdbtoolsservice/ossdbtoolsservice_main.py' ) # If I get the executable path on Mac sys.platform = 'darwin' path = disaster_recovery_service._get_pg_exe_path( self.pg_dump_exe) # Then the path uses the mac directory and does not have a trailing .exe self.assertEqual( path, os.path.normpath( '/ossdbtoolsservice/ossdbtoolsservice/pg_exes/mac/bin/pg_dump' )) # If I get the executable path on Linux sys.platform = 'linux' path = disaster_recovery_service._get_pg_exe_path( self.pg_dump_exe) # Then the path uses the linux directory and does not have a trailing .exe self.assertEqual( path, os.path.normpath( '/ossdbtoolsservice/ossdbtoolsservice/pg_exes/linux/bin/pg_dump' )) # If I get the executable path on Windows sys.platform = 'win32' path = disaster_recovery_service._get_pg_exe_path( self.pg_dump_exe) # Then the path uses the win directory and does have a trailing .exe self.assertEqual( path, os.path.normpath( '/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win/pg_dump.exe' )) finally: sys.argv[0] = old_arg0 sys.platform = old_platform
def test_get_pg_exe_path_local_win(self): """Test the get_pg_exe_path function for windows when the service is running from source code""" # Back up these values so that the test can overwrite them old_arg0 = sys.argv[0] old_platform = sys.platform return_value = [('/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win', ('11', '12'), ()), ('/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win/11', (), ('pg_dump', 'pg_restore')), ('/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win/12', (), ('pg_dump', 'pg_restore'))] try: with mock.patch('os.walk', new=mock.Mock(return_value=return_value)): with mock.patch('os.path.exists', new=mock.Mock(return_value=True)): # Override sys.argv[0] to simulate running the code directly from source sys.argv[0] = os.path.normpath( '/ossdbtoolsservice/ossdbtoolsservice/ossdbtoolsservice_main.py' ) # If I get the executable path on Windows sys.platform = 'win32' path = disaster_recovery_service._get_pg_exe_path( self.pg_dump_exe, (11, 0)) # Then the path uses the win directory and does have a trailing .exe self.assertEqual( path, os.path.normpath( '/ossdbtoolsservice/ossdbtoolsservice/pg_exes/win/11/pg_dump.exe' )) finally: sys.argv[0] = old_arg0 sys.platform = old_platform
def test_get_pg_exe_path_frozen_mac(self): """Test the get_pg_exe_path function for mac when the service is running from a cx_freeze build""" # Back up these values so that the test can overwrite them old_arg0 = sys.argv[0] old_platform = sys.platform return_value = [ ('/ossdbtoolsservice/build/ossdbtoolsservice/pg_exes/mac', ('9.5', '9.6'), ()), ('/ossdbtoolsservice/build/ossdbtoolsservice/pg_exes/mac/9.5', ('bin', 'lib'), ()), ('/ossdbtoolsservice/build/ossdbtoolsservice/pg_exes/mac/9.6', ('bin', 'lib'), ()) ] try: with mock.patch('os.walk', new=mock.Mock(return_value=return_value)): with mock.patch('os.path.exists', new=mock.Mock(return_value=True)): # Override sys.argv[0] to simulate running the code from a cx_freeze build sys.argv[0] = os.path.normpath( '/ossdbtoolsservice/build/ossdbtoolsservice/ossdbtoolsservice_main' ) # If I get the executable path on Mac sys.platform = 'darwin' path = disaster_recovery_service._get_pg_exe_path( self.pg_dump_exe, (9, 6)) # Then the path uses the mac directory and does not have a trailing .exe self.assertEqual( path, os.path.normpath( '/ossdbtoolsservice/build/ossdbtoolsservice/pg_exes/mac/9.6/bin/pg_dump' )) finally: sys.argv[0] = old_arg0 sys.platform = old_platform
def test_get_pg_exe_path_does_not_exist(self): """Test that the get_pg_exe_path function throws an error if the executable being searched for does not exist""" with mock.patch('os.path.exists', new=mock.Mock( return_value=False)), self.assertRaises(ValueError): disaster_recovery_service._get_pg_exe_path('not_pg_dump')