Skip to content

Commit

Permalink
test: add tests for python utils and config validation (#1485)
Browse files Browse the repository at this point in the history
**Issue number:** N/A

### PR Type

**What kind of change does this PR introduce?**
* [ ] Feature
* [ ] Bug Fix
* [ ] Refactoring (no functional or API changes)
* [ ] Documentation Update
* [x] Maintenance (dependency updates, CI, etc.)

## Summary
Tests added for function `get_os_path` in `utils`
valid config check when using `useInputToggleConfirmation`
### Changes

Test cases added.

### User experience

N/A

## Checklist

If an item doesn't apply to your changes, leave it unchecked.

* [x] I have performed a self-review of this change according to the
[development
guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines)
* [x] Tests have been added/modified to cover the changes [(testing
doc)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test)
* [ ] Changes are documented
* [x] PR title and description follows the [contributing
principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests)
  • Loading branch information
soleksy-splunk authored Nov 26, 2024
1 parent 34c8ec2 commit 282e2ef
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/unit/test_global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,15 @@ def test_should_warn_on_empty_validators(schema_json):
field["validators"] = [number_validator]

assert not should_warn_on_empty_validators(oauth_entity)


def test_config_validation_status_toggle_confirmation():
global_config_path = helpers.get_testdata_file_path(
"valid_config_with_input_status_confirmation.json"
)
global_config = global_config_lib.GlobalConfig(global_config_path)

validator = GlobalConfigValidator(helpers.get_path_to_source_dir(), global_config)

with does_not_raise():
validator.validate()
14 changes: 14 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,17 @@ def test_dump_yaml_config(tmp_path):
content = f.read()

assert expected_content == content


@pytest.mark.parametrize(
"test_path,expected_path",
[
("/home/john/Test/test.txt", "home/john/Test/test.txt"),
("\\home\\john\\Test\\test.txt", "home/john/Test/test.txt"),
("\\\\home\\\\john\\\\Test\\\\test.txt", "home/john/Test/test.txt"),
],
)
def test_get_os_path(test_path, expected_path):
stripped_path = utils.get_os_path(test_path)

assert stripped_path == expected_path
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"pages": {
"configuration": {
"tabs": [
{
"name": "account",
"table": {
"actions": ["edit", "delete", "clone"],
"header": [
{
"label": "Name",
"field": "name"
}
]
},
"entity": [
{
"type": "text",
"label": "Name",
"validators": [
{
"type": "string",
"errorMsg": "Length of ID should be between 1 and 50",
"minLength": 1,
"maxLength": 50
},
{
"type": "regex",
"errorMsg": "Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.",
"pattern": "^[a-zA-Z]\\w*$"
}
],
"field": "name",
"help": "Enter a unique name for this account.",
"required": true
}
],
"title": "Account"
}
],
"title": "Configuration",
"description": "Set up your add-on"
},
"inputs": {
"title": "Status toggle confirmation test",
"services": [
{
"name": "example_input_one",
"title": "Input one status toggle confirmation test",
"entity": [
{
"type": "text",
"label": "Name",
"field": "name"
}
]
},
{
"name": "example_input_two",
"title": "Input two status toggle confirmation test",
"entity": [
{
"type": "text",
"label": "Name",
"field": "name"
}
]
}
],
"table": {
"actions": ["edit", "delete", "clone"],
"header": [
{
"label": "Name",
"field": "name"
}
]
},
"useInputToggleConfirmation": true
}
},
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.39.0Ra9e840a6",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.3",
"_uccVersion": "5.39.0"
}
}

0 comments on commit 282e2ef

Please sign in to comment.