Skip to content

Commit

Permalink
Merge ea5ec50 into 3ecdf20
Browse files Browse the repository at this point in the history
  • Loading branch information
Shellyber committed Jun 10, 2024
2 parents 3ecdf20 + ea5ec50 commit f297883
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changelog/4331.yml
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
2 changes: 2 additions & 0 deletions demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ select = [
"DA100", "DA101",
"RP101", "BC106", "BC107",
"IT100", "IT101", "IT102", "IT103",
"MR100",
]
warning = []

Expand All @@ -67,6 +68,7 @@ select = [
"RP101",
"IT102", "IT103",
"RP101",
"MR100",
]
warning = ["IN101"]

Expand Down
29 changes: 29 additions & 0 deletions demisto_sdk/commands/validate/tests/MR_validators_test.py
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
)
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)
]

0 comments on commit f297883

Please sign in to comment.