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 5 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
2 changes: 1 addition & 1 deletion AutomationFramework/capabilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
HOSTS = [
{
'host': '10.95.86.216',
'port': '12022',
'port': '12034',
sbarguil marked this conversation as resolved.
Show resolved Hide resolved
'username': 'admin',
'password': 'admin',
},
Expand Down
84 changes: 71 additions & 13 deletions AutomationFramework/page_objects/base/base_page_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(self, test_case_file=None, test_case_name=None, rpc_idx=0):
def init_generic_variables_to_commit(self):
self.generic_variables_to_commit = []
for variable, value in self.rpcs_list[self.rpc_idx_in_test_case]['params'].items():
#self.generic_variables_to_commit['test_case_key'] = variable
sbarguil marked this conversation as resolved.
Show resolved Hide resolved
#self.generic_variables_to_commit['value_to_commit'] = value
sbarguil marked this conversation as resolved.
Show resolved Hide resolved
new_variable = {'test_case_key': variable, 'value_to_commit': value}
self.generic_variables_to_commit.append(new_variable)

Expand Down Expand Up @@ -93,7 +95,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,27 +111,65 @@ 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):
sbarguil marked this conversation as resolved.
Show resolved Hide resolved
#auxiliar_output_list: variable to store results in a list

return_result = None #Initialize the output variable
if len(path) == 1:
auxiliar_output_list.append(parsed_dict)
else:
try:
if isinstance(parsed_dict, list):
path = path[1:]
for i in range(0, len(parsed_dict)):
subdict = parsed_dict[i]
if path[0] in subdict:
return_result = self.get_tag_value_in_given_dict_by_path(auxiliar_output_list,path=path, parsed_dict=subdict[path[0]])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split line legth

else:
if path[0] in parsed_dict:
sublist = parsed_dict[path[0]] # diccionario_interno
if isinstance(sublist, list):
path = path[1:]
for j in range(0,len(sublist)):
subdict = sublist[j]
return_result = self.get_tag_value_in_given_dict_by_path(auxiliar_output_list,path=path,parsed_dict=subdict[path[0]])
else:
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:
Expand Down Expand Up @@ -240,11 +280,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 +464,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