def test_insert_description_to_yml(): with patch.object(IntegrationScriptUnifier, "__init__", lambda a, b, c, d, e: None): unifier = IntegrationScriptUnifier('', None, None, None) unifier.package_path = f"{git_path()}/demisto_sdk/tests/test_files/VulnDB/" unifier.dir_name = "Integrations" unifier.is_script_package = False with open(f"{git_path()}/demisto_sdk/tests/test_files/VulnDB/VulnDB_description.md", "rb") as desc_file: desc_data = desc_file.read().decode("utf-8") integration_doc_link = '\n\n---\n[View Integration Documentation]' \ '(https://xsoar.pan.dev/docs/reference/integrations/vuln-db)' yml_unified, found_data_path = unifier.insert_description_to_yml( {'commonfields': {'id': 'VulnDB'}}, {} ) assert found_data_path == f"{git_path()}/demisto_sdk/tests/test_files/VulnDB/VulnDB_description.md" assert (desc_data + integration_doc_link) == yml_unified['detaileddescription']
def test_insert_description_to_yml_doc_link_exist(tmp_path, mocker): """ Given: - integration which have a detailed description with "View Integration Documentation" doc link When: - Getting integration doc link Then: - Verify get_integration_doc_link function is not called """ detailed_desc = tmp_path / 'integration_description.md' detailed_desc.write_text('[View Integration Documentation]' '(https://xsoar.pan.dev/docs/reference/integrations/some-integration-id)') mock_func = mocker.patch.object(IntegrationScriptUnifier, 'get_integration_doc_link', return_result='') unifier = IntegrationScriptUnifier(str(tmp_path)) yml_unified, _ = unifier.insert_description_to_yml({'commonfields': {'id': 'some integration id'}}, {}) assert mock_func.call_count == 0
def test_insert_description_to_yml_with_no_detailed_desc(tmp_path): """ Given: - Integration with empty detailed description and with non-empty README When: - Inserting detailed description to the unified integration YAML Then: - Verify the integration doc markdown link is inserted to the detailed description """ readme = tmp_path / 'README.md' readme.write_text('README') detailed_desc = tmp_path / 'integration_description.md' detailed_desc.write_text('') unifier = IntegrationScriptUnifier(str(tmp_path)) yml_unified, _ = unifier.insert_description_to_yml({'commonfields': {'id': 'some integration id'}}, {}) assert '[View Integration Documentation](https://xsoar.pan.dev/docs/reference/integrations/some-integration-id)'\ == yml_unified['detaileddescription']