diff --git a/tests/mock/napalm_get_interfaces/post.json b/tests/mock/napalm_get_interfaces/post.json new file mode 100644 index 0000000..231ca1d --- /dev/null +++ b/tests/mock/napalm_get_interfaces/post.json @@ -0,0 +1,38 @@ +{ + ".local.": { + "description": "", + "is_enabled": false, + "is_up": false, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + }, + ".local..0": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + }, + ".local..1": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + }, + ".local..2": { + "description": "", + "is_enabled": false, + "is_up": false, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + } +} \ No newline at end of file diff --git a/tests/mock/napalm_get_interfaces/pre.json b/tests/mock/napalm_get_interfaces/pre.json new file mode 100644 index 0000000..8f9b273 --- /dev/null +++ b/tests/mock/napalm_get_interfaces/pre.json @@ -0,0 +1,38 @@ +{ + ".local.": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + }, + ".local..0": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + }, + ".local..1": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + }, + ".local..2": { + "description": "", + "is_enabled": true, + "is_up": true, + "last_flapped": -1, + "mac_address": "Unspecified", + "mtu": 0, + "speed": -1 + } +} \ No newline at end of file diff --git a/tests/test_get_value.py b/tests/test_get_value.py index 737a12a..e84db8d 100644 --- a/tests/test_get_value.py +++ b/tests/test_get_value.py @@ -14,3 +14,4 @@ def test_jmspath_return_none(data): extract_data_from_json(data=data, path=my_jmspath)() # pylint: disable=E0110 assert "JMSPath returned 'None'. Please, verify your JMSPath regex." in error.value.__str__() + diff --git a/tests/test_issues.py b/tests/test_issues.py new file mode 100644 index 0000000..01c2ca4 --- /dev/null +++ b/tests/test_issues.py @@ -0,0 +1,34 @@ +"""jdiff github issues unit tests.""" +import pytest +import jdiff +from jdiff import extract_data_from_json, CheckType +from .utility import load_mocks, ASSERT_FAIL_MESSAGE + +issue_91 = ( + "napalm_get_interfaces", + "exact_match", + {}, + "$*$.[is_up,is_enabled]", + ( + {}, + False, + ), +) + +check_tests = [ + issue_91, +] + + +@pytest.mark.parametrize("folder_name, check_type_str, evaluate_args, path, expected_result", check_tests) +def test_checks(folder_name, check_type_str, evaluate_args, path, expected_result): + """Validate multiple checks on the same data to catch corner cases.""" + check = CheckType.create(check_type_str) + pre_data, post_data = load_mocks(folder_name) + pre_value = extract_data_from_json(pre_data, path) + post_value = extract_data_from_json(post_data, path) + actual_results = check.evaluate(pre_value, post_value, **evaluate_args) + + assert actual_results == expected_result, ASSERT_FAIL_MESSAGE.format( + output=actual_results, expected_output=expected_result + )