diff --git a/AutomationFramework/capabilities.py b/AutomationFramework/capabilities.py index 529351f..e66d81f 100644 --- a/AutomationFramework/capabilities.py +++ b/AutomationFramework/capabilities.py @@ -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', }, ] diff --git a/AutomationFramework/page_objects/base/base_page_object.py b/AutomationFramework/page_objects/base/base_page_object.py index e038bed..efe74a3 100644 --- a/AutomationFramework/page_objects/base/base_page_object.py +++ b/AutomationFramework/page_objects/base/base_page_object.py @@ -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,21 +109,21 @@ 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') @@ -131,6 +131,57 @@ def get_tag_value_in_given_dict_by_path(self, path, parsed_dict): 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 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) + 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() diff --git a/AutomationFramework/page_objects/network_instance/network_intance.py b/AutomationFramework/page_objects/network_instance/network_intance.py index d4dd01c..38b96b5 100644 --- a/AutomationFramework/page_objects/network_instance/network_intance.py +++ b/AutomationFramework/page_objects/network_instance/network_intance.py @@ -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', diff --git a/AutomationFramework/test_cases/ni_config.yml b/AutomationFramework/test_cases/ni_config.yml index c7e8054..fb98de9 100644 --- a/AutomationFramework/test_cases/ni_config.yml +++ b/AutomationFramework/test_cases/ni_config.yml @@ -10,7 +10,7 @@ operation: edit-config commit: true params: - name: "Prueba_LxVPN" + name: "Jose1" - testcase: name: ni_config_type @@ -23,7 +23,7 @@ operation: edit-config commit: true params: - name: "Prueba_LxVPN" + name: "Jose2" type: "L3VRF" - testcase: @@ -37,7 +37,7 @@ operation: edit-config commit: true params: - name: "Prueba_LxVPN" + name: "Jose3" enabled: "true" - testcase: @@ -51,7 +51,7 @@ operation: edit-config commit: true params: - name: "Prueba_LxVPN" + name: "Jose4" description: "VPN de prueba para L3 y L2" - testcase: @@ -65,7 +65,7 @@ operation: edit-config commit: true params: - name: "Prueba_LxVPN" + name: "Jose5" router_id: "172.16.1.2" - testcase: @@ -79,7 +79,7 @@ operation: edit-config commit: true params: - name: "Prueba_LxVPN" + name: "Jose6" route_distinguisher: "65000:100" - testcase: @@ -93,7 +93,7 @@ operation: edit-config commit: true params: - name: "Prueba_LxVPN" + name: "Jose7" type: "L3VRF" enabled_address_families: "IPV4" @@ -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" + diff --git a/AutomationFramework/test_cases/templates/ni_get_name.xml b/AutomationFramework/test_cases/templates/ni_get_name.xml new file mode 100644 index 0000000..8114ca0 --- /dev/null +++ b/AutomationFramework/test_cases/templates/ni_get_name.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/AutomationFramework/tests/network_instance/test_ni_config.py b/AutomationFramework/tests/network_instance/test_ni_config.py index 5c1db0e..e5beb1c 100644 --- a/AutomationFramework/tests/network_instance/test_ni_config.py +++ b/AutomationFramework/tests/network_instance/test_ni_config.py @@ -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',