def test_execute_action_handler(self): sys.platform = 'linux' # reseting mock to original func def self.json_file_handler.get_json_file_content = self.get_json_file_content_backup ext_env_handler = ExtEnvHandler(self.json_file_handler, handler_env_file_path=os.path.join(os.path.pardir, "tests", "helpers")) install_command_handler = InstallCommandHandler(self.logger, ext_env_handler) self.assertEqual(install_command_handler.execute_handler_action(), Constants.ExitCode.Okay)
def test_validate_environment(self): config_type = 'handlerEnvironment' # file has no content ext_env_handler = ExtEnvHandler(self.json_file_handler) install_command_handler = InstallCommandHandler(self.logger, ext_env_handler) self.assertRaises(Exception, install_command_handler.validate_environment) # Validating datatype for fields in HandlerEnvironment handler_environment = [] handler_environment_dict = {} handler_environment.append(handler_environment_dict) install_command_handler = InstallCommandHandler(self.logger, handler_environment) self.verify_key(handler_environment[0], 'version', 1.0, 'abc', True, Exception, install_command_handler.validate_environment) self.verify_key(handler_environment[0], 'version', 1.0, '', True, Exception, install_command_handler.validate_environment) self.verify_key(handler_environment[0], 'handlerEnvironment', {}, 'abc', True, Exception, install_command_handler.validate_environment) self.verify_key(handler_environment[0][config_type], 'logFolder', 'test', 1.0, True, Exception, install_command_handler.validate_environment) self.verify_key(handler_environment[0][config_type], 'configFolder', 'test', 1.0, True, Exception, install_command_handler.validate_environment) self.verify_key(handler_environment[0][config_type], 'statusFolder', 'test', 1.0, True, Exception, install_command_handler.validate_environment) # Validating HandlerEnvironment.json file # reseting mock to original func def self.json_file_handler.get_json_file_content = self.get_json_file_content_backup ext_env_handler = ExtEnvHandler(self.json_file_handler, handler_env_file_path=os.path.join(os.path.pardir, "tests", "helpers")) install_command_handler = InstallCommandHandler(self.logger, ext_env_handler) install_command_handler.validate_environment()
def install(self): try: self.setup_file_logger(action=Constants.INSTALL) self.logger.log("Extension installation started") install_command_handler = InstallCommandHandler( self.logger, self.ext_env_handler) return install_command_handler.execute_handler_action() except Exception as error: self.logger.log_error( "Error occurred during extension install. [Error={0}]".format( repr(error))) return Constants.ExitCode.HandlerFailed finally: self.close_file_logger()
def test_validate_os_type_not_linux(self): ext_env_handler = ExtEnvHandler(self.json_file_handler) install_command_handler = InstallCommandHandler(self.logger, ext_env_handler) sys.platform = 'win32' self.assertRaises(Exception, install_command_handler.validate_os_type)
def test_validate_os_type_is_linux(self): ext_env_handler = ExtEnvHandler(self.json_file_handler) install_command_handler = InstallCommandHandler(self.logger, ext_env_handler) sys.platform = 'linux' self.assertTrue(install_command_handler.validate_os_type())