Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved removed_integration_parameters to new validations #4354

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
jlevypaloalto marked this conversation as resolved.
Show resolved Hide resolved
"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
52 changes: 52 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,52 @@ 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 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,41 @@

from __future__ import annotations

from typing import Iterable, List

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.RENAMED, 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(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)
Loading