Skip to content
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
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions AutomationFramework/capabilities.py
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',
},
]
95 changes: 82 additions & 13 deletions AutomationFramework/page_objects/base/base_page_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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):
Copy link
Owner

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.

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'] = \
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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):
Expand Down Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class NetworkInstance(BasePageObject):
'name': 'network-instances/network-instance/name',
}
],
'ni_get_name': [
{
'name': 'network-instances/network-instance/name',
}
],
'ni_config_type': [
{
'name': 'network-instances/network-instance/name',
Expand Down
28 changes: 20 additions & 8 deletions AutomationFramework/test_cases/ni_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose1"

- testcase:
name: ni_config_type
Expand All @@ -23,7 +23,7 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose2"
type: "L3VRF"

- testcase:
Expand All @@ -37,7 +37,7 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose3"
enabled: "true"

- testcase:
Expand All @@ -51,7 +51,7 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose4"
description: "VPN de prueba para L3 y L2"

- testcase:
Expand All @@ -65,7 +65,7 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose5"
router_id: "172.16.1.2"

- testcase:
Expand All @@ -79,7 +79,7 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose6"
route_distinguisher: "65000:100"

- testcase:
Expand All @@ -93,7 +93,7 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose7"
type: "L3VRF"
enabled_address_families: "IPV4"

Expand All @@ -108,6 +108,18 @@
operation: edit-config
commit: true
params:
name: "Prueba_LxVPN"
name: "Jose8"
type: "L2VSI"
mtu: "1450"

- testcase:
name: ni_get_name
id: 9
description: >
This test is to get the name of network instances
rpcs:
- template: ni_get_name.xml
operation: get
params:
name: "Prueba_Samier"

9 changes: 9 additions & 0 deletions AutomationFramework/test_cases/templates/ni_get_name.xml
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>
7 changes: 7 additions & 0 deletions AutomationFramework/tests/network_instance/test_ni_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class TestNetworkInstanceConfig(BaseTest):
def test_ni_config_name(self, create_page_object):
create_page_object.execute_network_instance_edit_config_test_case()
assert create_page_object.generic_validate_test_case_params(), create_page_object.get_test_case_description()

@pytest.mark.parametrize('create_page_object_arg', [{'test_case_file': test_case_file,
'test_case_name': 'ni_get_name',
'page_object_class': NetworkInstance}])
def test_ni_get_name(self, create_page_object):
create_page_object.execute_get_test_case_with_dispatch()
assert create_page_object.validate_get_test_case(), create_page_object.get_test_case_description()

@pytest.mark.parametrize('create_page_object_arg', [{'test_case_file': test_case_file,
'test_case_name': 'ni_config_type',
Expand Down