def call_importer(args, cfg): # pragma: no cover """Returns result of galaxy_importer import process. :param file: Artifact file to import. Method excluded from pytest unit test coverage, tests exist in tests/integration """ if not args.file: return collection.import_collection( git_clone_path=os.path.abspath(args.git_clone_path), output_path=os.path.abspath(args.output_path), logger=logger, cfg=cfg, ) match = FILENAME_REGEXP.match(os.path.basename(args.file)) namespace, name, version = match.groups() filename = collection.CollectionFilename(namespace, name, version) with open(args.file, "rb") as fh: try: data = collection.import_collection(fh, filename, logger=logger, cfg=cfg) except ImporterError as e: logger.error(f"The import failed for the following reason: {str(e)}") return None except Exception as e: logger.exception(f"Unexpected error occurred: {str(e)}") return None logger.info("Importer processing completed successfully") return data
def call_importer(filepath, cfg): """Returns result of galaxy_importer import process. :param file: Artifact file to import. """ match = FILENAME_REGEXP.match(os.path.basename(filepath)) namespace, name, version = match.groups() filename = collection.CollectionFilename(namespace, name, version) with open(filepath, 'rb') as f: try: data = collection.import_collection(f, filename, logger=logger, cfg=cfg) except ImporterError as e: logger.error( f'The import failed for the following reason: {str(e)}') return None except Exception: logger.exception('Unexpected error occurred:') return None logger.info('Importer processing completed successfully') return data
def call_importer(file): """Returns result of galaxy_importer import process. :param file: Artifact file to import. """ data = collection.import_collection(file) if data['result'] == 'completed': print('Importer processing completed successfully') else: print(f'Error during importer proccessing: {data["error"]}') return data
def call_importer(filepath): """Returns result of galaxy_importer import process. :param file: Artifact file to import. """ match = FILENAME_REGEXP.match(os.path.basename(filepath)) namespace, name, version = match.groups() filename = collection.CollectionFilename(namespace, name, version) with open(filepath, 'rb') as f: try: data = collection.import_collection(f, filename) except Exception: logging.error('Error during importer proccessing:', exc_info=True) return None logging.info('Importer processing completed successfully') return data
def test_import_collection(mocker): mocker.patch.object(collection, '_import_collection') mocker.patch.object(ConfigFile, 'load') collection.import_collection(file=None, logger=logging, cfg=None) assert ConfigFile.load.called assert collection._import_collection.called
def test_import_collection(mocker): mocker.patch.object(collection, "_import_collection") mocker.patch.object(config.ConfigFile, "load") collection.import_collection(file="file_placeholder", logger=logging, cfg=None) assert config.ConfigFile.load.called assert collection._import_collection.called