def get_apache_configurator(config_path, config_dir, work_dir, version=(2, 4, 7)): """Create an Apache Configurator with the specified options.""" backups = os.path.join(work_dir, "backups") with mock.patch("letsencrypt_apache.configurator." "subprocess.Popen") as mock_popen: # This just states that the ssl module is already loaded mock_popen().communicate.return_value = ("ssl_module", "") config = configurator.ApacheConfigurator(config=mock.MagicMock( apache_server_root=config_path, apache_le_vhost_ext=constants.CLI_DEFAULTS["le_vhost_ext"], backup_dir=backups, config_dir=config_dir, temp_checkpoint_dir=os.path.join(work_dir, "temp_checkpoints"), in_progress_dir=os.path.join(backups, "IN_PROGRESS"), work_dir=work_dir), name="apache", version=version) config.prepare() return config
def _prepare_configurator(self, server_root, config_file): """Prepares the Apache plugin for testing""" self.le_config.apache_server_root = server_root self.le_config.apache_ctl = "apachectl -d {0} -f {1}".format( server_root, config_file) self.le_config.apache_enmod = "a2enmod.sh {0}".format(server_root) self.le_config.apache_init_script = self.le_config.apache_ctl + " -k" self._apache_configurator = configurator.ApacheConfigurator( config=configuration.NamespaceConfig(self.le_config), name="apache") self._apache_configurator.prepare()
def get_apache_configurator(config_path, config_dir, work_dir, version=(2, 4, 7), conf=None): """Create an Apache Configurator with the specified options. :param conf: Function that returns binary paths. self.conf in Configurator """ backups = os.path.join(work_dir, "backups") mock_le_config = mock.MagicMock( apache_server_root=config_path, apache_le_vhost_ext=constants.CLI_DEFAULTS["le_vhost_ext"], backup_dir=backups, config_dir=config_dir, temp_checkpoint_dir=os.path.join(work_dir, "temp_checkpoints"), in_progress_dir=os.path.join(backups, "IN_PROGRESS"), work_dir=work_dir) with mock.patch("letsencrypt_apache.configurator." "subprocess.Popen") as mock_popen: # This indicates config_test passes mock_popen().communicate.return_value = ("Fine output", "No problems") mock_popen().returncode = 0 with mock.patch("letsencrypt_apache.configurator.le_util." "exe_exists") as mock_exe_exists: mock_exe_exists.return_value = True with mock.patch("letsencrypt_apache.parser.ApacheParser." "update_runtime_variables"): config = configurator.ApacheConfigurator(config=mock_le_config, name="apache", version=version) # This allows testing scripts to set it a bit more quickly if conf is not None: config.conf = conf # pragma: no cover config.prepare() return config
def get_apache_configurator(config_path, vhost_path, config_dir, work_dir, version=(2, 4, 7), conf=None): """Create an Apache Configurator with the specified options. :param conf: Function that returns binary paths. self.conf in Configurator """ backups = os.path.join(work_dir, "backups") mock_le_config = mock.MagicMock( apache_server_root=config_path, apache_vhost_root=vhost_path, apache_le_vhost_ext=constants.os_constant("le_vhost_ext"), apache_challenge_location=config_path, backup_dir=backups, config_dir=config_dir, temp_checkpoint_dir=os.path.join(work_dir, "temp_checkpoints"), in_progress_dir=os.path.join(backups, "IN_PROGRESS"), work_dir=work_dir) with mock.patch("letsencrypt_apache.configurator.le_util.run_script"): with mock.patch("letsencrypt_apache.configurator.le_util." "exe_exists") as mock_exe_exists: mock_exe_exists.return_value = True with mock.patch("letsencrypt_apache.parser.ApacheParser." "update_runtime_variables"): config = configurator.ApacheConfigurator(config=mock_le_config, name="apache", version=version) # This allows testing scripts to set it a bit more quickly if conf is not None: config.conf = conf # pragma: no cover config.prepare() return config