def setUpClass(cls): cls.logger = setup_logger(cls.__name__, logger_level=logging.DEBUG) cls.runner = LocalCommandRunner(cls.logger) cls.plugins_work_dir = tempfile.mkdtemp(prefix='plugins-work-dir-') cls.file_server_resource_base = tempfile.mkdtemp( prefix='file-server-resource-base-') cls.fs = test_utils.FileServer(root_path=cls.file_server_resource_base) cls.fs.start() cls.file_server_url = 'http://localhost:{0}'.format(cls.fs.port) cls.plugins_to_be_installed = [ 'mock-plugin', 'mock-plugin-modified', 'mock-plugin-with-requirements' ] cls.wagons = {} for plugin_dir in cls.plugins_to_be_installed: test_utils.create_plugin_tar( plugin_dir_name=plugin_dir, target_directory=cls.file_server_resource_base) cls.wagons[plugin_dir] = test_utils.create_plugin_wagon( plugin_dir_name=plugin_dir, target_directory=cls.file_server_resource_base)
def setUpClass(cls): cls.logger = setup_logger(cls.__name__, logger_level=logging.DEBUG) cls.runner = LocalCommandRunner(cls.logger) cls.plugins_work_dir = tempfile.mkdtemp( prefix='plugins-work-dir-') cls.file_server_resource_base = tempfile.mkdtemp( prefix='file-server-resource-base-') cls.fs = test_utils.FileServer( root_path=cls.file_server_resource_base) cls.fs.start() cls.file_server_url = 'http://localhost:{0}'.format(cls.fs.port) cls.plugins_to_be_installed = [ 'mock-plugin', 'mock-plugin-modified', 'mock-plugin-with-requirements' ] cls.wagons = {} for plugin_dir in cls.plugins_to_be_installed: test_utils.create_plugin_tar( plugin_dir_name=plugin_dir, target_directory=cls.file_server_resource_base) cls.wagons[plugin_dir] = test_utils.create_plugin_wagon( plugin_dir_name=plugin_dir, target_directory=cls.file_server_resource_base)
def test_plugins(file_server): plugins_to_be_installed = [ 'mock-plugin', 'mock-plugin-modified', 'mock-plugin-with-requirements' ] wagons = {} for plugin_dir in plugins_to_be_installed: create_plugin_tar(plugin_dir_name=plugin_dir, target_directory=file_server.root_path) wagons[plugin_dir] = create_plugin_wagon( plugin_dir_name=plugin_dir, target_directory=file_server.root_path) yield wagons shutil.rmtree(os.path.join(sys.prefix, 'plugins'), ignore_errors=True) shutil.rmtree(os.path.join(sys.prefix, 'source_plugins'), ignore_errors=True)
def test_extract_package_to_dir(test_plugins, file_server): # create a plugin tar file and put it in the file server plugin_dir_name = 'mock-plugin-with-requirements' plugin_tar_name = test_utils.create_plugin_tar(plugin_dir_name, file_server.root_path) plugin_source_path = resources.get_resource( os.path.join('plugins', plugin_dir_name)) plugin_tar_url = '{0}/{1}'.format(file_server.url, plugin_tar_name) extracted_plugin_path = installer.extract_package_to_dir(plugin_tar_url) assert test_utils.are_dir_trees_equal(plugin_source_path, extracted_plugin_path)
def test_extract_package_to_dir(self): # create a plugin tar file and put it in the file server plugin_dir_name = 'mock-plugin-with-requirements' plugin_tar_name = test_utils.create_plugin_tar( plugin_dir_name, self.file_server_resource_base) plugin_source_path = resources.get_resource(os.path.join( 'plugins', plugin_dir_name)) plugin_tar_url = '{0}/{1}'.format(self.file_server_url, plugin_tar_name) extracted_plugin_path = installer.extract_package_to_dir( plugin_tar_url) self.assertTrue(test_utils.are_dir_trees_equal( plugin_source_path, extracted_plugin_path))
def test_install_dependencies_versions_conflict(self): def extract_requests_version(): pip_freeze = self.installer._pip_freeze().split('\n') for package in pip_freeze: if package.startswith('requests=='): requests_version = package.split('==')[0] return requests_version raise AssertionError('Expected requests to be installed.') requests_plugin = test_utils.create_mock_plugin( basedir=self.plugins_work_dir, install_requires=['requests==2.6.0']) requests_tar = test_utils.create_plugin_tar( basedir=self.plugins_work_dir, plugin_dir_name=requests_plugin, target_directory=self.file_server_resource_base) requests_wagon = test_utils.create_plugin_wagon( basedir=self.plugins_work_dir, plugin_dir_name=requests_plugin, target_directory=self.file_server_resource_base) before_requests_version = extract_requests_version() plugin_struct = self._plugin_struct(source=requests_tar, name=requests_plugin) try: self.installer.install(plugin_struct) after_requests_version = extract_requests_version() finally: self.installer.uninstall(plugin=plugin_struct) self.assertEqual(before_requests_version, after_requests_version) try: with _patch_for_install_wagon(requests_plugin, '0.1', download_path=requests_wagon): self.installer.install(self._plugin_struct()) after_requests_version = extract_requests_version() finally: self.installer.uninstall_wagon(requests_plugin, '0.1') self.assertEqual(before_requests_version, after_requests_version)