This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
catalystwan/integration_tests/test_find_template_values.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import unittest | ||
from typing import Any, List, cast | ||
|
||
from catalystwan.session import create_manager_session | ||
from catalystwan.utils.feature_template.find_template_values import find_template_values | ||
|
||
|
||
class TestFindTemplateValues(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.session = create_manager_session( | ||
url=cast(str, os.environ.get("TEST_VMANAGE_URL")), | ||
port=cast(int, int(os.environ.get("TEST_VMANAGE_PORT"))), # type: ignore | ||
username=cast(str, os.environ.get("TEST_VMANAGE_USERNAME")), | ||
password=cast(str, os.environ.get("TEST_VMANAGE_PASSWORD")), | ||
) | ||
self.templates = self.session.api.templates._get_feature_templates() | ||
|
||
def test_find_template_value(self): | ||
for template in self.templates: | ||
definition = template.template_definiton | ||
with self.subTest(template_name=template.name): | ||
parsed_values = find_template_values(definition) | ||
self.assertFalse( | ||
self.is_key_present(parsed_values, ["vipType", "vipValue", "vipVariableName", "vipObjectType"]) | ||
) | ||
|
||
def is_key_present(self, d: dict, keys: List[Any]): | ||
""" | ||
Checks if any key from keys is present within the dictionary d | ||
""" | ||
for key, value in d.items(): | ||
if key in keys: | ||
return True | ||
if isinstance(value, dict): | ||
if self.is_key_present(value, keys): | ||
return True | ||
if isinstance(value, list): | ||
for v in value: | ||
if self.is_key_present(v, keys): | ||
return True | ||
return False | ||
|
||
def tearDown(self) -> None: | ||
self.session.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters