def test_unify_integration__detailed_description_with_special_char(self): """ - """ description = ''' some test with special chars שלום hello 你好 ''' create_test_package( test_dir=self.test_dir_path, package_name=self.package_name, base_yml='demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/SampleIntegPackage.yml', script_code=TEST_VALID_CODE, image_file='demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/SampleIntegPackage_image.png', detailed_description=description, ) unifier = IntegrationScriptUnifier(self.export_dir_path, output=self.test_dir_path) yml_files = unifier.unify() export_yml_path = yml_files[0] assert export_yml_path == self.expected_yml_path actual_yml = get_yaml(export_yml_path) expected_yml = get_yaml('demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/' 'integration-SampleIntegPackageDescSpecialChars.yml') assert expected_yml == actual_yml assert actual_yml['detaileddescription'] == description
def test_unify_script__docker45(self): """ sanity test of merge_script_package_to_yml of script """ create_test_package( test_dir=self.test_dir_path, package_name=self.package_name, base_yml='demisto_sdk/tests/test_files/Unifier/SampleScriptPackage/SampleScriptPackageDocker45.yml', script_code=TEST_VALID_CODE, ) unifier = IntegrationScriptUnifier(input=self.export_dir_path, output=self.test_dir_path) yml_files = unifier.unify() assert len(yml_files) == 2 export_yml_path = yml_files[0] export_yml_path_45 = yml_files[1] assert export_yml_path == self.expected_yml_path assert export_yml_path_45 == self.expected_yml_path.replace('.yml', '_45.yml') actual_yml = get_yaml(export_yml_path) expected_yml = get_yaml('demisto_sdk/tests/test_files/Unifier/SampleScriptPackage/' 'script-SampleScriptPackageSanityDocker45.yml') assert expected_yml == actual_yml actual_yml_45 = get_yaml(export_yml_path_45) expected_yml_45 = get_yaml('demisto_sdk/tests/test_files/Unifier/SampleScriptPackage/' 'script-SampleScriptPackageSanityDocker45_45.yml') assert expected_yml_45 == actual_yml_45
def test_unify_integration(self): """ sanity test of merge_script_package_to_yml of integration """ create_test_package( test_dir=self.test_dir_path, package_name=self.package_name, base_yml='demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/SampleIntegPackage.yml', script_code=TEST_VALID_CODE, detailed_description=TEST_VALID_DETAILED_DESCRIPTION, image_file='demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/SampleIntegPackage_image.png', ) unifier = IntegrationScriptUnifier(input=self.export_dir_path, output=self.test_dir_path) yml_files = unifier.unify() export_yml_path = yml_files[0] assert export_yml_path == self.expected_yml_path comment = '# this is a comment text inside a file 033dab25fd9655480dbec3a4c579a0e6' with open(export_yml_path) as file_: unified_content = file_.read() assert comment in unified_content actual_yml = get_yaml(export_yml_path) expected_yml = get_yaml('demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/' 'integration-SampleIntegPackageSanity.yml') assert expected_yml == actual_yml
def build( self, code: Optional[str] = None, yml: Optional[dict] = None, readme: Optional[str] = None, description: Optional[str] = None, changelog: Optional[str] = None, image: Optional[bytes] = None ): """Writes not None objects to files. """ if code is not None: self.code.write(code) if yml is not None: self.yml.write_dict(yml) if readme is not None: self.readme.write(readme) if description is not None: self.description.write(description) if changelog is not None: self.changelog.write(changelog) if image is not None: self.image.write_bytes(image) if self.create_unified: unifier = IntegrationScriptUnifier(input=self.path, output=os.path.dirname(self._tmpdir_integration_path)) yml_path = unifier.unify()[0] readme_path = unifier.move_readme_next_to_unified(yml_path) shutil.rmtree(self._tmpdir_integration_path) self.yml.path = yml_path self.readme.path = readme_path
def _unify(self, dest_dir: Path) -> List[Path]: """Unify YAMLContentUnfiedObject in destination dir. Args: dest_dir: Destination directory. Returns: List[Path]: List of new created files. TODO: 1. Add Exception raising in unify module. 2. Verbosity to quiet mode option in unify module. """ # Directory configuration - Integrations or Scripts unify_dir = ENTITY_TYPE_TO_DIR[self._content_type.value] # Unify step unifier: Union[IntegrationScriptUnifier, RuleUnifier] if self._content_type in [FileType.SCRIPT, FileType.INTEGRATION]: unifier = IntegrationScriptUnifier(input=str(self.path.parent), dir_name=unify_dir, output=dest_dir, force=True, yml_modified_data=self.to_dict()) elif self._content_type in [FileType.PARSING_RULE, FileType.MODELING_RULE]: unifier = RuleUnifier(input=str(self.path.parent), output=dest_dir, force=True) created_files: List[str] = unifier.unify() # Validate that unify succeed - there is not exception raised in unify module. if not created_files: raise exc.ContentDumpError(self, self.path, "Unable to unify object") return [Path(path) for path in created_files]
def test_unify_default_output_script(self): """ Given - DummyScript script. - No output path. When - Running Unify on it. Then - Ensure Unify script works with default output. """ input_path_script = TESTS_DIR + '/test_files/Packs/DummyPack/Scripts/DummyScript' unifier = IntegrationScriptUnifier(input_path_script) yml_files = unifier.unify() export_yml_path = yml_files[0] expected_yml_path = TESTS_DIR + '/test_files/Packs/DummyPack/Scripts/DummyScript/script-DummyScript.yml' assert export_yml_path == expected_yml_path os.remove(expected_yml_path)
def test_unify_default_output_integration(self): """ Given - UploadTest integration. - No output path. When - Running Unify on it. Then - Ensure Unify command works with default output. """ input_path_integration = TESTS_DIR + '/test_files/Packs/DummyPack/Integrations/UploadTest' unifier = IntegrationScriptUnifier(input_path_integration) yml_files = unifier.unify() export_yml_path = yml_files[0] expected_yml_path = TESTS_DIR + '/test_files/Packs/DummyPack/Integrations/UploadTest/integration-UploadTest.yml' assert export_yml_path == expected_yml_path os.remove(expected_yml_path)
def test_unify_integration__detailed_description_with_yml_structure(self): """ - """ description = ''' this is a regular line some test with special chars hello key: - subkey: hello subkey2: hi keys: "some more values" asd - hello hi: 'dsfsd' final test: hi ''' create_test_package( test_dir=self.test_dir_path, package_name=self.package_name, base_yml='demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/SampleIntegPackage.yml', script_code=TEST_VALID_CODE, image_file='demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/SampleIntegPackage_image.png', detailed_description=description, ) unifier = IntegrationScriptUnifier(self.export_dir_path, output=self.test_dir_path) yml_files = unifier.unify() export_yml_path = yml_files[0] assert export_yml_path == self.expected_yml_path actual_yml = get_yaml(export_yml_path) expected_yml = get_yaml('demisto_sdk/tests/test_files/Unifier/SampleIntegPackage/' 'integration-SampleIntegPackageDescAsYML.yml') assert expected_yml == actual_yml assert actual_yml['detaileddescription'] == description
def test_unify_script(self): """ sanity test of merge_script_package_to_yml of script """ create_test_package( test_dir=self.test_dir_path, package_name=self.package_name, base_yml='demisto_sdk/tests/test_files/Unifier/SampleScriptPackage/SampleScriptPackage.yml', script_code=TEST_VALID_CODE, ) unifier = IntegrationScriptUnifier(input=self.export_dir_path, output=self.test_dir_path) yml_files = unifier.unify() export_yml_path = yml_files[0] assert export_yml_path == self.expected_yml_path actual_yml = get_yaml(export_yml_path) expected_yml = get_yaml('demisto_sdk/tests/test_files/Unifier/SampleScriptPackage/' 'script-SampleScriptPackageSanity.yml') assert expected_yml == actual_yml
def test_unify_default_output_integration_for_relative_current_dir_input(self, mocker): """ Given - Input path of '.'. - UploadTest integration. When - Running Unify on it. Then - Ensure Unify command works with default output given relative path to current directory. """ from demisto_sdk.commands.unify.integration_script_unifier import \ IntegrationScriptUnifier abs_path_mock = mocker.patch('demisto_sdk.commands.unify.integration_script_unifier.os.path.abspath') abs_path_mock.return_value = TESTS_DIR + '/test_files/Packs/DummyPack/Integrations/UploadTest' input_path_integration = '.' unifier = IntegrationScriptUnifier(input_path_integration) yml_files = unifier.unify() export_yml_path = yml_files[0] expected_yml_path = TESTS_DIR + '/test_files/Packs/DummyPack/Integrations/UploadTest/integration-UploadTest.yml' assert export_yml_path == expected_yml_path os.remove(expected_yml_path)