From 71d404a49e91ae7651a42d62de89beec609e1e7e Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 22 Feb 2021 12:39:25 +0100 Subject: [PATCH] Issue #99 solved, we must test the code meets the requirements to be integrated in base_page_object.py --- .../base/get_tag_value_funcionando.py | 496 ++++++++++++++++++ 1 file changed, 496 insertions(+) create mode 100644 AutomationFramework/page_objects/base/get_tag_value_funcionando.py diff --git a/AutomationFramework/page_objects/base/get_tag_value_funcionando.py b/AutomationFramework/page_objects/base/get_tag_value_funcionando.py new file mode 100644 index 0000000..2b2538f --- /dev/null +++ b/AutomationFramework/page_objects/base/get_tag_value_funcionando.py @@ -0,0 +1,496 @@ +import collections + +parsed_dict = 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')]))]))]))]))])])]) + +path_str = 'components/component/name' +path = path_str.split('/') + +def get_tag_value_in_given_dict_by_path(auxiliar_output_list,path, parsed_dict): + return_result = None + if len(path) == 1: + auxiliar_output_list.append(parsed_dict) + return_result = auxiliar_output_list + else: + try: + if isinstance(parsed_dict, list): + path = path[1:] + for i in range(0, len(parsed_dict)): + subdict = parsed_dict[i] + 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 + path = path[1:] + if isinstance(sublist, list): + for j in range(0,len(sublist)): + subdict = sublist[j] + #if j > 0: + # path = original_path[1:] + 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]]) + return_result = auxiliar_output_list + + else: + raise Exception('The path specified for the param doesnt exists in the response') + + except: + return_result = None + return return_result + +#auxiliar_output_list = [] +#return_result = get_tag_value_in_given_dict_by_path(return_result_recursive,path,path,parsed_dict) +return_result = get_tag_value_in_given_dict_by_path([],path,parsed_dict) + +print('Return result recursive:') +print(return_result) + +print('Finished!')