def test_merge_and_extract_existing_file_corrupted_dir( self, tmp_path, mocker, capsys): """ Given - The integration exist in output pack, the directory is corrupted (i.e. a file is missing, for example: the image file) When - An integration about to be downloaded Then - Ensure integration is downloaded successfully """ env = Environment(tmp_path) mocker.patch.object(Downloader, 'get_corresponding_pack_file_object', return_value={}) with patch.object(Downloader, "__init__", lambda a, b, c: None): downloader = Downloader('', '') downloader.output_pack_path = env.PACK_INSTANCE_PATH downloader.log_verbose = False downloader.pack_content = env.PACK_CONTENT downloader.run_format = False downloader.num_merged_files = 0 downloader.num_added_files = 0 downloader.log_verbose = False downloader.merge_and_extract_existing_file( env.INTEGRATION_CUSTOM_CONTENT_OBJECT) stdout, _ = capsys.readouterr() assert 'Merged' in stdout
def test_merge_and_extract_existing_file_js(self, tmp_path): with patch.object(Downloader, "__init__", lambda a, b, c: None): downloader = Downloader('', '') downloader.log_verbose = False downloader.num_merged_files = 0 downloader.num_added_files = 0 downloader.log_verbose = False downloader.files_not_downloaded = [] downloader.pack_content = { entity: list() for entity in CONTENT_ENTITIES_DIRS } js_custom_content_object = { 'id': 'SumoLogic', 'name': 'SumoLogic', 'path': 'demisto_sdk/commands/download/tests/tests_data/custom_content/integration-DummyJSIntegration' '.yml', 'entity': 'Integrations', 'type': 'integration', 'file_ending': 'yml', 'exist_in_pack': True, 'code_lang': 'javascript' } downloader.merge_and_extract_existing_file( js_custom_content_object)
def test_merge_and_extract_existing_file(self, tmp_path): env = Environment(tmp_path) with patch.object(Downloader, "__init__", lambda a, b, c: None): downloader = Downloader('', '') ryaml = YAML() ryaml.preserve_quotes = True downloader.log_verbose = False downloader.pack_content = env.PACK_CONTENT downloader.run_format = False downloader.num_merged_files = 0 downloader.num_added_files = 0 downloader.log_verbose = False downloader.merge_and_extract_existing_file( env.INTEGRATION_CUSTOM_CONTENT_OBJECT) paths = [ file['path'] for file in env.INTEGRATION_PACK_OBJECT['Test Integration'] ] for path in paths: assert os.path.isfile(path) yml_data = get_yaml( env.INTEGRATION_PACK_OBJECT['Test Integration'][2]['path']) for field in DELETED_YML_FIELDS_BY_DEMISTO: obj = yml_data dotted_path_list = field.split('.') for path_part in dotted_path_list: if path_part != dotted_path_list[-1]: obj = obj.get(path_part) else: if obj.get(path_part): assert True else: assert False with open( env.INTEGRATION_PACK_OBJECT['Test Integration'][5]['path'], 'r') as description_file: description_data = description_file.read() assert 'Test Integration Long Description TEST' in description_data with open( env.INTEGRATION_PACK_OBJECT['Test Integration'][0]['path'], 'r') as code_file: code_data = code_file.read() assert 'TEST' in code_data