-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 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: Added the MR100 to the new validation format. Validates that the modeling rules has a schema file. | ||
type: internal | ||
pr_number: 4331 |
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,29 @@ | ||
from demisto_sdk.commands.validate.tests.test_tools import ( | ||
create_modeling_rule_object, | ||
) | ||
from demisto_sdk.commands.validate.validators.MR_validators.MR100_validate_schema_file_exists import ( | ||
ValidateSchemaFileExistsValidator, | ||
) | ||
|
||
|
||
def test_ValidateSchemaFileExistsValidator_is_valid(): | ||
""" | ||
Given: | ||
- Modeling Rules content items | ||
When: | ||
- run is_valid method | ||
Then: | ||
- Ensure that no ValidationResult returned when schema file exists. | ||
- Ensure that the ValidationResult returned when there is no schema file. | ||
""" | ||
modeling_rule = create_modeling_rule_object() | ||
# Valid | ||
assert not ValidateSchemaFileExistsValidator().is_valid([modeling_rule]) | ||
|
||
# Schema file does not exist | ||
modeling_rule.schema_file.exist = False | ||
results = ValidateSchemaFileExistsValidator().is_valid([modeling_rule]) | ||
assert ( | ||
'The modeling rule "Duo Modeling Rule" is missing a schema file.' | ||
== results[0].message | ||
) |
31 changes: 31 additions & 0 deletions
31
demisto_sdk/commands/validate/validators/MR_validators/MR100_validate_schema_file_exists.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,31 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List | ||
|
||
from demisto_sdk.commands.content_graph.objects.modeling_rule import ModelingRule | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = ModelingRule | ||
|
||
|
||
class ValidateSchemaFileExistsValidator(BaseValidator[ContentTypes]): | ||
error_code = "MR100" | ||
description = "Validate that each modeling rule has a corresponding schema file." | ||
rationale = "For each modeling rule, there has to be schema file." | ||
error_message = 'The modeling rule "{0}" is missing a schema file.' | ||
related_field = "modeling rule" | ||
is_auto_fixable = False | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
return [ | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message.format(content_item.name), | ||
content_object=content_item, | ||
) | ||
for content_item in content_items | ||
if (not content_item.schema_file.exist) | ||
] |