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

YR/-BC-104-New-format-validation/CIAC-10001 #4187

Merged
merged 49 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
439e029
testing
RosenbergYehuda Mar 13, 2024
78006c6
ruff
RosenbergYehuda Mar 18, 2024
d2a9b58
Merge remote-tracking branch 'origin/master' into YR/test-graph-was-c…
RosenbergYehuda Mar 18, 2024
7b25809
try
RosenbergYehuda Mar 18, 2024
24abd13
exclude None
RosenbergYehuda Mar 18, 2024
b1d729e
try
RosenbergYehuda Mar 18, 2024
e181f53
Merge remote-tracking branch 'origin/master' into YR/test-graph-was-c…
RosenbergYehuda Mar 18, 2024
b8e0d4f
remove
RosenbergYehuda Mar 19, 2024
c999bbb
Merge remote-tracking branch 'origin/master' into YR/test-graph-was-c…
RosenbergYehuda Mar 19, 2024
b171757
add name to the object
RosenbergYehuda Mar 19, 2024
816f9d0
Merge remote-tracking branch 'origin/master' into YR/test-graph-was-c…
RosenbergYehuda Mar 19, 2024
8563070
changelog
RosenbergYehuda Mar 19, 2024
376fe6c
try
RosenbergYehuda Mar 19, 2024
c40a12c
add test
RosenbergYehuda Mar 19, 2024
58c5601
Merge remote-tracking branch 'origin/master' into YR/test-graph-was-c…
RosenbergYehuda Mar 19, 2024
1cd4217
Merge remote-tracking branch 'origin/master' into YR/test-graph-was-c…
RosenbergYehuda Mar 19, 2024
71ee331
init
RosenbergYehuda Mar 26, 2024
d472c24
per command
RosenbergYehuda Mar 26, 2024
6b2ab2d
fix
RosenbergYehuda Mar 26, 2024
955466a
Merge remote-tracking branch 'origin/master' into YR/-BC-104-New-form…
RosenbergYehuda Mar 27, 2024
07234ce
tomel
RosenbergYehuda Mar 27, 2024
a7f1e5c
revert
RosenbergYehuda Mar 27, 2024
17eefbc
Merge remote-tracking branch 'origin/master' into YR/-BC-104-New-form…
RosenbergYehuda Mar 27, 2024
985ab39
try
RosenbergYehuda Mar 27, 2024
5780d3a
tomel
RosenbergYehuda Mar 27, 2024
3e16a9a
better
RosenbergYehuda Mar 27, 2024
f03ed6d
better
RosenbergYehuda Mar 27, 2024
2930fe5
remove function to tools
RosenbergYehuda Mar 27, 2024
134648e
fix
RosenbergYehuda Mar 27, 2024
4fb286d
push
RosenbergYehuda Mar 28, 2024
d919d2a
fix test
RosenbergYehuda Apr 1, 2024
5def3fa
fixes
RosenbergYehuda Apr 1, 2024
e2c2744
init
RosenbergYehuda Apr 2, 2024
8026dd4
test
RosenbergYehuda Apr 2, 2024
b82e56b
cr
RosenbergYehuda Apr 3, 2024
0a4fff2
cr
RosenbergYehuda Apr 4, 2024
2859cf5
cr
RosenbergYehuda Apr 4, 2024
8cf1e4e
cr
RosenbergYehuda Apr 4, 2024
2b71f4c
merge origin master
RosenbergYehuda Apr 4, 2024
fa6f3ac
fix
RosenbergYehuda Apr 4, 2024
858b6d2
change name
RosenbergYehuda Apr 4, 2024
231f276
cr
RosenbergYehuda Apr 11, 2024
a14bb64
Merge remote-tracking branch 'origin/master' into YR/-BC-104-New-form…
RosenbergYehuda Apr 11, 2024
bfce346
comment
RosenbergYehuda Apr 11, 2024
c4eedf2
cr
RosenbergYehuda Apr 13, 2024
38bf9b2
Merge remote-tracking branch 'origin' into YR/-BC-104-New-format-vali…
RosenbergYehuda Apr 13, 2024
021b065
Merge remote-tracking branch 'origin' into YR/-BC-104-New-format-vali…
RosenbergYehuda Apr 14, 2024
7a77524
fix
RosenbergYehuda Apr 14, 2024
a6cb351
add comma
RosenbergYehuda Apr 14, 2024
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", "BA110", "BA111", "BA114", "BA116", "BA118", "BA119", "BA124", "BA126",
"PA100", "PA101", "PA102", "PA103", "PA104", "PA105", "PA107", "PA108", "PA109", "PA111", "PA113", "PA115", "PA117", "PA118", "PA119", "PA120",
"PA121", "PA123", "PA125", "PA127", "PA128", "PA130",
"BC100", "BC101", "BC102", "BC105", "BC108",
"BC100", "BC101", "BC102", "BC104", "BC105", "BC108", "BC110"
RosenbergYehuda 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
229 changes: 229 additions & 0 deletions demisto_sdk/commands/validate/tests/BC_validators_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from typing import List

