-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat path evaluation #162
Open
josemtnzjmnz
wants to merge
6
commits into
develop
Choose a base branch
from
feat_pathEvaluation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat path evaluation #162
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
71d404a
Issue #99 solved, we must test the code meets the requirements to be …
josemtnzjmnz cede6a2
Some modifications and tests have been done.
josemtnzjmnz bbd5138
New test added.
josemtnzjmnz 253f573
Issue #99 solved. I have changed the method get_tag_value_in_given_di…
josemtnzjmnz 2c5b278
It was a file containing isolated tests of the feature/issue.
josemtnzjmnz b7d1b7c
Testing issue #99 successfully with another machine. Documentation ad…
josemtnzjmnz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
HOSTS = [ | ||
{ | ||
'host': '10.95.86.216', | ||
'port': '12022', | ||
'username': 'admin', | ||
'password': 'admin', | ||
'host': '10.95.86.212', | ||
'port': '830', | ||
'username': 'cisco', | ||
'password': 'cisco2020', | ||
}, | ||
] |
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 |
---|---|---|
|
@@ -93,7 +93,7 @@ def set_generic_values_after_commit(self): | |
self.edit_config_second_get_config_response.xml)[rpc_reply_key][data_key] | ||
for variable in self.generic_variables_to_commit: | ||
new_variable = {'test_case_key': variable['test_case_key'], | ||
'value_after_commit': self.get_tag_value_in_given_dict_by_path(parsed_dict=parsed_dict, | ||
'value_after_commit': self.get_unique_tag_value_in_given_dict_by_path(parsed_dict=parsed_dict, | ||
path=variable['path_list']), | ||
'path_string': variable['path_string'], | ||
'path_list': variable['path_list'], | ||
|
@@ -109,28 +109,79 @@ def set_generic_values_before_commit(self): | |
self.edit_config_first_get_config_response.xml)[rpc_reply_key][data_key] | ||
for variable in self.generic_variables_to_commit: | ||
new_variable = {'test_case_key': variable['test_case_key'], | ||
'value_before_commit': self.get_tag_value_in_given_dict_by_path(parsed_dict=parsed_dict, | ||
'value_before_commit': self.get_unique_tag_value_in_given_dict_by_path(parsed_dict=parsed_dict, | ||
path=variable['path_list']), | ||
'path_string': variable['path_string'], | ||
'path_list': variable['path_list'], | ||
} | ||
self.generic_values_before_commit.append(new_variable) | ||
|
||
def get_tag_value_in_given_dict_by_path(self, path, parsed_dict): | ||
def get_unique_tag_value_in_given_dict_by_path(self, path, parsed_dict): | ||
recursive_return = None | ||
if len(path) == 1: | ||
return parsed_dict[path[0]] | ||
else: | ||
try: | ||
if path[0] in parsed_dict: | ||
recursive_return = self.get_tag_value_in_given_dict_by_path(path=path[1:], | ||
recursive_return = self.get_unique_tag_value_in_given_dict_by_path(path=path[1:], | ||
parsed_dict=parsed_dict[path[0]]) | ||
else: | ||
raise Exception('The path specified for the param doesnt exists in the response') | ||
except: | ||
recursive_return = None | ||
return recursive_return | ||
|
||
def get_tag_value_in_given_dict_by_path(self, auxiliar_output_list, path, parsed_dict): | ||
# auxiliar_output_list: variable to store results in a list | ||
|
||
return_result = None # Initialize the output variable | ||
|
||
# When path length is 1 the workflow of the search is finished. | ||
# Parsed_dict here is the match with the end of the path; | ||
if len(path) == 1: | ||
auxiliar_output_list.append(parsed_dict) | ||
else: | ||
try: | ||
if isinstance(parsed_dict, | ||
list): # Usually this will be the first step (list or dict?) since path usually has length >1 | ||
path = path[1:] # Delete first level/position of the path | ||
for i in range(0, len(parsed_dict)): # Iterate the list of dictionaries (parsed_dict) | ||
subdict = parsed_dict[i] # Store a dictionary from the list | ||
if path[ | ||
0] in subdict: # If a match is found with the path then we are going to the next level of the path: | ||
return_result = self.get_tag_value_in_given_dict_by_path(auxiliar_output_list, path=path, | ||
parsed_dict=subdict[path[0]]) | ||
else: # Usually this will be a dictionary | ||
if path[0] in parsed_dict: # Check if the dictionary has a match with one of the levels of the path | ||
sublist = parsed_dict[ | ||
path[0]] # Store a list of dictionaries in a variable sublist (it could be subdict too) | ||
if isinstance(sublist, list): # Check if is a list or a dict (list if yes) | ||
path = path[1:] # Delete first position of the path | ||
for j in range(0, len(sublist)): # Iterate the list of dictionaries (sublist) | ||
subdict = sublist[j] # Store a dictionary from the list | ||
# If a match is found with the path then we are going to the next level of the path: | ||
return_result = self.get_tag_value_in_given_dict_by_path(auxiliar_output_list, | ||
path=path, | ||
parsed_dict=subdict[path[0]]) | ||
else: # In this case the variable is a dict so we go to another loop: | ||
return_result = self.get_tag_value_in_given_dict_by_path(auxiliar_output_list, | ||
path=path[1:], | ||
parsed_dict=parsed_dict[path[0]]) | ||
elif path[ | ||
1] in parsed_dict: # In those specific cases where the content of parsed_dict is only one element | ||
# we could have directly the final result | ||
|
||
# IMPORTANT! To test these particular cases when the current path is not the end | ||
auxiliar_output_list.append(parsed_dict[path[1]]) | ||
|
||
else: | ||
raise Exception('The path specified for the param doesnt exists in the response') | ||
except: | ||
return_result = None | ||
|
||
return_result = auxiliar_output_list | ||
return return_result | ||
|
||
def set_generic_variables_to_commit(self): | ||
for variable in self.generic_variables_to_commit: | ||
variable['path_string'] = \ | ||
|
@@ -240,11 +291,15 @@ def validate_get_test_case(self): | |
print(self.values_after_get) | ||
test_passes = True | ||
for key, value in self.values_after_get.items(): | ||
if not self.values_after_get[key]: | ||
if not self.values_after_get[key]: #Check if some of the elements of values_after_get[key] is zero, empty, False or None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eplit line length |
||
test_passes = False | ||
return test_passes | ||
|
||
def get_test_case_description(self): | ||
print('get_test_case_description:') | ||
print(self.test_case) | ||
print('boolean_get_test_case_description:') | ||
print(self.test_case['testcase']['description']) | ||
return self.test_case['testcase']['description'] | ||
|
||
def verify_test_and_skip(self): | ||
|
@@ -420,14 +475,28 @@ def set_values_after_get_from_generic_variables(self): | |
rpc_reply_key = self.get_rpc_reply_key_from_get_response() | ||
data_key = self.get_data_key_from_get_response(rpc_reply_key=rpc_reply_key) | ||
parsed_dict = xmltodict.parse(self.get_response.xml)[rpc_reply_key][data_key] | ||
variables_to_search = [] | ||
for variable in self.generic_variables_to_commit: | ||
if not variable['value_to_commit']: | ||
variables_to_search.append(variable) | ||
|
||
for variable in variables_to_search: | ||
self.values_after_get[variable['test_case_key']] = self.get_tag_value_in_given_dict_by_path( | ||
path=variable['path_list'], parsed_dict=parsed_dict) | ||
dict_variables_to_commit = self.generic_variables_to_commit[0] | ||
dict_variables_to_commit.pop('value_to_commit') | ||
variables_to_search=dict_variables_to_commit | ||
list_path_eval = self.get_tag_value_in_given_dict_by_path([],path=variables_to_search['path_list'], parsed_dict=parsed_dict) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line legth |
||
self.values_after_get[variables_to_search['test_case_key']] = list_path_eval | ||
print('variables_to_search') | ||
print(variables_to_search) | ||
print('self.values_after_get') | ||
print(self.values_after_get) | ||
#{'test_case_key': 'name', 'path_string': 'network-instances/network-instance/name', 'path_list': ['network-instances', 'network-instance', 'name']} | ||
print('variables_to_search[test_case_key]') | ||
print(variables_to_search['test_case_key']) | ||
print('variables_to_search[path_list]') | ||
print(variables_to_search['path_list']) | ||
print('path:') | ||
print(variables_to_search['path_list']) | ||
print('parsed_dict') | ||
print(parsed_dict) | ||
print('list_path_eval') | ||
print(list_path_eval) | ||
print('values_after_get') | ||
print(self.values_after_get) | ||
|
||
def set_values_after_get(self): | ||
rpc_reply_key = self.get_rpc_reply_key_from_get_response() | ||
|
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
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,9 @@ | ||
<get> | ||
<filter> | ||
<network-instances xmlns="http://openconfig.net/yang/network-instance"> | ||
<network-instance> | ||
<name></name> | ||
</network-instance> | ||
</network-instances> | ||
</filter> | ||
</get> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method definitions inside a class are surrounded by a single blank line.