Skip to content

Commit

Permalink
Merge branch 'ay-add-handle-error-to-mdx-server' of github.com:demist…
Browse files Browse the repository at this point in the history
…o/demisto-sdk into ay-add-handle-error-to-mdx-server
  • Loading branch information
anas-yousef committed Feb 21, 2024
2 parents 01fec1a + cf20daa commit 52225fd
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changelog/4058.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed an issue where the *init* command sometimes failed in the dialogue when enter was pressed and not explicitly written false.
type: fix
pr_number: 4058
2 changes: 1 addition & 1 deletion demisto_sdk/commands/common/files/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def read_from_git_path(
def __read_git_file(self, tag: str, from_remote: bool = True) -> Any:
try:
return self.load(
self._git_util.read_file_content(
self.git_util().read_file_content(
self.path, commit_or_branch=tag, from_remote=from_remote
)
)
Expand Down
4 changes: 4 additions & 0 deletions demisto_sdk/commands/content_graph/objects/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,7 @@ def get_related_content(self) -> Dict[RelatedFileType, Dict]:
@property
def readme(self) -> str:
return self.get_related_text_file(RelatedFileType.README)

@property
def author_image_path(self) -> Path:
return Path(self.related_content[RelatedFileType.AUTHOR_IMAGE]["path"][0])
2 changes: 1 addition & 1 deletion demisto_sdk/commands/init/initiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def pack_init(self) -> bool:
create_integration = str(
input("\nDo you want to create an integration in the pack? Y/N ")
).lower()
if string_to_bool(create_integration):
if string_to_bool(create_integration, default_when_empty=False):
if not self.marketplace == MarketplaceVersions.MarketplaceV2:
is_same_category = str(
input(
Expand Down
45 changes: 45 additions & 0 deletions demisto_sdk/commands/validate/tests/IM_validators_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest

from demisto_sdk.commands.validate.tests.test_tools import (
create_metadata_object,
)
from demisto_sdk.commands.validate.validators.IM_validators.IM108_author_image_is_empty import (
AuthorImageIsEmptyValidator,
)


@pytest.mark.parametrize(
"content_items, expected_number_of_failures, expected_msgs",
[
([create_metadata_object()], 0, []),
(
[create_metadata_object(image="")],
1,
["The author image should not be empty. Please provide a relevant image."],
),
],
)
def test_AuthorImageIsEmptyValidator_is_valid(
content_items, expected_number_of_failures, expected_msgs
):
"""
Given
content_items.
- Case 1: Author image not empty.
- Case 2: Author image is empty.
When
- Calling the AuthorImageIsEmptyValidator is_valid function.
Then
- Make sure the right amount of pack author image failed, and that the right error message is returned.
- Case 1: Shouldn't fail.
- Case 2: Should fail.
"""
results = AuthorImageIsEmptyValidator().is_valid(content_items)
assert len(results) == expected_number_of_failures
assert all(
[
result.message == expected_msg
for result, expected_msg in zip(results, expected_msgs)
]
)
3 changes: 3 additions & 0 deletions demisto_sdk/commands/validate/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def create_metadata_object(
values: Optional[List[Any]] = None,
fields_to_delete: Optional[List[str]] = None,
readme_text: str = "",
image: Optional[str] = None,
) -> PackMetadata:
"""Creating an pack_metadata object with altered fields from a default pack_metadata json structure.
Expand All @@ -204,6 +205,8 @@ def create_metadata_object(
PackParser.parse_ignored_errors = MagicMock(return_value={})
pack.pack_metadata.write_json(json_content)
pack.readme.write_text(readme_text)
if image is not None:
pack.author_image.write(image)
return BaseContent.from_path(Path(pack.path))


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import annotations

from typing import Iterable, List

from demisto_sdk.commands.common.constants import RelatedFileType
from demisto_sdk.commands.content_graph.objects.pack import Pack
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)

ContentTypes = Pack


class AuthorImageIsEmptyValidator(BaseValidator[ContentTypes]):
error_code = "IM108"
description = "Checks that the author image file is not empty"
error_message = (
"The author image should not be empty. Please provide a relevant image."
)
related_field = "image"
is_auto_fixable = False
related_file_type = [RelatedFileType.AUTHOR_IMAGE]

def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
return [
ValidationResult(
validator=self,
message=self.error_message,
content_object=content_item,
)
for content_item in content_items
if (content_item.author_image_path.stat().st_size == 0)
]

0 comments on commit 52225fd

Please sign in to comment.