import pytest
Expand All @@ -24,6 +25,9 @@
from demisto_sdk.commands.validate.validators.BC_validators.BC102_is_context_path_changed import (
IsContextPathChangedValidator,
)
from demisto_sdk.commands.validate.validators.BC_validators.BC104_have_commands_or_args_name_changed import (
HaveCommandsOrArgsNameChangedValidator,
)
from demisto_sdk.commands.validate.validators.BC_validators.BC105_id_changed import (
IdChangedValidator,
)
Expand All @@ -33,6 +37,9 @@
from demisto_sdk.commands.validate.validators.BC_validators.BC108_was_marketplace_modified import (
WasMarketplaceModifiedValidator,
)
from demisto_sdk.commands.validate.validators.BC_validators.BC110_new_required_argument import (
NewRequiredArgumentValidator,
)
from TestSuite.repo import ChangeCWD

ALL_MARKETPLACES = list(MarketplaceVersions)
Expand All @@ -43,6 +50,53 @@
XSOAR_MARKETPLACE_FOR_IN_PACK = [ALL_MARKETPLACES_FOR_IN_PACK[0]]


# Create a new content item with 3 commands with unique names. all commands have only 1 argument except the third command which has 2 arguments.
generic_integration_with_3_commands_and_4_args = create_integration_object(
paths=["script.commands"],
values=[
[
{
"name": "command_1",
"description": "test",
"arguments": [
{
"name": "arg_1_command_1",
"description": "nothing description.",
}
],
"outputs": [],
},
{
"name": "command_2",
"description": "test",
"arguments": [
{
"name": "arg_1_command_2",
"description": "nothing description.",
}
],
"outputs": [],
},
{
"name": "command_3",
"description": "test",
"arguments": [
{
"name": "arg_1_command_3",
"description": "nothing description.",
},
{
"name": "arg_2_command_3",
"description": "nothing description.",
},
],
"outputs": [],
},
]
],
)


