-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ay-add-handle-error-to-mdx-server' of github.com:demist…
…o/demisto-sdk into ay-add-handle-error-to-mdx-server
- Loading branch information
Showing
7 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
demisto_sdk/commands/validate/validators/IM_validators/IM108_author_image_is_empty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
] |