Skip to content

Commit

Permalink
test: ADDON-59948 Added test cases for Multi-level menu (#657)
Browse files Browse the repository at this point in the history
* ci: update agreements CLA to 1.3 (#650)

* test: ADDON-59948 Added test cases for multilevel menu

* test: simplify test samples

---------

Co-authored-by: Artem Rys <rysartem@gmail.com>
  • Loading branch information
tbalar-splunk and artemrys authored Feb 20, 2023
1 parent c1c4e49 commit b86426f
Show file tree
Hide file tree
Showing 5 changed files with 673 additions and 0 deletions.
42 changes: 42 additions & 0 deletions splunk_add_on_ucc_framework/global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,47 @@ def _validate_autoCompleteFields_duplicates(
f"Duplicates found for autoCompleteFields: '{entity_label}'"
)

def _validate_multilevel_menu(self) -> None:
inputs = self._config.get("pages").get("inputs")
if inputs:
groups_menu = inputs.get("groupsMenu")
if groups_menu:
names, titles = [], []
for group in groups_menu:
names.append(group.get("groupName").lower())
titles.append(group.get("groupTitle").lower())
group_services = group.get("groupServices")
if group_services:
for serviceName in group_services:
if not any(
serviceName == service.get("name")
for service in inputs.get("services")
):
raise GlobalConfigValidatorException(
f"{serviceName} ServiceName in the "
f"multi-level menu does not match any "
f"services name."
)
else:
if not any(
group.get("groupName") == service.get("name")
and group.get("groupTitle") == service.get("title")
for service in inputs.get("services")
):
raise GlobalConfigValidatorException(
f'{group.get("groupName")} groupName or '
f'{group.get("groupTitle")} groupTitle in the '
f"multi-level menu does not match any services "
f"name or title."
)

if self._find_duplicates_in_list(
names
) or self._find_duplicates_in_list(titles):
raise GlobalConfigValidatorException(
"Duplicates found for multi-level menu groups' names or titles."
)

def _validate_entity_duplicates(self, entity: list) -> None:
"""
Validates duplicates in entity keys
Expand Down Expand Up @@ -350,4 +391,5 @@ def validate(self) -> None:
self._validate_custom_rest_handlers()
self._validate_file_type_entity()
self._validate_validators()
self._validate_multilevel_menu()
self._validate_duplicates()
25 changes: 25 additions & 0 deletions tests/unit/test_global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,31 @@ def test_config_validation_when_valid(filename, is_yaml):
pytest.raises(GlobalConfigValidatorException),
"Duplicates found for autoCompleteFields: 'Single Select'",
),
(
"invalid_config_inputs_multilevel_menu_duplicate_groups.json",
False,
pytest.raises(GlobalConfigValidatorException),
"Duplicates found for multi-level menu groups' names or titles.",
),
(
"invalid_config_inputs_multilevel_menu_invalid_groupservices.json",
False,
pytest.raises(GlobalConfigValidatorException),
(
"example_input_three ServiceName in the multi-level menu does "
"not match any services name."
),
),
(
"invalid_config_inputs_multilevel_menu_invalid_groupname_or_grouptitle.json",
False,
pytest.raises(GlobalConfigValidatorException),
(
"example_input_three groupName or Example Input Three "
"groupTitle in the multi-level menu does not match any "
"services name or title."
),
),
],
)
def test_config_validation_when_error(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"pages": {
"configuration": {
"tabs": [
{
"name": "logging",
"entity": [
{
"type": "singleSelect",
"label": "Log level",
"options": {
"disableSearch": true,
"autoCompleteFields": [
{
"value": "DEBUG",
"label": "DEBUG"
},
{
"value": "INFO",
"label": "INFO"
},
{
"value": "WARNING",
"label": "WARNING"
},
{
"value": "ERROR",
"label": "ERROR"
},
{
"value": "CRITICAL",
"label": "CRITICAL"
}
]
},
"defaultValue": "INFO",
"field": "loglevel"
}
],
"title": "Logging"
}
],
"title": "Configuration",
"description": "Set up your add-on"
},
"inputs": {
"services": [
{
"hook": {
"src": "Hook"
},
"name": "example_input_one",
"entity": [
{
"type": "text",
"label": "Name",
"validators": [
{
"type": "regex",
"errorMsg": "Input Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.",
"pattern": "^[a-zA-Z]\\w*$"
},
{
"type": "string",
"errorMsg": "Length of input name should be between 1 and 100",
"minLength": 1,
"maxLength": 100
}
],
"field": "name",
"help": "A unique name for the data input.",
"required": true
}
],
"title": "Example Input One"
},
{
"name": "example_input_two",
"entity": [
{
"type": "text",
"label": "Name",
"validators": [
{
"type": "regex",
"errorMsg": "Input Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.",
"pattern": "^[a-zA-Z]\\w*$"
},
{
"type": "string",
"errorMsg": "Length of input name should be between 1 and 100",
"minLength": 1,
"maxLength": 100
}
],
"field": "name",
"help": "A unique name for the data input.",
"required": true
}
],
"title": "Example Input Two"
}
],
"title": "Inputs",
"description": "Manage your data inputs",
"table": {
"actions": [
"edit",
"enable",
"delete",
"clone"
],
"header": [
{
"label": "Name",
"field": "name"
},
{
"label": "Account Name",
"field": "account"
},
{
"label": "Interval",
"field": "interval"
},
{
"label": "Index",
"field": "index"
},
{
"label": "Status",
"field": "disabled"
}
],
"moreInfo": [
{
"label": "Name",
"field": "name"
},
{
"label": "Interval",
"field": "interval"
},
{
"label": "Index",
"field": "index"
},
{
"label": "Status",
"field": "disabled",
"mapping": {
"true": "Disabled",
"false": "Enabled"
}
},
{
"label": "Example Account",
"field": "account"
},
{
"label": "Object",
"field": "object"
},
{
"label": "Object Fields",
"field": "object_fields"
},
{
"label": "Order By",
"field": "order_by"
},
{
"label": "Query Start Date",
"field": "start_date"
},
{
"label": "Limit",
"field": "limit"
}
]
},
"groupsMenu": [
{
"groupName": "group_one",
"groupTitle": "Group One",
"groupServices": ["example_input_one", "example_input_two"]
},
{
"groupName": "group_one",
"groupTitle": "Group One",
"groupServices": ["example_input_one", "example_input_two"]
}
]

}
},
"meta": {
"apiVersion": "3.2.0",
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "1.0.0",
"displayName": "Splunk UCC test Add-on"
}
}
Loading

0 comments on commit b86426f

Please sign in to comment.