RosenbergYehuda marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize(
"content_items, old_content_items, expected_number_of_failures, expected_msgs",
[
Expand Down Expand Up @@ -891,3 +945,178 @@ def test_IsContextPathChangedValidator_remove_command():
f"Command {command_name} has been removed from the integration. This is a breaking change, and is not allowed."
in errors[0].message
)


def test_HaveCommandsOrArgsNameChangedValidator__fails():
"""
Given
- A new content item with 3 commands. all commands have only 1 argument except the third command which has 2 arguments.
- An old content item with the same structure as the new content item, but with different command and argument names.
When
- Calling the HaveCommandsOrArgsNameChangedValidator.
Then
- Make sure the validation fails and the right error message is returned notifying only on changes in the second command name, and third command argument name.
- The first command has no changes.
- The second command name has changed from 'old_command_1' to 'command_1', and its arg name has changed from 'oldarg_1_command_1' to 'arg_1_command_1.
(the args change souled be ignored since we reported on its command name change.)
- The third command name has not changed, but one of its arguments name has changed from 'old_arg_1_command_2' to 'arg_1_command_2'.

"""
# Setup new content item with changes in command and argument names
new_content_item = generic_integration_with_3_commands_and_4_args

# Setup old content item with original command and argument names
old_content_item = deepcopy(new_content_item)
old_content_item.commands[1].name = "old_command_1"
old_content_item.commands[1].args[0].name = "old_arg_1_command_1"
old_content_item.commands[2].args[0].name = "old_arg_1_command_2"

# Create old file pointers and validate
create_old_file_pointers([new_content_item], [old_content_item])
results = HaveCommandsOrArgsNameChangedValidator().is_valid([new_content_item])

assert (
'changes to the names of the following existing commands:"old_command_1". In addition, you have made changes to the names of existing arguments: In command "command_3" the following arguments have been changed: "old_arg_1_command_2".'
in results[0].message
)


def test_HaveCommandsOrArgsNameChangedValidator__passes():
"""
Given
- An old content item with 3 commands. all commands have only 1 argument except the third command which has 2 arguments.
- A new content item with the same structure as the old content item, but with addition of a new argument to the third command, and a new command as well.
When
- Calling the HaveCommandsOrArgsNameChangedValidator.
Then
- Make sure the validation passes and no error messages are returned, since adding new commands or arguments is allowed.
"""
# Setup new content item with changes in command and argument names
old_content_item = generic_integration_with_3_commands_and_4_args
new_content_item = deepcopy(old_content_item)

new_content_item.commands.append(
create_integration_object(
paths=["script.commands"], values=[[{"name": "command_4"}]]
).commands[0]
)
# add a new argument to the third command
new_content_item.commands[2].args.append(
create_integration_object(
paths=[
"script.commands",
],
values=[
[
{
"name": "command_1",
"description": "test",
"arguments": [
{
"name": "arg_3_command_1",
}
],
"outputs": [],
}
]
],
)
.commands[0]
.args[0]
)

# Setup old content item with original command and argument names
old_content_item = generic_integration_with_3_commands_and_4_args

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


def test_NewRequiredArgumentValidator__fails():
"""
Given
- A old content item with 3 commands. all commands have only 1 argument except the third command which has 2 arguments.
- A new content item with the same structure as the old content item, but with changes in the second command argument to be required and a new required argument in the third command.
When
- Calling the NewRequiredArgumentValidator.
Then
- Make sure the validation fails and the right error message is returned notifying on the new required argument in the second command and the third command.
"""
old_content_item = generic_integration_with_3_commands_and_4_args
new_content_item = deepcopy(old_content_item)
# add new required arg
new_content_item.commands[2].args.append(
create_integration_object(
paths=[
"script.commands",
],
values=[
[
{
"name": "test_command",
"arguments": [
{
"name": "arg_3_command_3",
"required": True,
}
],
}
]
],
)
.commands[0]
.args[0]
)

# change existing arg to be required
new_content_item.commands[1].args[0].required = True

create_old_file_pointers([new_content_item], [old_content_item])
res = NewRequiredArgumentValidator().is_valid([new_content_item])

assert (
"added the following new *required* arguments: in command 'command_2' you have added a new required argument:'arg_1_command_2'. in command 'command_3' you have added a new required argument:'arg_3_command_1'."
in res[0].message
)


def test_NewRequiredArgumentValidator__passes():
"""
Given
- A old content item with 3 commands. all commands have only 1 argument except the third command which has 2 arguments.
- A new content item with the same structure as the old content item, but with changes in the second command argument to be required and a new required argument in the new forth command with a required argument.
When
- Calling the NewRequiredArgumentValidator.
Then
- Make sure the validation passes and no error messages are returned, since adding new required arguments is allowed
if the new required argument is in a new command or if it has a default value.
"""
new_content_item = deepcopy(generic_integration_with_3_commands_and_4_args)
# change existing arg to be required but add a default value
new_content_item.commands[1].args[0].required = True
new_content_item.commands[1].args[0].defaultvalue = "test"
# add new command with required arg without a default value
new_content_item.commands.append(
create_integration_object(
paths=[
"script.commands",
],
values=[
[
{
"name": "command_4",
"arguments": [
{
"name": "arg_1_command_4",
"required": True,
}
],
}
]
],
).commands[0]
)
old_content_item = generic_integration_with_3_commands_and_4_args
create_old_file_pointers([new_content_item], [old_content_item])

assert not NewRequiredArgumentValidator().is_valid([new_content_item])
18 changes: 18 additions & 0 deletions demisto_sdk/commands/validate/tests/tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from demisto_sdk.commands.validate.tools import (
collect_all_inputs_from_inputs_section,
collect_all_inputs_in_use,
compare_lists,
)


Expand Down Expand Up @@ -87,3 +88,20 @@ def test_collect_all_inputs_from_inputs_section(content_item, expected_result):
- A set with all inputs defined in the inputs section with no duplicates or empty spaces are returned.
"""
assert collect_all_inputs_from_inputs_section(content_item) == expected_result


def test_compare_lists():
"""
Given:
- Two lists with some elements in common and some that are not.
When:
- Running compare_lists
Then:
- Return a list of the elements that are in the sub_list but not in the main_list, including duplicates if not all elements are in the main_list.
RosenbergYehuda marked this conversation as resolved.
Show resolved Hide resolved
"""
main_list = ["a", "b", "c"]
sub_list = ["a", "b", "b", "d"]
assert compare_lists(sub_list, main_list) == [
"b",
"d",
]
13 changes: 13 additions & 0 deletions demisto_sdk/commands/validate/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from collections import Counter
from pathlib import Path
from typing import Dict, List, Optional, Set

Expand Down Expand Up @@ -147,3 +148,15 @@ def find_command(commands: List[Command], command_to_find: str) -> Optional[Comm
if command.name == command_to_find:
return command
return None


def compare_lists(sub_list: List[str], main_list: List[str]) -> List[str]:
"""
Compares two lists and returns the elements that are in the sub list but not in the main list, including duplicates.
Args:
sub_list: list of elements to compare if they are a subset of main_list
main_list: the list to compare against
Returns:
List the elements that appear in the sublist but not in the main list, including duplicates if they are not all present in the main list.
"""
return list((Counter(sub_list) - Counter(main_list)).elements())
Loading