diff --git a/AutomationFramework/page_objects/base/get_tag_value_funcionando.py b/AutomationFramework/page_objects/base/get_tag_value_funcionando.py deleted file mode 100644 index 4b5d553..0000000 --- a/AutomationFramework/page_objects/base/get_tag_value_funcionando.py +++ /dev/null @@ -1,570 +0,0 @@ -import collections - -parsed_dict0 = collections.OrderedDict([(u'components', - [collections.OrderedDict([(u'component', - [collections.OrderedDict([(u'name', u'Chassis'), - (u'state', - collections.OrderedDict([(u'name', u'Chassis'), - (u'type', u'CHASSIS'), - (u'id', - u'VM5F7C7584A7'), - (u'location', - u'Chassis'), - (u'description', - u'VMX'), - (u'mfg-date', - u'00-00-0000'), - (u'serial-no', - u'VM5F7C7584A7'), - (u'removable', u'0'), - (u'oper-status', - u'INACTIVE'), - (u'empty', u'0'), - (u'temperature', - collections.OrderedDict([(u'instant', - u'0.0')])), - (u'memory', - collections.OrderedDict([(u'available', - u'0'), - (u'utilized', - u'0')])), - (u'allocated-power', - u'0')]))]), - collections.OrderedDict([(u'name', u'Routing Engine0'), - (u'state', - collections.OrderedDict([(u'name', - u'Routing Engine0'), - (u'type', u'MODULE'), - (u'location', - u'Routing Engine0'), - (u'description', - u'RE-VMX'), - (u'mfg-date', - u'00-00-0000'), - (u'removable', u'1'), - (u'oper-status', - u'ACTIVE'), - (u'empty', u'0'), - (u'temperature', - collections.OrderedDict([(u'instant', - u'0.0')])), - (u'memory', - collections.OrderedDict([(u'available', - u'2048'), - (u'utilized', - u'368')])), - (u'allocated-power', - u'0')])), - (u'properties', - collections.OrderedDict([(u'property', - [collections.OrderedDict([(u'name', - u'state'), - (u'state', - collections.OrderedDict([(u'value', - u'Online Master'), - (u'configurable', - u'1')]))]), - collections.OrderedDict([(u'name', - u'mastership-state'), - (u'state', - collections.OrderedDict([(u'value', - u'Master'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'mastership-priority'), - (u'state', - collections.OrderedDict([(u'value', - u'Master (default)'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'cpu-utilization-user'), - (u'state', - collections.OrderedDict([(u'value', - u'0'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'cpu-utilization-background'), - (u'state', - collections.OrderedDict([(u'value', - u'0'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'cpu-utilization-kernel'), - (u'state', - collections.OrderedDict([(u'value', - u'1'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'cpu-utilization-interrupt'), - (u'state', - collections.OrderedDict([(u'value', - u'1'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'cpu-utilization-idle'), - (u'state', - collections.OrderedDict([(u'value', - u'98'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'memory-dram-used'), - (u'state', - collections.OrderedDict([(u'value', - u'1998'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'memory-dram-installed'), - (u'state', - collections.OrderedDict([(u'value', - u'2048'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'memory-utilization-buffer'), - (u'state', - collections.OrderedDict([(u'value', - u'18'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'uptime'), - (u'state', - collections.OrderedDict([(u'value', - u'3271201'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'reboot-reason'), - (u'state', - collections.OrderedDict([(u'value', - u'Router rebooted after a normal shutdown.'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'fru-model-number'), - (u'state', - collections.OrderedDict([(u'value', - u'RE-VMX'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'firmware-rev'), - (u'state', - collections.OrderedDict([(u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'manufacture-date'), - (u'state', - collections.OrderedDict([(u'value', - u'date:00-00-0000'), - (u'configurable', - u'0')]))])])]))]), - collections.OrderedDict([(u'name', u'CB0'), - (u'state', - collections.OrderedDict([(u'name', u'CB0'), - (u'type', - u'LINECARD'), - (u'location', u'CB0'), - (u'description', - u'VMX SCB'), - (u'mfg-date', - u'00-00-0000'), - (u'removable', u'1'), - (u'oper-status', - u'ACTIVE'), - (u'empty', u'0'), - (u'temperature', - collections.OrderedDict([(u'instant', - u'0.0')])), - (u'memory', - collections.OrderedDict([(u'available', - u'0'), - (u'utilized', - u'0')])), - (u'allocated-power', - u'0')])), - (u'properties', - collections.OrderedDict([(u'property', - [collections.OrderedDict([(u'name', - u'state'), - (u'state', - collections.OrderedDict([(u'value', - u'Online Master'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'fru-model-number'), - (u'state', - collections.OrderedDict([(u'value', - u'VMX SCB'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'manufacture-date'), - (u'state', - collections.OrderedDict([(u'value', - u'date:00-00-0000'), - (u'configurable', - u'0')]))])])]))]), - collections.OrderedDict([(u'name', u'FPC0'), - (u'state', - collections.OrderedDict([(u'name', u'FPC0'), - (u'type', - u'LINECARD'), - (u'location', - u'FPC0'), - (u'description', - u'Virtual FPC'), - (u'mfg-date', - u'00-00-0000'), - (u'firmware-version', - u'PC Bios'), - (u'software-version', - u'Version 20.2I20201005_1439_karanth by karanth on 2020-10-05 15:58:03 UTC'), - (u'removable', u'1'), - (u'oper-status', - u'ACTIVE'), - (u'empty', u'0'), - (u'temperature', - collections.OrderedDict([(u'instant', - u'0.0')])), - (u'memory', - collections.OrderedDict([(u'available', - u'511'), - (u'utilized', - u'158')])), - (u'allocated-power', - u'0')])), - (u'properties', - collections.OrderedDict([(u'property', - [collections.OrderedDict([(u'name', - u'state'), - (u'state', - collections.OrderedDict([(u'value', - u'Online'), - (u'configurable', - u'1')]))]), - collections.OrderedDict([(u'name', - u'power-maximum'), - (u'state', - collections.OrderedDict([(u'value', - u'0'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'memory-dram-used'), - (u'state', - collections.OrderedDict([(u'value', - u'511'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'memory-utilization-heap'), - (u'state', - collections.OrderedDict([(u'value', - u'31'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'memory-utilization-buffer'), - (u'state', - collections.OrderedDict([(u'value', - u'0'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'uptime'), - (u'state', - collections.OrderedDict([(u'value', - u'312671'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'fru-model-number'), - (u'state', - collections.OrderedDict([(u'value', - u'Virtual FPC'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'rom-software-rev-chassis'), - (u'state', - collections.OrderedDict([(u'value', - u'PC Bios'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'software-rev'), - (u'state', - collections.OrderedDict([(u'value', - u'Version 20.2I20201005_1439_karanth by karanth on 2020-10-05 15:58:03 UTC'), - (u'configurable', - u'0')]))]), - collections.OrderedDict([(u'name', - u'manufacture-date'), - (u'state', - collections.OrderedDict([(u'value', - u'date:00-00-0000'), - (u'configurable', - u'0')]))])])]))]), - collections.OrderedDict([(u'name', u'FPC0:CPU'), - (u'state', - collections.OrderedDict([(u'name', - u'FPC0:CPU'), - (u'type', u'CPU'), - (u'id', u'BUILTIN'), - (u'location', - u'FPC0:CPU'), - (u'mfg-date', - u'08-18-2013'), - (u'hardware-version', - u'Rev. 1.0'), - (u'serial-no', - u'BUILTIN'), - (u'part-no', - u'RIOT-LITE'), - (u'removable', u'0'), - (u'oper-status', - u'INACTIVE'), - (u'empty', u'0'), - (u'parent', u'FPC0'), - (u'temperature', - collections.OrderedDict([(u'instant', - u'0.0')])), - (u'memory', - collections.OrderedDict([(u'available', - u'0'), - (u'utilized', - u'0')])), - (u'allocated-power', - u'0')]))]), - collections.OrderedDict([(u'name', u'FPC0:MIC0'), - (u'state', - collections.OrderedDict([(u'name', - u'FPC0:MIC0'), - (u'type', - u'LINECARD'), - (u'location', - u'FPC0:MIC0'), - (u'description', - u'Virtual'), - (u'mfg-date', - u'00-00-0000'), - (u'removable', u'1'), - (u'oper-status', - u'ACTIVE'), - (u'empty', u'0'), - (u'parent', u'FPC0'), - (u'temperature', - collections.OrderedDict([(u'instant', - u'0.0')])), - (u'memory', - collections.OrderedDict([(u'available', - u'0'), - (u'utilized', - u'0')])), - (u'allocated-power', - u'0')])), - (u'properties', - collections.OrderedDict([(u'property', - collections.OrderedDict([(u'name', - u'state'), - (u'state', - collections.OrderedDict([(u'value', - u'Online'), - (u'configurable', - u'0')]))]))]))]), - collections.OrderedDict([(u'name', u'FPC0:PIC0'), - (u'state', - collections.OrderedDict([(u'name', - u'FPC0:PIC0'), - (u'type', u'MODULE'), - (u'id', u'BUILTIN'), - (u'location', - u'FPC0:PIC0'), - (u'description', - u'Virtual'), - (u'mfg-date', - u'00-00-0000'), - (u'serial-no', - u'BUILTIN'), - (u'part-no', - u'BUILTIN'), - (u'removable', u'0'), - (u'oper-status', - u'ACTIVE'), - (u'empty', u'0'), - (u'parent', u'FPC0'), - (u'temperature', - collections.OrderedDict([(u'instant', - u'0.0')])), - (u'memory', - collections.OrderedDict([(u'available', - u'0'), - (u'utilized', - u'0')])), - (u'allocated-power', - u'0')])), - (u'properties', - collections.OrderedDict([(u'property', - collections.OrderedDict([(u'name', - u'state'), - (u'state', - collections.OrderedDict([(u'value', - u'Online'), - (u'configurable', - u'1')]))]))]))])])]), - collections.OrderedDict([(u'component', - collections.OrderedDict([(u'name', u'CPU0:CORE0'), - (u'cpu', - collections.OrderedDict([(u'utilization', - collections.OrderedDict([(u'state', - collections.OrderedDict([(u'name', - u'CPU0:CORE0'), - (u'instant', - u'2'), - (u'avg', - u'2'), - (u'min', - u'0'), - (u'max', - u'2'), - (u'interval', - u'2273257329'), - (u'min-time', - u'0'), - (u'max-time', - u'1613723685674613655')]))]))]))]))])])]) - -parsed_dict1 = {'components':[{'component':[{'name':'Browser'},{'name':'Mario'},{'name':'Luigi'}]},{'component':{'name':'Pikachu'}}]} -parsed_dict2 = {'components':{'component':[{'name':'Browser'},{'name':'Mario'},{'name':'Luigi'}]}} -parsed_dict3 = {'components':[{'component':[{'config':'Browser'},{'config':'Mario'},{'name':'Luigi'}]},{'component':{'config':'Pikachu'}}]} -parsed_dict4 = {'components':[{'component':[{'config':'Browser'},{'config':'Mario'},{'config':'Luigi'}]},{'component':{'name':'Pikachu'}}]} -parsed_dict5 = {'components':[{'component':{'name':'Pikachu'}},{'component':[{'config':'Bulbasur'},{'config':'Charmander'},{'name':'Squirtle'}]}]} -parsed_dict6 = collections.OrderedDict([('network-instances', collections.OrderedDict([('@xmlns', 'http://openconfig.net/yang/network-instance'), ('network-instance', [collections.OrderedDict([('name', 'Prueba_Samier')]), collections.OrderedDict([('name', 'default')])])]))]) - -path2 = ['network-instances', 'network-instance', 'name'] - - -path_str = 'components/component/name' -path = path_str.split('/') - -def get_tag_value_in_given_dict_by_path(auxiliar_output_list, path, parsed_dict): - #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 = get_tag_value_in_given_dict_by_path(auxiliar_output_list,path=path, parsed_dict=subdict[path[0]]) - 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 = get_tag_value_in_given_dict_by_path(auxiliar_output_list,path=path,parsed_dict=subdict[path[0]]) - else: - return_result = 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 - -# Test 0 -return_result = get_tag_value_in_given_dict_by_path([],path,parsed_dict0) -print('Return result recursive:') -print(return_result) -result_valid0 = ['Chassis', 'Routing Engine0', 'CB0', 'FPC0', 'FPC0:CPU', 'FPC0:MIC0', 'FPC0:PIC0', 'CPU0:CORE0'] -if return_result == result_valid0: - print('Test 0 have done successfully!') -else: - print('Some error in the produced result.') -print('---------------------------------\n') - -# Test 1 -return_result = get_tag_value_in_given_dict_by_path([],path,parsed_dict1) -print('Return result recursive:') -print(return_result) -result_valid1 = ['Browser', 'Mario', 'Luigi', 'Pikachu'] -if return_result == result_valid1: - print('Test 1 have done successfully!') -else: - print('Some error in the produced result.') -print('---------------------------------\n') - -# Test 2 -return_result = get_tag_value_in_given_dict_by_path([],path,parsed_dict2) -print('Return result recursive:') -print(return_result) -result_valid2 = ['Browser', 'Mario', 'Luigi'] -if return_result == result_valid2: - print('Test 2 have done successfully!') -else: - print('Some error in the produced result.') -print('---------------------------------\n') - -# Test 3 -return_result = get_tag_value_in_given_dict_by_path([],path,parsed_dict3) -print('Return result recursive:') -print(return_result) -result_valid3 = ['Luigi'] -if return_result == result_valid3: - print('Test 3 have done successfully!') -else: - print('Some error in the produced result.') -print('---------------------------------\n') - -# Test 4 -return_result = get_tag_value_in_given_dict_by_path([],path,parsed_dict4) -print('Return result recursive:') -print(return_result) -result_valid4 = ['Pikachu'] -if return_result == result_valid4: - print('Test 4 have done successfully!') -else: - print('Some error in the produced result.') -print('---------------------------------\n') - -# Test 5 -return_result = get_tag_value_in_given_dict_by_path([],path,parsed_dict5) -print('Return result recursive:') -print(return_result) -result_valid5 = ['Pikachu', 'Squirtle'] -if return_result == result_valid5: - print('Test 5 have done successfully!') -else: - print('Some error in the produced result.') -print('---------------------------------\n') - -# Test 6 -return_result = get_tag_value_in_given_dict_by_path([],path2,parsed_dict6) -print('Return result recursive:') -print(return_result) - - -print('Finished!')