Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuel44 committed Nov 14, 2024
1 parent 7de48ea commit 9983f5d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ def get_items_using_deprecated(
def get_items_using_deprecated_commands(
tx: Transaction, file_paths: List[str]
) -> List[Tuple[str, str, List[graph.Node]]]:
files_filter = (
f"AND (p.path in {file_paths} OR i.path IN {file_paths})" if file_paths else ""
)
files_filter = f"AND p.path IN {file_paths}" if file_paths else ""

command_query = f"""// Returning all the items which using deprecated commands
MATCH (p{{deprecated: false}})-[:USES]->(c:Command)<-[:HAS_COMMAND{{deprecated: true}}]-(i:Integration) WHERE NOT p.is_test
OPTIONAL MATCH (i2:Integration)-[:HAS_COMMAND{{deprecated: false}}]->(c)
Expand All @@ -143,9 +142,8 @@ def get_items_using_deprecated_commands(
def get_items_using_deprecated_content_items(
tx: Transaction, file_paths: List[str]
) -> List[Tuple[str, str, List[graph.Node]]]:
files_filter = (
f"AND (p.path IN {file_paths} OR d.path IN {file_paths})" if file_paths else ""
)
files_filter = f"AND p.path IN {file_paths}" if file_paths else ""

query = f"""
MATCH (p{{deprecated: false}})-[:USES]->(d{{deprecated: true}}) WHERE not p.is_test
// be sure the USES relationship is not because a command, as commands has dedicated query
Expand Down
32 changes: 31 additions & 1 deletion demisto_sdk/commands/validate/tests/GR_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def test_GR107_IsDeprecatedContentItemInUsageValidatorListFiles_invalid_script(
assert len(validation_results) == 1


def test_GR107_IsDeprecatedContentItemInUsageValidatorListFiles_valid(
def test_GR107_IsDeprecatedContentItemInUsageValidatorListFiles_valid_script(
repo_for_test_gr_107: Repo,
):
"""
Expand Down Expand Up @@ -718,6 +718,36 @@ def test_GR107_IsDeprecatedContentItemInUsageValidatorListFiles_valid(
assert len(validation_results) == 0


def test_GR107_IsDeprecatedContentItemInUsageValidatorListFiles_valid_playbook(
repo_for_test_gr_107: Repo,
):
"""
Test the GR107_IsDeprecatedContentItemInUsageValidatorListFiles validator for a valid script.
Given:
- A repository with a deprecated playbook and an integration that uses the deprecated playbook.
The deprecated playbook does not use any deprecated content items.
When:
- Running the GR107_IsDeprecatedContentItemInUsageValidatorListFiles on the specific script.
Then:
- Verify that the validator correctly identifies that no deprecated content items are used.
- Assert that the validation results are empty.
"""
graph_interface = repo_for_test_gr_107.create_graph()
BaseValidator.graph_interface = graph_interface

pack_objects = [
repo_for_test_gr_107.packs[1].playbooks[1].get_graph_object(graph_interface),
]
validation_results = GR107_IsDeprecatedContentItemInUsageValidatorListFiles().obtain_invalid_content_items(
pack_objects
)

assert len(validation_results) == 0


def test_GR107_IsDeprecatedContentItemInUsageValidatorAllFiles_is_invalid(
repo_for_test_gr_107: Repo,
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class IsDeprecatedContentItemInUsageValidator(BaseValidator[ContentTypes], ABC):
"Validates that deprecated content items are not used in other content items."
)
rationale = "Using deprecated content items can lead to unexpected behavior and should be avoided."
error_message = "The {deprecated_item_type} '{deprecated_item}' is deprecated but used in the following content item: {using_deprecated_item}."
error_message = "The item '{using_deprecated_item}' is using the following deprecated {deprecated_item_type}: {deprecated_item}"
related_field = "deprecated"
is_auto_fixable = False

Expand Down

0 comments on commit 9983f5d

Please sign in to comment.