Skip to content

Commit

Permalink
Moved removed_integration_parameters to new validations (#4354)
Browse files Browse the repository at this point in the history
* added removed_integration_parameters

* added to toml

* Update demisto_sdk/commands/validate/sdk_validation_config.toml

Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com>

* pre-commit issues fixed

* pre-commit issues fixed

* RN

---------

Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com>
  • Loading branch information
jlevypaloalto and YuvHayun committed Jun 17, 2024
1 parent 11d1731 commit f232b29
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changelog/4354.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added the `removed_integration_parameter` validation to the new validate as `NoRemovedIntegrationParametersValidator`.
type: internal
pr_number: 4354
2 changes: 1 addition & 1 deletion demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ select = [
"BA100", "BA101", "BA105", "BA106", "BA108", "BA109", "BA110", "BA111", "BA114", "BA116", "BA118", "BA119", "BA124", "BA125", "BA126",
"PA100", "PA101", "PA102", "PA103", "PA104", "PA105", "PA107", "PA108", "PA109", "PA111", "PA113", "PA115", "PA117", "PA118", "PA119", "PA120",
"PA121", "PA123", "PA125", "PA127", "PA128", "PA130", "PA131", "PA132",
"BC100", "BC101", "BC102", "BC103", "BC104", "BC105", "BC106", "BC107", "BC108", "BC110", "BC111",
"BC100", "BC101", "BC102", "BC103", "BC104", "BC105", "BC106", "BC107", "BC108", "BC110", "BC111", "BC112",
"IN100", "IN101", "IN102", "IN104", "IN106", "IN107", "IN108", "IN109", "IN110", "IN112", "IN113", "IN114", "IN115", "IN117", "IN118", "IN121", "IN122", "IN123", "IN124", "IN125", "IN126", "IN127", "IN130",
"IN131", "IN134", "IN135", "IN139", "IN141", "IN142", "IN144", "IN145", "IN146", "IN149", "IN150", "IN151", "IN152", "IN153", "IN154", "IN156", "IN158", "IN159", "IN160",
"IN161", "IN162",
Expand Down
53 changes: 53 additions & 0 deletions demisto_sdk/commands/validate/tests/BC_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
from demisto_sdk.commands.validate.validators.BC_validators.BC111_new_required_argument_script import (
NewRequiredArgumentScriptValidator,
)
from demisto_sdk.commands.validate.validators.BC_validators.BC112_no_removed_integration_parameters import (
NoRemovedIntegrationParametersValidator,
)
from TestSuite.repo import ChangeCWD

ALL_MARKETPLACES = list(MarketplaceVersions)
Expand Down Expand Up @@ -1324,3 +1327,53 @@ def test_NewRequiredArgumentScriptValidator__passes(new_args):

create_old_file_pointers([new_content_item], [old_content_item])
assert not NewRequiredArgumentScriptValidator().is_valid([new_content_item])


def test_has_removed_integration_parameters_with_changed_params():
"""
Given
- integration configuration with changed parameters.
When
- running the validation no_removed_integration_parameters.
Then
- return a ValidationResult with a list of missing parameters.
"""
new_item = create_integration_object(
paths=["configuration"], values=[[{"name": "param_3"}, {"name": "param_4"}]]
)
new_item.old_base_content_object = create_integration_object(
paths=["configuration"],
values=[[{"name": "param_1"}, {"name": "param_2"}, {"name": "param_3"}]],
)

res = NoRemovedIntegrationParametersValidator().is_valid([new_item])

assert (

Check failure on line 1353 in demisto_sdk/commands/validate/tests/BC_validators_test.py

View workflow job for this annotation

GitHub Actions / Unit Tests / Python 3.8

test_has_removed_integration_parameters_with_changed_params assert "Parameters h...', 'param_2'." == "Parameters h...', 'param_1'." - Parameters have been removed from the integration, the removed parameters are: 'param_2', 'param_1'. ? ----------- + Parameters have been removed from the integration, the removed parameters are: 'param_1', 'param_2'. ? +++++++++++

Check failure on line 1353 in demisto_sdk/commands/validate/tests/BC_validators_test.py

View workflow job for this annotation

GitHub Actions / Unit Tests / Python 3.9

test_has_removed_integration_parameters_with_changed_params assert "Parameters h...', 'param_2'." == "Parameters h...', 'param_1'." - Parameters have been removed from the integration, the removed parameters are: 'param_2', 'param_1'. ? ----------- + Parameters have been removed from the integration, the removed parameters are: 'param_1', 'param_2'. ? +++++++++++

Check failure on line 1353 in demisto_sdk/commands/validate/tests/BC_validators_test.py

View workflow job for this annotation

GitHub Actions / Unit Tests / Python 3.10

test_has_removed_integration_parameters_with_changed_params assert "Parameters h...', 'param_2'." == "Parameters h...', 'param_1'." - Parameters have been removed from the integration, the removed parameters are: 'param_2', 'param_1'. ? ----------- + Parameters have been removed from the integration, the removed parameters are: 'param_1', 'param_2'. ? +++++++++++

Check failure on line 1353 in demisto_sdk/commands/validate/tests/BC_validators_test.py

View workflow job for this annotation

GitHub Actions / Unit Tests / Python 3.11

test_has_removed_integration_parameters_with_changed_params assert "Parameters h...', 'param_2'." == "Parameters h...', 'param_1'." - Parameters have been removed from the integration, the removed parameters are: 'param_2', 'param_1'. ? ----------- + Parameters have been removed from the integration, the removed parameters are: 'param_1', 'param_2'. ? +++++++++++
res[0].message
== "Parameters have been removed from the integration, the removed parameters are: 'param_2', 'param_1'."
)


def test_has_removed_integration_parameters_without_changed_params():
"""
Given
- integration configuration with no changed parameters.
When
- running the validation no_removed_integration_parameters.
Then
- return an empty list.
"""
new_item = create_integration_object(
paths=["configuration"], values=[[{"name": "param_1"}, {"name": "param_2"}]]
)
new_item.old_base_content_object = create_integration_object(
paths=["configuration"], values=[[{"name": "param_1"}, {"name": "param_2"}]]
)

res = NoRemovedIntegrationParametersValidator().is_valid([new_item])

assert res == []
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

from typing import Iterable, List, cast

from demisto_sdk.commands.common.constants import GitStatuses
from demisto_sdk.commands.content_graph.objects.integration import Integration
from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)

ContentTypes = Integration


class NoRemovedIntegrationParametersValidator(BaseValidator[ContentTypes]):
error_code = "BC112"
description = "Ensure that no parameters are removed from an existing integration."
rationale = "Removed parameters can cause errors if the parameter is needed by the server of integration code."
error_message = "Parameters have been removed from the integration, the removed parameters are: {}."
related_field = "configuration"
is_auto_fixable = False
expected_git_statuses = [GitStatuses.MODIFIED]
related_file_type = [RelatedFileType.YML]

def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
return [
ValidationResult(
validator=self,
message=self.error_message.format(", ".join(map(repr, difference))),
content_object=content_item,
)
for content_item in content_items
if (
difference := self.removed_parameters(
cast(ContentTypes, content_item.old_base_content_object),
content_item,
)
)
]

def removed_parameters(self, old_item: ContentTypes, new_item: ContentTypes) -> set:
old_params = {param.name for param in old_item.params}
new_params = {param.name for param in new_item.params}
return old_params.difference(new_params)

0 comments on commit f232b29

Please sign in to comment.