Framework.Utils package¶
Submodules¶
Framework.Utils.cli_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.cli_Utils.
disconnect
(child)[source]¶ - Disconnects warrior_cli_class session object(pexpect/paramiko)
- Returns session object(same child)
-
Framework.Utils.cli_Utils.
get_connection_port
(conn_type, inpdict)[source]¶ Gets the port for ssh or telnet connections 1. ssh :
- looks if ssh_port is present in inpdict.
- if not checks for conn_port
- if both not present returns None
-
Framework.Utils.cli_Utils.
get_response_dict
(started_thread_for_system, thread_instance_list, same_system, response)[source]¶ This function iterates over thread_instance_list and gets the data that the threads have stored in its data variable. Updates the remote_resp_dict with the system name and the corresponding data collected.
The system names in same_system also get stored in the remote_resp_dict but their value is the same as the response that was obtained through the _send_cmd function
Returns: remote_resp_dict (dict) with collected logs as value to the system_name key
-
Framework.Utils.cli_Utils.
get_unique_log_and_verify_list
(log_list, verify_on_list, system_name)[source]¶ This function loops through the log_list and the verify_on_list and returns a unique list containing unique sustem names fromboth the lists
-
Framework.Utils.cli_Utils.
pexpect_spawn_with_env
(pexpect_obj, command, timeout, escape=False, env=None)[source]¶ spawn a pexpect object with environment variable
-
Framework.Utils.cli_Utils.
sendPing
(hostname, count, fname)[source]¶ Sends a ping command :Arguments:
- count(string) = no of pings to be sent
- src_iface(string) = source interface from whihc ping messages
- are to be sent.
- destip(string) = the destination ip address to ping.
- fname = logfile to log ping response.
Returns: status = boolean
-
Framework.Utils.cli_Utils.
sendSourcePing
(count, src_iface, destip, fname)[source]¶ Sends a source based ping command i.e. if multiple interfaces are configured and available, sends pings from the src_iface provided :Arguments:
- count(string) = no of pings to be sent
- src_iface(string) = source interface from whihc ping messages
- are to be sent.
- destip(string) = the destination ip address to ping.
- fname = logfile to log ping response.
Returns: status = boolean
-
Framework.Utils.cli_Utils.
send_commands_from_testdata
(testdatafile, obj_session, **args)[source]¶ - Parses the testdata file and gets the command details
for rows marked execute=yes and row=str_rownum. - Sends the obtained commands to the warrior_cli_class session object(obj_Session). - If the commands have verification attribute set, then verifies the verification text for presence/absence as defined in the respective found attribute in the testdatfile.
Arguments: - testdatafile = the xml file where command details are available
- obj_session = pexpect or warrior_cli_class session object
- logfile = logfile of the pexpect session object.
- varconfigfile= xml file from which the values will be taken for subtitution
- var_sub(string) = the pattern [var_sub] in the testdata commands,
- start_prompt, end_prompt, verification search will substituted with this value.
- args = Optional filter to specify title/rownum
Returns: - finalresult = boolean
-
Framework.Utils.cli_Utils.
send_smart_cmd
(connect_testdata, session_object, tag_value, call_system_name, pre_tag)[source]¶ The beacons of Gondor are lit send out the smart command :param connect_testdata:
the smart testdata file that contains the smart cmdParameters: - session_object – use this pexpect object to send out command
- tag_value – specify the testdata block of commands that get sent out
- call_system_name – in order to get passed the substitutions, a system name must be provided
- pre_tag – Distinguish if it is a connect smart action or disconnect smart action
-
Framework.Utils.cli_Utils.
smart_action
(datafile, call_system_name, raw_prompt, session_object, tag_value, connect_testdata=None)[source]¶ entry function for sending smart command :param datafile:
the testcase datafileParameters: - call_system_name – in order to get passed the substitutions, a system name must be provided
- raw_prompt – The string that will be analyzed in order to find the device system
- session_object – use this pexpect object to send out command
- tag_value – specify the testdata block of commands that get sent out
- connect_testdata – the smart testdata file that contains the smart cmd, optional in here
Returns: the smart testdata file that contains the smart cmd
-
Framework.Utils.cli_Utils.
smart_analyze
(prompt, testdatafile=None)[source]¶ retrieve the correspond smart testdata file for smart cmd from either Tools/connection or testcase testdata file :param prompt:
The string that will be analyzed in order to find the device systemParameters: testdatafile – optional arg to provide a pre-defined device system in the test datafile Returns: the smart datafile that contains the smart cmd to be sent
-
Framework.Utils.cli_Utils.
start_threads
(started_thread_for_system, thread_instance_list, same_system, unique_log_verify_list, system_name)[source]¶ This function iterates over unique_log_verify_list which consists of unique values gotten from monitor attributes and verify_on attributes
If a system_name has a * against it, it indicates that the system is the same as the one on which the testcase is running. Thread would not be started for that system.
Returns: started_thread_for_system (list[str]) = Stores the system names for which threads were succesfully created
thread_instance_list (list[str]) = stores the instances of thread created for corresponding system in the started_thread_for_system list,
same_system (list[str]) = stores the system name which was the same as the system on which the TC is running without the trailing *,
Framework.Utils.config_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Framework.Utils.csv_utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.csv_utils.
convert_csv_or_excel_to_xml
(input_file, mapping_file=None, output_xml_file_path=None, overwrite='yes')[source]¶ Takes file path as input 1. If it is excel file, converts to csv and then converts
csv file to xml- If it is csv file, converts to xml file.
- Mapping file is used to map the column names in the excel sheet to
- a meaningful name as recognized by the code.
- Arguments:
- input_file: input_file which is either csv file path or excel file path
- mapping_file: If a mapping file path is given, it is used to map columns with the meaningful name as recognized by the user else the spaces in the column names will be replaced by “_” in the output xml
- output_xml_file_path: If user gives the output_xml_file_path, creating an xml file in that path else creating xml file in the path from where he have given csv or excel file.
- Returns:
1. output_xml_file_path: Returns the output xml file path 2 output_dict: Updates the output_dict with
json string and with output xml.
-
Framework.Utils.csv_utils.
convert_csv_to_list_of_dict
(input_csv_file)[source]¶ Takes the CSV file path as input and converts it to list of dictionaries
- Arguments:
- input_csv_file: it takes CSV file path as input
- Returns:
- Returns list of dictionaries where keys are column names and values are respective column values
-
Framework.Utils.csv_utils.
convert_excel_to_csv
(input_excel_file, output_csv_file_path=None, return_csv_file=False)[source]¶ Takes the excel file path as input and converts into csv file and if we select return_csv_file as True returns csv file else returns csv file object
- Arguments:
input_excel_file: It is a excel file path which is to be converted into csv file
output_csv_file_path: If user gives the output csv path, then creating csv file at that path else creating a csv file
in the directory from where he have given excel file.
return_csv_file: If the user selects return_csv_file as True, returning the output csv file else returning the object.
- Returns:
- Returns the csv file path if user selects return_csv_file as True else returns the object.
-
Framework.Utils.csv_utils.
convert_xml_to_csv
(input_file, mapping_file=None, output_csv_file_path=None, overwrite='yes')[source]¶ It takes xml file path as input and converts to csv.
- Arguments:
- input_file: Takes xml file path as input
- mapping_file: If a mapping file path is given, it is used to map columns with the meaningful name as recognized by the user else the tags in the xml file will be used as column names in the csv file.
- output_csv_file_path: If user gives the output_csv_file_path, creating an csv file in that path else creating csv file in the path from where he have given xml file.
- Returns:
- Returns output csv file path.
Framework.Utils.data_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.data_Utils.
convert2type
(value, data_type='str')[source]¶ Convert value to data_type and return value in that data_type Currently supported are str/int/float only
-
Framework.Utils.data_Utils.
evaluate_tc_argument_value
(element)[source]¶ Splits the value of the attribute value in the argument tag in the TC
-
Framework.Utils.data_Utils.
generate_datafile
(lists_of_systems, output_dir, filename)[source]¶ take in a list of lists which contains systems generate one input data file per list
-
Framework.Utils.data_Utils.
getSystemData
(datafile, system_name, cnode, system='system')[source]¶ Returns the value for tag or attrib of a system or susbsystem
If an attribute and a tag of the same name is present then returns the value of the attribute.
Incase of attribute the value is the attribute value. Incase of a tag the value is the text of the tag.
Arguments: - datafile(string) = absolute path of the system datafile
- system_name (string) = This can be name of the system or a subsystem. In case of subsystem only single subsystem is supported.
- cnode(string) = attributes or tag whose value is to be obtained.
- :Returns:system=’system’
- False if the system/subsystem cannot be found in the datafile.
- If an attribute or tag is not present its value=boolean False
- If a tag is present but has no text its value=None
-
Framework.Utils.data_Utils.
get_actual_cred_value
(tag, value, etype, startdir='')[source]¶ get the credential value after converting to the desired type and if file type get absolute path relative to the startdir
-
Framework.Utils.data_Utils.
get_all_system_or_subsystem
(datafile, system_name=None)[source]¶ return all the system elements or all the children of a system element with specific name
-
Framework.Utils.data_Utils.
get_child_tag_value_list
(datafile, system_name, child_list=[], *args)[source]¶ Parse the datafile for the system and get the tag list , value list of all the children provided in the child_list
-
Framework.Utils.data_Utils.
get_cred_value_from_elem
(element, tag, startdir='')[source]¶ given an credential element find the credential value desired
-
Framework.Utils.data_Utils.
get_credentials
(datafile, system_name, myInfo=[], tag_name='system', attr_name='name', **kwargs)[source]¶ Takes an list(myInfo) of attribute or tag names as input and returns a dictionary having values for each of the requested attribute or tag name.
If an empty list provided as myInfo returns a dictionary having all the attribute and tags with their values
If an attribute and a tag of the same name is present then returns the value of the attribute.
Incase of attribute the value is the attribute value. Incase of a tag the value is the text of the tag.
If the tag has child elements, the value will be a dictionary with all its child tags as keys & their texts as values.
Arguments: - datafile(string) = absolute path of the system datafile
- system_name (string) = This can be name of the system or a subsystem. In case of subsystem only single subsystem is supported.
- List of attributes or tags whose values are to be obtained.
Returns: - Dictionary of attributes/tags and their values
- False if the system/subsystem cannot be found in the datafile.
- If an attribute or tag is not present its value=boolean False
- If a tag is present but has no text its value=None
-
Framework.Utils.data_Utils.
get_default_ecf_and_et
(arguments_dict, current_datafile, current_browser, name_tuple=('element_config_file', 'element_tag'), def_name_tuple=('DEF_ecf', 'DEF_et'))[source]¶ Updates selenium argument sict with Default ECF and default element_tag
-
Framework.Utils.data_Utils.
get_filepath_from_system
(datafile, system_name, *args)[source]¶ This function takes variable number of tag names as input and returns a list of absolute paths for all the tag values. In case of non-string tag values, it will simply return those non-string values.
-
Framework.Utils.data_Utils.
get_iteration_syslist
(system_node_list, system_name_list)[source]¶ Takes a list of system nodes and system names and returns. 1. List of system names with iter=yes 2. List of system nodes with iter=yes
-
Framework.Utils.data_Utils.
get_nc_config_string
(config_datafile, config_name, var_configfile=None)[source]¶ Get the config of netconf as a list
-
Framework.Utils.data_Utils.
get_nc_request_rpc_string
(config_datafile, xmlns, request_type, xmlns_tag)[source]¶ Get the Request of netconf as a list
-
Framework.Utils.data_Utils.
get_netconf_data
(datafile, config_name, **kwargs)[source]¶ Get the details for netconf from the datafile. The required details are provided as a key,value pair for the **kwargs argument. of example, if rest_url, rest_data are required then while call this funciton as get_netconf_data(datafile, system_name, rest_url=value, rest_data=value)
If the input value of one of them in None then use the value from the datafile else use the provided value
-
Framework.Utils.data_Utils.
get_no_impact_logic
(context_str)[source]¶ Get the silent tag from context return silence value and context value
-
Framework.Utils.data_Utils.
get_object_from_datarepository
(object_key, verbose=True)[source]¶ Gets the value for the object with the provided name from data repository. object_key contains .(dot) will be treated as nested key
-
Framework.Utils.data_Utils.
get_session_id
(system_name, session_name=None)[source]¶ Returns the session-id based on the provided system_name :Arguments:
- system_name (string) = This can be name of the system or a subsystem. In case of subsystem only single subsystem is supported.
- session_name (string) = Name of the session to the system or to the session.
Returns: - For system returns system_name + session_name
- For subsystems returns system_name + subsystem_name + session_name
-
Framework.Utils.data_Utils.
get_system_list
(datafile, node_req=False)[source]¶ Get the list of systems from the datafile if node_req = True returns 1. list of system names, 2. list of system nodes if node_rq = False returns on the list of system names
-
Framework.Utils.data_Utils.
get_td_vc
(datafile, system_name, td_tag, vc_tag)[source]¶ Get the testdata and varconfig file paths from the datafile using the testdata nd varconfig tag given as input
-
Framework.Utils.data_Utils.
get_user_specified_tag_values_in_tc
(datafile, system_name, **kwargs)[source]¶ Get the details for rest call from the datafile. The required details are provided as a key,value pair for the **kwargs argument of example, if rest_url, rest_data are required then while call this funciton as get_user_specified_tag_values_in_tc(datafile, system_name, rest_url=value, rest_data=value)
If the input value of one of them in None then use the value from the datafile else use the provided value
-
Framework.Utils.data_Utils.
get_var_by_string_prefix
(string)[source]¶ Get value from Environment variable or data repo
-
Framework.Utils.data_Utils.
get_var_configfile
(datafile, system_name)[source]¶ Gets the var config file for the system with provided system_name in the datafile
-
Framework.Utils.data_Utils.
get_verify_text_context_as_list
(testdata, verify_list)[source]¶ From the testdata file takes a testdat node and a list of nodes with verification present as input
Return: - a list of verifcation_text
- a list of verification context
-
Framework.Utils.data_Utils.
group_systems_with_same_tag_value
(root, tag, value)[source]¶ Put systems with the same tag value pair in one list and all other system in another list
-
Framework.Utils.data_Utils.
group_systems_with_unique_tag_value
(root, tag)[source]¶ Separate system into lists where each list only has system with unique tag value
-
Framework.Utils.data_Utils.
process_subsystem_list
(datafile, system_name, subsystem=None)[source]¶ Takes a system_name and a list of subsystem names as input and process them by removing blank spaces for each element in the subsystem name list. Then remove all duplicate entries in the list. If any input subsystem_name in the list is ‘all’, a list of all subsystem exist under the provided system_name in the datafile will be return. If the system_name is not found in the datafile, subsystem_list will be set None.
-
Framework.Utils.data_Utils.
resolve_argument_value_to_get_tag_value
(datafile, system_name, element_value_in_argument)[source]¶ Here, the value of the attribute value in the argument tag is resolved. From now on value represents the value of the attribute value in the argument tag in the TC
Conditions: value can be simple and direct. Eg. “http://httpbin.org”. In this case, it is returned as is.
value can start with tag, then everything after “=” is taken and a tag of that name is searched for under the provided system in the datafile. If tag of the same name is found, then the text of that tag is returned.
If tag is not found, then a False is returned.
If no system tag with the name as that of the system name is found then, then value is returned.
-
Framework.Utils.data_Utils.
resolve_system_subsystem_list
(datafile, system_name)[source]¶ Using the provided system_name which may include both system_name and subsystem_name. Ex: NE1[dip,cli] Call ‘split_system_subsystem’ to separate the system_name and subsystem(s) Then call ‘process_subsystem_list’ to compare the list of subsystem(s) from the input against actuals subsystem in the referenced datafile. Return a system_name, subsystem_list
-
Framework.Utils.data_Utils.
split_system_subsystem
(system_name)[source]¶ Separate system_name and subsystem_name str from the input Ex: system_name=NE1[cli,dip,if1] will be separate into
system_name=NE1 subsystem_name str = ‘cli, dip, if1’
-
Framework.Utils.data_Utils.
sub_from_data_repo
(raw_value, start_pattern='${', end_pattern='}')[source]¶ wrapper function for subst_var_patterns_by_prefix
-
Framework.Utils.data_Utils.
sub_from_env_var
(raw_value, start_pattern='${', end_pattern='}')[source]¶ wrapper function for subst_var_patterns_by_prefix
-
Framework.Utils.data_Utils.
subst_var_patterns_by_prefix
(raw_value, start_pattern='${', end_pattern='}', prefix='ENV')[source]¶ - Takes a key value pair or string (value) as input in raw_value,
- if the value has a pattern matching ${ENV.env_variable_name}.
Searches for the env_variable_name in the environment and replaces it and return the updated dictionary. If environment variable is not found then substitutes with None.
if the value has a pattern matching ${REPO.key}.Searches for the key in the data repository and replaces it and return the updated dictionary. If key is not found then None is substituted.
if the value has a pattern matching ${REPO.k1.k2.k3}.Searches for the keys k1, k2, k3 in the data repository in nested order as provided and replaces it and return the updated dictionary. If keys is not found in the order or does not exist then None is substituted. source could be environment or datarepository for now.
-
Framework.Utils.data_Utils.
substitute_var_patterns
(raw_value, start_pattern='${', end_pattern='}')[source]¶ substitute variable inside start and end pattern
-
Framework.Utils.data_Utils.
update_datarepository
(input_dict)[source]¶ Updates the data repository with the provided dictionary
-
Framework.Utils.data_Utils.
verify_arith_exp
(expression, expected, comparison='eq', repo_key='exp_op')[source]¶ Verify the output of the arithmetic expression matches the expected(float comparison) Note : Binary floating-point arithmetic holds many surprises. Please refer to link, https://docs.python.org/2/tutorial/floatingpoint.html This Keyword inherits errors in Python float operations. :Arguments:
- expression: Arithmetic expression to be compared with expected.
- This can have env & data_repo values embedded in it.
Ex. expression: “10+${ENV.x}-${REPO.y}*10”
Expression will be evaluated based on python operator precedence Supported operators: +, -, , /, %, *, ^
- expected: Value to be compared with the expression output
This can be a env or data_repo or any numeral value.
- comparison: Type of comparison(eq/ne/gt/ge/lt/le)
eq - check if both are same(equal) ne - check if both are not same(not equal) gt - check if expression output is greater than expected ge - check if expression output is greater than or equal to expected lt - check if expression output is lesser than expected le - check if expression output is lesser than or equal to expected
repo_key: Name of the key to be used to save the expression_output in the warrior data repository
- Ex. If repo_key is ‘exp_op’ & expression_output is 10.0
It will be stored in data_repo in the below format data_repo = {
… verify_arith_exp: {‘exp_op’: 10.0}, …
}
This value can be retrieved from data_repo using key : ‘verify_arith_exp.exp_op’.
Returns: - status(boolean)
-
Framework.Utils.data_Utils.
verify_data
(expected, key, data_type='str', comparison='eq')[source]¶ Verify the value of the key in data repository matches with expected value the comparison will compare expected to key with comparison value eg. expected=5, value of key=3, comparison=’ge’ mean 5 >= 3
-
Framework.Utils.data_Utils.
verify_relation
(actual_value, cond_value, operator, cond_type)[source]¶ verify the actual_value with the expected value
-
Framework.Utils.data_Utils.
verify_resp_across_sys
(match_list, context_list, command, response, varconfigfile=None, verify_on_list=None, verify_list=None, remote_resp_dict=None, endprompt='', verify_group=None)[source]¶ New method to verify response of a command sent on one system with the response recieved from another system
-
Framework.Utils.data_Utils.
verify_resp_inorder
(match_list, context_list, command, response, varconfigfile=None, verify_on_list=None, verify_list=None, remote_resp_dict=None, verify_group=None)[source]¶ Method for in-order search. Verifies the ‘search strings’ in the system response and also verifies whether they are in order or not
Framework.Utils.datetime_utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.datetime_utils.
get_current_timestamp
()[source]¶ Returns system current timestamp with date and month Arguments:
No args
- Returns:
- Current System Time in the format of Year, Month, Date, Time(without microseconds)
- eg: 2015-04-27 09:48:21
-
Framework.Utils.datetime_utils.
get_hms_for_seconds
(seconds)[source]¶ prints number of seconds in hours:minutes:seconds format
-
Framework.Utils.datetime_utils.
get_time_delta
(start_time, end_time=None)[source]¶ Returns system current timestamp with date and month Arguments:
- time_stamp = time stamp in the format of system datetime(without microseconds)
- eg: 2015-04-27 09:48:21
- Returns:
Time delta = Returns time difference between the present system time and between the time stamp which comes as argument in the format of seconds.
eg: 212342.0
-
Framework.Utils.datetime_utils.
wait_for_timeout
(wait_time, unit='SECONDS', notify_count=4)[source]¶ Warrior, Wait till the time is a generic wait. The Wait is informed to the user as a countdown
Arguments: 1.wait_time: Time for Warrior wait. 2.unit: The unit of Time supported are
- Second (default)
- Minute
- Hour
- Day
- Month (30 days is assumed for one Month)
- Year (365 days is assumed for one Year)
- 3.notify_count: number of times, the user needs to be notified
during wait time. Default value is 4. Ex: If the notify_count=4 and timeout=400 the timeout is divided into 4 partitions each as 100 and notified to user as 100(25%),200(50%),300(75%),400(100%)
Returns: Status = Bool
Framework.Utils.demo_utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Framework.Utils.dict_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.dict_Utils.
convert_string_to_dict
(element, key_value_pair_sep=';', key_value_sep='=')[source]¶ This function converts a string into a dict.
input = “foo=foo1; bar=bar1; ; =foobar; barfoo=” return value = {‘foo’: ‘foo1’, ‘bar’: ‘bar1’}If the dict is empty at the end of the function, None is returned
Framework.Utils.driver_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.driver_Utils.
execute_keyword
(keyword, data_repository, args_repository, package_list)[source]¶ Executes the keyword provided by product driver 1. searches for class methods in the package list 2. searches for independent functions in the package list 3. If class method matching the keyword is found in the actions package executes it
else searches for independent fucntions matching the keyword name and executes it
Framework.Utils.email_utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.email_utils.
compose_send_email
(exec_type, abs_filepath, logs_dir, results_dir, result, mail_on='per_execution')[source]¶ compose and sends email from smtp server using input arguments as: :Arguments:
exec_type - type of test(case/suite/project)
abs_filepath - full path of case/suite/project
logs_dir - full path of logs directory
results_dir - full path of results directory
result - execution result
mail_on(optional) - it is to specify when to send an email Supported options below:
- per_execution(default)
- first_failure
- every_failure
-
Framework.Utils.email_utils.
construct_mail_body
(exec_type, abs_filepath, logs_dir, results_dir)[source]¶ construct e-mail body with Project, Logs/Results directory & Execution summary :Arguments:
- exec_type - type of test(case/suite/project)
- abs_filepath - full path of case/suite/project
- logs_dir - full path of logs directory
- results_dir - full path of results directory
Returns: - body - return mail body
-
Framework.Utils.email_utils.
get_email_params
(mail_on='per_execution')[source]¶ Get the parameters from the w_settings.xml file. :Arguments:
- 1.mail_on(optional) - it is to specify when to send an email.
- Supported options below:
- per_execution(default)
- first_failure
- every_failure
Returns: - smtp_host - smtp host name
- sender - sender email ID
- receivers - receiver email ID(s)
- subject - email subject line
- compress - compression(Yes/No)
-
Framework.Utils.email_utils.
send_email
(smtp_host, sender, receivers, subject, body, files)[source]¶ sends email from smtp server using input arguments: :Arguments:
- smtp_host - smtp host name
- sender - sender email ID
- receivers - receiver email ID(s)
- subject - email subject line
- body - email body
- files - files to be attached
-
Framework.Utils.email_utils.
set_params_send_email
(addsubject, data_repository, files, mail_on)[source]¶ - From data_repository array constructs body of email
- using testcase/testsuite name, logs directory, results directory fetches smtp host, sender, receiver from w_settings.xml uses paramters such as: subject, body, attachments
Arguments: subject - email subject
- data_repository - array of email body lines e.g.
- testcase/testsuite name
- logs directory
- results directory
files - list of file attachments
mail_on(optional) - it is to specify when to send an email Supported options below:
- per_execution(default)
- first_failure
- every_failure
Framework.Utils.encryption_utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.encryption_utils.
get_key
(encoded_key)[source]¶ Function that returns enc instance using secret key, passed to this function or read from secret.key file
- Args:
- encoded_key - False or base64 secrety key for encryption
- Return:
- IV - Random seed used to enc CIPHER - Enc instance used to for encryption
-
Framework.Utils.encryption_utils.
set_secret_key
(plain_text_key)[source]¶ Function that saves base64 encoded format of secret key, passed to this function and saved to secret.key file
- Args:
- plain_text_key - Plain text key, that is is used for encryption
- Return:
- status - True if key is base64 encoded and saved
- False if not saved
key - base64 endoced key
Framework.Utils.file_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.file_Utils.
check_and_create_dir
(dirpath)[source]¶ Checks if dir exists in provided path. If dir exists returns True Elseif dir does not exists, tries to create a directory
- If dir created successfully, returns True.
- If dir creation failed returns false
-
Framework.Utils.file_Utils.
check_extension_get_absolute_path
(relative_path, start_directory, list_extn=['.json', '.xml', '.txt'])[source]¶ This is wrapper function that gets and verifies extention of a file path and then returns the absolute path. start_directory must be an absolute path
-
Framework.Utils.file_Utils.
close
(fd)[source]¶ Close the file. A closed file cannot be read or written any more. :Arguments:
fd - file descriptor got from open_fileReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
convert_to_zip
(file_path, compression_type=8)[source]¶ Compress the given file based on the compression_type using zipfile module. Name of the zipped file will be same as the given file name :Arguments:
- file_path - File to be zipped
- compression_type - ZIP_STORED(no compression) or ZIP_DEFLATED(requires zlib)
Returns: - zipped_file - zipped file
-
Framework.Utils.file_Utils.
copy
(src, dst)[source]¶ Copy the file src to the file or directory dst. If dst is a directory, a file with the same basename as src is created (or overwritten) in the directory specified. Permission bits are copied. src and dst are path names given as strings. :Arguments:
src - file to be copied dst - file/dir on which to be copiedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
copy2
(src, dst)[source]¶ Similar to shutil.copy(), but metadata (permissions etc., as mentioned in copy_stat above) is copied as well in fact, this is just shutil.copy() followed by copystat(). This is similar to the Unix command cp -p. :Arguments:
src - file and metadata to be copied dst - file/dir on which to be copiedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
copyFileContents
(srcfile, dstfile)[source]¶ copy file from src to dst using append method
-
Framework.Utils.file_Utils.
copyfile
(src, dst)[source]¶ Copy the contents (no metadata) of the file named src to a file named dst. dst must be the complete target file name. :Arguments:
src - file to be copied dst - file on which to be copiedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
copyfileobj
(fsrc, fdst)[source]¶ Copy the contents of the file-like object fsrc to the file-like object fdst. :Arguments:
fsrc - file descriptor of the file to be copied fdst - file descriptor of the file on which to be copiedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
copymode
(src, dst)[source]¶ Copy the permission bits from src to dst. The file contents, owner, and group are unaffected. src and dst are path names given as strings. :Arguments:
src - mode of the file to be copied dst - file on which mode has to be copiedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
copystat
(src, dst)[source]¶ Copy the permission bits, last access time, last modification time, and flags from src to dst. The file contents, owner, and group are unaffected. src and dst are path names given as strings. :Arguments:
src - permission bits of the file to be copied dst - file on which permission bits has to be copiedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
createDir
(path, dirname)[source]¶ Creates a new directory with name = dirname under the provided path, ignores if directory with same name already exists Arguments:
- path = (string) full path of an existing directory where a new directory need to be created
- dirname = (string) name of the new directory to be created
-
Framework.Utils.file_Utils.
createDirForPyTc
(filename, path, dirname)[source]¶ method for old directory structure, delete later if not required
-
Framework.Utils.file_Utils.
createDir_addtimestamp
(path, dirname)[source]¶ Creates a new directory with name = dirname under the provided path, if directory with same name already exists adds date+timestamp to the name and creates a new directory with name = dirname+date×tamp Arguments:
- path = (string) full path of an existing directory where a new directory need to be created
- dirname = (string) name of the new directory to be created
-
Framework.Utils.file_Utils.
create_execution_directory
(filepath)[source]¶ Gets a Testcase/Testsuite/Project.xml filepath as input, Checks if a directory called Execution exits at the same level of Testcase/Testsuite/Project directory If it does not exist creates a directory called Execution.
-
Framework.Utils.file_Utils.
create_zipdir
(zipname, path, extn='zip')[source]¶ zip the path and output to same level
-
Framework.Utils.file_Utils.
delFolder
(path)[source]¶ check if folder exists and delete it with its content
-
Framework.Utils.file_Utils.
deleteFirstLine
(filename)[source]¶ Takes a file name as input and deletes the first line
-
Framework.Utils.file_Utils.
deleteLinesFromFirst
(filename)[source]¶ Takes a file name as input and deletes the first line
-
Framework.Utils.file_Utils.
deleteLinesUntilMatch
(filename, match, startfrom='first')[source]¶ Opens a file and deletes all the lines until a matching line is encoutered
# filename = location of the file from which lines are to be deleted # match = the line to be matched with, this is the entire line given in string format # startfrom = ‘first’ (default), starts the search begining form the first line of the file # and deletes all the lines until matching line is reached # = ‘last’, starts the search begining form the last line of the file moving upwards # and deletes all the lines until matching line is reached
-
Framework.Utils.file_Utils.
deleteMatchingFileLines
(origfile, newfile, arrValues)[source]¶ Searches existing file for text and creates new file without the lines containing the text.
-
Framework.Utils.file_Utils.
fileno
(fd)[source]¶ Returns the integer file descriptor that is used by the underlying implementation to request I/O operations from the operating system. :Arguments:
fd - file descriptor got from open_fileReturn: integer file descriptor
-
Framework.Utils.file_Utils.
findLastString
(filename, searchterm)[source]¶ Return the last line of a file
-
Framework.Utils.file_Utils.
flush
(fd)[source]¶ Flush the internal buffer, like stdio’s fflush. This may be a no-op on some file-like objects. :Arguments:
fd - file descriptor got from open_fileReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
getAbsPath
(relative_path, start_directory='.')[source]¶ This function is used to manipulate the path according to the relative path that is specified
Arguments: - @param relative_path: The relative path of directory or file
- @param start_directory: The actual dir path where the file must be
Returns: - @return: Returns the abspath with the relative path specified
-
Framework.Utils.file_Utils.
getCurrentFileName
()[source]¶ Will return the file name of file_Utils. Copy into file needed.
-
Framework.Utils.file_Utils.
getCustomLogFile
(filename, path, custom, ext='.log')[source]¶ append filename of log file with custom string
-
Framework.Utils.file_Utils.
getDateTime
(time_format=None)[source]¶ Returns the current year-month-date_hour-minute-second
-
Framework.Utils.file_Utils.
getDirName
(filepath)[source]¶ returns the directory component for the path provided
-
Framework.Utils.file_Utils.
getLinesBetweenMatchingLines
(srcfile, dstfile, start, end, no_of_search=1)[source]¶ This function opens a file, searches for the start and end strings and writes the lines in between start and end string into a new file (start, end inluded) # srcfile = source file which has the data to be parsed # dstfile = destination file to which the captured data is to be written # start = starting string to be serached for # end = ending string to be searched for # no_of_searches = denotes the number of times the file has to be searched for the start and end strings # supported values = any interger greater than 0 # = EOF | eof searches the entire file
-
Framework.Utils.file_Utils.
getNameOnly
(filename)[source]¶ get file name without extension from a path
-
Framework.Utils.file_Utils.
getNewExtension
(filename, extension)[source]¶ Replace the extention of the file
-
Framework.Utils.file_Utils.
getSubDirFile
(subdir, existing_dir, ext)[source]¶ Searches for a sub-directory with provided name under a directory. If it does # not exist creates a new sub-directory # Now under this newly created directory creates file with sub-directory name and # provided extension.If a file with the same name already exists # adds data and # time-stamp to the filename . # Returns the filename thus created to the calling function # # Arguments: # subdir = name of the directory and the file to be created under an existing directory # dir = an existing directory # ext = extension for the newly created filename # # Note: This function does not open the result file, it only creates a name for the file. # The file with the created name has to be opened seperately
-
Framework.Utils.file_Utils.
getXMLDataFile
(filename, path)[source]¶ Get the xml Datafile for ‘.py’ testcases
-
Framework.Utils.file_Utils.
get_absolute_path_from_start_directory
(relative_path, start_directory, extension='.json')[source]¶ DEPRECATED IN 2.9
Keyword developer must be aware that relative path can be relative to 1. testcase file 2. data file (if path is given in tag= value) start_directory must be an absolute path
-
Framework.Utils.file_Utils.
get_absolute_path_of_directory
(relative_path_of_dir, start_directory)[source]¶ DEPRECATED IN 2.9
When provided with a start directory and a relative path of a directory, this function returns the absolute path. Else returns the relative path
Keyword developer must be aware that relative path can be relative to 1. testcase file 2. data file (if path is given in tag= value) start_directory must be an absolute path
-
Framework.Utils.file_Utils.
get_current_position
(fd)[source]¶ Returns the file’s current position :Arguments:
fd - file descriptor got from open_fileReturn: current position of the file, -1 if error occurred
-
Framework.Utils.file_Utils.
get_extension_from_path
(path)[source]¶ Takes a filepath as input and returns the extension (extension is everything from the last dot to the end) If the input is a directory, the extension returned will be empty
- Arguments:
- path = path of the file or directory
-
Framework.Utils.file_Utils.
get_file_from_remote_server
(remote_ip, remote_uname, remote_passwd, src, dest, logfile=None)[source]¶ use scp to get file from remote server
-
Framework.Utils.file_Utils.
get_file_mode
(fd)[source]¶ Returns access mode with which file was opened. :Arguments:
fd - file descriptor got from open_fileReturn: mode
-
Framework.Utils.file_Utils.
get_file_name
(fd)[source]¶ Returns name of the file. :Arguments:
fd - file descriptor got from open_fileReturn: name of the file, empty string if there was an exception
-
Framework.Utils.file_Utils.
get_lines_between
(fd, startidx, endidx)[source]¶ Get lines between args[0] to args[1] :Arguments:
startidx - line index from which to send endidx - line index till to be sendReturn: lines between startidx and endidx
-
Framework.Utils.file_Utils.
get_modified_files
(src_dir, time_stamp, filetypes='')[source]¶ Finds the modified files(with any one of the filetypes) after a given time_stamp in the src_dir. If filetypes argument is empty, all modified files will be included. :Arguments:
- src_dir(string) - path of the directory where the files will be
- time_stamp(int/float) - time stamp value. Ex. time.time() will
- return current system time in seconds
- filetypes(sting) - comma separated file types. Ex. “.py, .xml”
Return: - modified_files(list) - list of files modified
-
Framework.Utils.file_Utils.
get_next_line
(fd)[source]¶ Returns the next line from the file each time it is being called. :Arguments:
fd - file descriptor got from open_fileReturn: next line
-
Framework.Utils.file_Utils.
get_parent_dir
(path, child)[source]¶ This function gets the parent directory of any a specified child folder from the given path
-
Framework.Utils.file_Utils.
is_file_closed
(fd)[source]¶ Returns true if file is closed, false otherwise. :Arguments:
fd - file descriptor got from open_fileReturn: True/False - description above
-
Framework.Utils.file_Utils.
is_softspace_required
(fd)[source]¶ Returns false if space explicitly required with print, true otherwise. :Arguments:
fd - file descriptor got from open_fileReturn: True/False - description above
-
Framework.Utils.file_Utils.
isatty
(fd)[source]¶ Returns True if the file is connected to a tty(-like) device, else False. :Arguments:
fd - file descriptor got from open_fileReturn: True/False - description above
-
Framework.Utils.file_Utils.
log_result
(oper, result)[source]¶ the methods in file_actions class use this to log the result of its operation
-
Framework.Utils.file_Utils.
move
(src, dst)[source]¶ Recursively move a file or directory (src) to another location (dst). If the destination is an existing directory, then src is moved inside that directory. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics.If the destination is on the current filesystem, then os.rename() is used. Otherwise, src is copied (using shutil.copy2()) to dst and then removed. :Arguments:
src - source file to be moved dst - target file/directory on which to be movedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
move_to_position
(fd, offset, **kwargs)[source]¶ Sets the file’s current position :Arguments:
fd - file descriptor got from open_file offset - number of bytes to be movedOptional: - whence -
0 - move offset positions from beginning of file 1 - move offset positions from current position of file 2 - move offset positions from end of file
Return: current position after movement
-
Framework.Utils.file_Utils.
move_to_text
(fd, pattern, n=1)[source]¶ seek to a text in the file :Arguments:
pattern - the regular expression pattern to search for in the file n - seek to the nth occurrence from beginning, default first occurrence
use negative indices for from the endReturn: True/False - based success or failure of seeking
-
Framework.Utils.file_Utils.
open_file
(newfile, mode)[source]¶ Opens the newfile in the mode specified and returns the filedescriptor which would be used by all the other file util operations. :Arguments:
newfile - name of the file to be opened mode - mode determines the mode in which the file has to be opened, i.e., read, write, append, etc.
- r - Opens a file for reading only. The file pointer is placed at
- the beginning of the file. This is the default mode.
- rb - Opens a file for reading only in binary format. The file
- pointer is placed at the beginning of the file. This is the default mode.
- r+ - Opens a file for both reading and writing. The file pointer
- placed at the beginning of the file.
- rb+ - Opens a file for both reading and writing in binary format.
- The file pointer placed at the beginning of the file.
- w - Opens a file for writing only. Overwrites the file if the file
- exists. If the file does not exist, creates a new file for writing.
- wb - Opens a file for writing only in binary format. Overwrites
- the file if the file exists. If the file does not exist, creates a new file for writing.
- w+ - Opens a file for both writing and reading. Overwrites the
- existing file if the file exists. If the file does not exist, creates a new file for reading and writing.
- wb+ - Opens a file for both writing and reading in binary format.
- Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.
- a - Opens a file for appending. The file pointer is at the end of
- the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
- ab - Opens a file for appending in binary format. The file pointer
- is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
- a+ - Opens a file for both appending and reading. The file pointer
- is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.
- ab+ - Opens a file for both appending and reading in binary format.
- The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.
Return: fd - file descriptor of the new file opened
-
Framework.Utils.file_Utils.
pathExists
(path)[source]¶ check if path exists , does not care if it is file or directory
-
Framework.Utils.file_Utils.
put_file_to_remote_server
(remote_ip, remote_uname, remote_passwd, src, dest, logfile=None)[source]¶ use scp to put file from remote server
-
Framework.Utils.file_Utils.
read
(fd, **kwargs)[source]¶ Reads at most size bytes from the file (less if the read hits EOF before obtaining size bytes). :Arguments:
fd - file descriptor got from open_fileOptional: size - number of bytes to be read Return: the string read from the file, None if not able to read
-
Framework.Utils.file_Utils.
readline
(fd, **kwargs)[source]¶ Reads one entire line from the file. A trailing newline character is kept in the string. :Arguments:
fd - file descriptor got from open_fileReturn: the line read
-
Framework.Utils.file_Utils.
readlines
(fd, **kwargs)[source]¶ Reads until EOF using readline() and return a list containing the lines. If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (possibly after rounding up to an internal buffer size) are read. :Arguments:
fd - file descriptor got from open_fileReturn: list of lines from the file
-
Framework.Utils.file_Utils.
recursive_findfile
(file_name, src_dir)[source]¶ Finds the file_name in the given directory. :Arguments:
- file_name(string) - name of the file(with extension) to be searched
- src_dir(string) - path of the dir where the file will be searched
Return: - output_path(string) - Path of the file(from src_dir) with extension
- if the file exists else False
-
Framework.Utils.file_Utils.
remove
(nfile)[source]¶ removes the file from the filesystem :Arguments:
nfile - filepath to be removedReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
searchFile
(filename, searchterm)[source]¶ search file for text, return True or False
-
Framework.Utils.file_Utils.
searchaftertext
(filename, startterm, searchterm)[source]¶ Start search after a certain text in a file
-
Framework.Utils.file_Utils.
truncate
(fd, **kwargs)[source]¶ Truncates the file’s size. If the optional size argument is present, the file is truncated to (at most) that size. :Arguments:
fd - file descriptor got from open_fileOptional: size - size up to which to truncate Return: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
write
(fd, string)[source]¶ Writes a string to the file. :Arguments:
fd - file descriptor got from open_file str - string to writeReturn: True/False - based on the success/failure of the operation
-
Framework.Utils.file_Utils.
writelines
(fd, seq)[source]¶ Writes a sequence of strings to the file. The sequence can be any iterable object producing strings, typically a list of strings. :Arguments:
fd - file descriptor got from open_file sequence - sequence of lines to be writtenReturn: True/False - based on the success/failure of the operation
Framework.Utils.import_utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.import_utils.
import_submodules
(package, recursive=True)[source]¶ Import all submodules of a package, recursively, including subpackages
Arguments: 1. package = (string) name of the package
(module) loader of the package- recrusive = (bool) True = load packages and modules from all sub-packages as well.
- (bool) False = load only first level of packages and modules, do not load modules from sub packages
Framework.Utils.list_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.list_Utils.
get_list_by_separating_strings
(list_to_be_processed, char_to_be_replaced=', ', str_to_replace_with_if_empty=None)[source]¶ This function converts a list of type: [‘str1, str2, str3’, ‘str4, str5, str6, str7’, None, ‘str8’] to: [[‘str1’, ‘str2’, ‘str3’], [‘str4’, ‘str5’, ‘str6’, ‘str7’], [], [‘str8’]]
Framework.Utils.print_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.print_Utils.
print_debug
(message, *args)[source]¶ Print a debug message to the terminal
-
Framework.Utils.print_Utils.
print_error
(message, *args)[source]¶ Prints an error message to the terminal
-
Framework.Utils.print_Utils.
print_exception
(exception)[source]¶ Print details of an exception to the console
-
Framework.Utils.print_Utils.
print_info
(message, *args)[source]¶ Print an info message to the terminal
-
Framework.Utils.print_Utils.
print_normal
(message, *args)[source]¶ Prints with out print type(-I-,-E-),with color cyan in bold TEXT
-
Framework.Utils.print_Utils.
print_notype
(message, *args)[source]¶ Prints with out print type(-I-,-E-),with color cyan in bold TEXT
-
Framework.Utils.print_Utils.
print_sub
(message, *args)[source]¶ Substitutes the string with *args tuple provided User has to provide the place holder for substitution in the message as {0}, {1}, {2} ..etc and the corresponding values in the *args.
Eg: print_sub(“My name is {0} {1}, I live in {2}”, ‘John’, ‘Doe’, ‘Texas’) Output: My Name is John Doe, I live in Texas
Framework.Utils.rest_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.rest_Utils.
check_ext_get_abspath
(relative_path, start_directory, list_extn=['.json', '.xml', '.txt'])[source]¶ This is wrapper function that gets and verifies extention of a file path and then calls get_abs_path_from_start_dir and returns the absolute path. start_directory must be an absolute path
-
Framework.Utils.rest_Utils.
dict_in_tuple
(element)[source]¶ This function evaluates the value of the files tag and returned validated data.
input: string
(path/to/file5.txt;content_type;(header1=value;header2=value2)), (path/to/file1.txt;content_type;(header3=value3;header4=value4))
output: dict
{ file5.txt: (file5.txt, open file5.txt (in binary mode), content_type, { header1: value, header2: value2 }), file1.txt: (file1.txt, open file5.txt (in binary mode), content_type, { header3: value3, header4: value4 }) }
-
Framework.Utils.rest_Utils.
dict_with_file_paths
(element)[source]¶ This function evaluates the value of the files tag and returned validated data.
input: string
file_group_name=path/to/file2.txt; path/to/file3.txt
output: dict
{ file_group_name_1: open file2.txt (in binary mode), file_group_name_2: open file3.txt (in binary mode), }
-
Framework.Utils.rest_Utils.
get_abs_path_from_start_dir
(relative_path, start_directory, extension='.json')[source]¶ When provided with a start directory and a relative path, this function returns the absolute path. Else returns the relative path start_directory must be an absolute path
-
Framework.Utils.rest_Utils.
get_all_file_paths
(element)[source]¶ This function evaluates the value of the files tag and returned validated data.
input: string
path/to/file1.txt, path/to/file2.txt
output: dict
{ file1.txt: open file1.txt (in binary mode), file2.txt: open file2.txt (in binary mode), }
-
Framework.Utils.rest_Utils.
get_type_of_api_response
(response)[source]¶ Takes API response as input and returns the type of the response whether it is json or xml or text Arguments:
response: It takes API response as input- Returns:
- returns the type of the response
-
Framework.Utils.rest_Utils.
just_a_tuple
(element)[source]¶ This function evaluates the value of the files tag and returned validated data.
input: string
(path/to/file4.txt;content_type), (path/to/file1.txt;content_type)
output: dict
{ file4.txt: (file4.txt, open file4.txt (in binary mode), content_type) file1.txt: (file1.txt, open file1.txt (in binary mode), content_type) }
-
Framework.Utils.rest_Utils.
remove_invalid_req_args
(credentials_dict, invalid_args)[source]¶ This function iterates through the invalid_args list and removes the elements in that list from credentials_dict and adds those to a new dictionary
- Returns:
- credentials_dict: Input dictionary after popping the elements in invalid_args invalid_args_dict: All popped elements.
-
Framework.Utils.rest_Utils.
resolve_credentials_for_rest
(credentials, element, datafile=None, system_name=None, variable_config='variable_config', var_sub='var_sub')[source]¶
-
Framework.Utils.rest_Utils.
resolve_exp_resp_string_as_list
(element)[source]¶ User given comma separated data is converted into a list. If no data is given, then an empty list is formed.
-
Framework.Utils.rest_Utils.
resolve_value_of_cert
(element)[source]¶ This function verifies the value of the parameter cert. cert takes in either a path to the certificate file or a tuple containing the cerificate file and if the key is not included in that file, then a file containing the key. Else None.
- This function evaluates user input for cookies. If a file path is given,
- then a cookiejar object is created and the contents of the file are loaded into the object. This object is then returned.
Else, a dictionary would be created out of the string given input = “foo=foo1; bar=bar1; ; =foobar; barfoo=” return value = {‘foo’: ‘foo1’, ‘bar’: ‘bar1’}
If the dictionary is empty at the end of the function, None is retuened.
-
Framework.Utils.rest_Utils.
resolve_value_of_data
(element, datafile)[source]¶ This function validates the user input for data. If the input is a file path, then a file object is returned. if the input is in bytes, then the input is retuned. else, dictionary is returned.
input = “foo=foo1; bar=bar1; ; =foobar; barfoo=” return value = {‘foo’: ‘foo1’, ‘bar’: ‘bar1’}If the dict is empty at the end of the function, None is returned
-
Framework.Utils.rest_Utils.
resolve_value_of_files
(element)[source]¶ This function evaluates the value of the files tag and returned validated data.
input: string
path/to/file1.txt, file_group_name=path/to/file2.txt; path/to/file3.txt, (path/to/file4.txt;content_type), (path/to/file5.txt;content_type;(header1=value;header2=value2))
output: dict
{ file1.txt: open file1.txt (in binary mode), file_group_name_1: open file2.txt (in binary mode), file_group_name_2: open file3.txt (in binary mode), file4.txt: (file4.txt, open file4.txt (in binary mode), content_type) file5.txt: (file5.txt, open file5.txt (in binary mode), content_type,
{ header1: value, header2: value2 })}
-
Framework.Utils.rest_Utils.
resolve_value_of_json
(element, datafile=None, system_name=None, variable_config=None, var_sub=None)[source]¶ Input string or file is converted to a json object. If an exception occurs, ‘Error’ is returned.
-
Framework.Utils.rest_Utils.
resolve_value_of_redirects
(element)[source]¶ If allow_redirects is specifically set not no (case ignored), then and only then allow_redirects is set to False. Else is set to true.
-
Framework.Utils.rest_Utils.
resolve_value_of_stream
(element)[source]¶ This function verifies the value of the parameter stream. If set explicitly to ‘no’, it would be evaluated as False, else True.
-
Framework.Utils.rest_Utils.
resolve_value_of_timeout
(element)[source]¶ The value given by the User, either in the datafile or in the TC, for the “timeout” parameter is assessed here. The User can either give a single value or comma separated value.
- Requests docs for timeout:
- ** :param timeout: (optional) How long to wait for the server to send data
- before giving up, as a float, or a (connect timeout, read timeout) tuple.
If a single value is given, then that value is used for both connect timeout and read timeout
If more than two comma separated values are given, only the first two are considered.
If the input is invalid (i.e. it is neither an integer, nor a float), then this function throws out an error, but keeps the user specified values, so that the Error can be caught when the keyword actually executes.
Framework.Utils.selenium_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.selenium_Utils.
create_display
()[source]¶ Create a virtual display Default size is 1920x1080 as smaller resolution may cause problem in firefox
-
Framework.Utils.selenium_Utils.
evaluate_argument_value
(xpath_or_tagname, datafile)[source]¶ This function takes checks if the given xpath_or_tagname exists in the datafile and returns its value. Else returns None.
-
Framework.Utils.selenium_Utils.
execute_script
(browser_instance, user_script)[source]¶ To exceute a user provided script
-
Framework.Utils.selenium_Utils.
get_browser_details
(browser, datafile=None, br_name='browser_name', def_name_tuple=('DEF_ecf', 'DEF_et'), bw_comp=('element_config_file', 'element_tag'), **kwargs)[source]¶ This function returns the correct browser details by evaluating the data files and the element config files
-
Framework.Utils.selenium_Utils.
get_default_tag_for_locs
(config_file, element_tag, locator_types)[source]¶ This function gets the default value of the locator_type from the element config file.
This function checks for default tags under the current <browser>
-
Framework.Utils.selenium_Utils.
get_element_from_config_file
(config_file, element_tag, child_tag, is_locator_type='no', default=False)[source]¶ Gets default locators from json file
-
Framework.Utils.selenium_Utils.
get_final_json_values
(element, final_dict, mapper, def_name_tuple)[source]¶ This gets JSON values for every element and updates the dictionary
-
Framework.Utils.selenium_Utils.
get_json_value_from_path
(path, file, default)[source]¶ This function returns the value of json key (it can also be a path) obtained from the json file.
-
Framework.Utils.selenium_Utils.
get_mapped_to_elements
(mapper)[source]¶ The mapper list contains all the element names that have been mapped to by other elements
-
Framework.Utils.selenium_Utils.
get_mappers_for_all_elements
(final_dict, def_name_tuple)[source]¶ This function gets the user defined mappings for tags and stores them in a mapper dictionary
-
Framework.Utils.selenium_Utils.
save_screenshot_onerror
(status, current_browser)[source]¶ To get the filename, directory name and to take screenshot of the current browser window
-
Framework.Utils.selenium_Utils.
split_kwargs_on_tag_equalto
(kwargs, datafile, browser)[source]¶ This function splits kwargs on tag= If the value is an xpath, then it follows the xpath and returns the value Else, if is it a singular tag name, then it searched for a tag with that name under the current <browser>
Framework.Utils.snmp_utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Framework.Utils.string_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.string_Utils.
compare_string_using_regex
(response, list_of_regex_patterns)[source]¶ Checks whether each regular expression is present in response and if all are present returns True else False
-
Framework.Utils.string_Utils.
conv_str_to_bool
(text, mapping_dict=None)[source]¶ Map a text to a boolean value. The default text to bool mapping is provided in the default_map dict below, however text and mapping_dict as inputs to map as per needs. default_map = {‘yes’: True, ‘y’: True, ‘no’: False, ‘n’: False }
-
Framework.Utils.string_Utils.
get_list_from_varconfigfile
(string, varconfigfile, start_pat='${', end_pat='}')[source]¶
-
Framework.Utils.string_Utils.
replace_from_varconfig
(varconfigfile, details_dict, var_sub=None)[source]¶ replace variables with values from variable config file
-
Framework.Utils.string_Utils.
return_quote
(a, start_pat='${', end_pat='}')[source]¶ - return the list of element that needs to be substituted in a string
Parameters: a – Returns:
-
Framework.Utils.string_Utils.
seek_next
(pattern, data)[source]¶ find the next pattern in the data and return its position
-
Framework.Utils.string_Utils.
strip_white_spaces
(input_list)[source]¶ Takes a list of string as input Removes the leading and trailing white spaces from each string in the list Returns an output list having the string elements with leading and trailing white spaces removed
-
Framework.Utils.string_Utils.
sub_from_varconfig
(varconfigfile, string_list, var_sub=None, start_pat='${', end_pat='}')[source]¶ Replaces the string variables with their values taken from varconfig_file. :Arguments:
1. varconfigfile - xml file or list of xml files from which the values will be taken for subtitution 2. string_list - List of command strings, where the variables will be replaced by the config values 3. var_sub(string) = the pattern [var_sub] in the testdata commands,
start_prompt, end_prompt, verification search will substituted with this value.Returns: - List of command strings with replaced values or False(boolean) - if any one of the variables does not exist in varconfig_file
-
Framework.Utils.string_Utils.
sub_from_varconfigfile
(string, varconfigfile, start_pat='${', end_pat='}')[source]¶
-
Framework.Utils.string_Utils.
sub_from_varsub
(string, var_sub)[source]¶ Replace the pattern [var_sub] in the string with the value of var_sub
Arguments: 1. string(string) = input string which needs substitution 3. var_sub(string) = value to replace the pattern [var_sub]
in the input string
Returns: - updated string
Framework.Utils.telnet_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
class
Framework.Utils.telnet_Utils.
Tnet_Comm
(target, port='', uid='', pid='', logfile='telnet_log', cmd_rsp=None)[source]¶ Bases:
object
Does communication with the NE/Server using Telnet protocol Write/Read commands to and from the NE/Server
-
get_response
(cmd_string, prompt, timeout=120)[source]¶ Reads the output till the prompt and returns the result and reports Failure on mismatch of response
-
Framework.Utils.testcase_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.testcase_Utils.
TCOBJ
= <WarriorCore.Classes.testcase_utils_class.TestcaseUtils object>¶
-
Framework.Utils.testcase_Utils.
add_defects_to_resultfile
(resultfile, defect_id)[source]¶ Adds defects if any to the testcase result file
-
Framework.Utils.testcase_Utils.
append_result_files
(dst_resultfile, kw_resultfile_list, dst_root='Testcase')[source]¶ append kw/system result xml files into testcase result xml file
-
Framework.Utils.testcase_Utils.
compute_status_using_impact
(input_status_list, input_impact_list, status=True)[source]¶ Computes the status from the list of input status and input impact
-
Framework.Utils.testcase_Utils.
compute_status_without_impact
(input_status_list, status=True)[source]¶ Computes the system status from the list of step status adn impact
-
Framework.Utils.testcase_Utils.
compute_system_resultfile
(kw_resultfile_list, resultsdir, system_name)[source]¶ Generates a system resultfile from the list of keyword result files
-
Framework.Utils.testcase_Utils.
convertLogic
(text)[source]¶ Converts True -> PASS False -> FAIL ERROR -> ERROR EXCEPTION -> ERROR
-
Framework.Utils.testcase_Utils.
get_context_from_xmlfile
(element)[source]¶ Gets the context value of a step/testcase/suite from the testcase.xml/testsuite.xml/project.xml file
-
Framework.Utils.testcase_Utils.
get_defonerror_fromxml_file
(filepath)[source]¶ Gets the default on error value of a step/testcase/suite from the testcase.xml/testsuite.xml/project.xml file
-
Framework.Utils.testcase_Utils.
get_description_from_xmlfile
(element)[source]¶ Gets the description value of a step/testcase/suite from the testcase.xml/testsuite.xml/project.xml file
-
Framework.Utils.testcase_Utils.
get_impact_from_xmlfile
(element)[source]¶ Gets the impact value of a step/testcase/suite from the testcase.xml/testsuite.xml/project.xml file
-
Framework.Utils.testcase_Utils.
get_requirement_id_list
(testcase_filepath)[source]¶ gets the list of requirements for the testcase
-
Framework.Utils.testcase_Utils.
get_steps_list
(testcase_filepath)[source]¶ Takes the location of any Testcase xml file as input Returns a list of all the step elements present in the Testcase
Arguments: - testcase_filepath = full path of the Testcase xml file
-
Framework.Utils.testcase_Utils.
get_wdesc_string
(function_object)[source]¶ Gets the WDesc string from the function object
-
Framework.Utils.testcase_Utils.
pConvertLogical
(text)[source]¶ map NO=false, YES=True and return the bool to the calling function
-
Framework.Utils.testcase_Utils.
pCustomTag
(name, txt)[source]¶ Adds a note to the testcase xml result file under the current tag :Arguments:
- txt = (string) a text description of the step
- print_type(string) = type of print - info/debug/error/exception/warn/None
Returns: None
-
Framework.Utils.testcase_Utils.
pDriver
(driver_txt)[source]¶ create a driver tag in testcase result xml file
-
Framework.Utils.testcase_Utils.
pKeyword
(keyword_txt, driver_txt)[source]¶ Creates a keyword tag as direct child to the <Testcase> tag
-
Framework.Utils.testcase_Utils.
pNote
(txt, print_type='info')[source]¶ Adds the provided txt as a note to the test case xml result file under the current tag and also prints the txt to the console. :Arguments:
- txt (string) = a text to be written to result file and printed to the console.
Returns: None
-
Framework.Utils.testcase_Utils.
pNote_level
(txt, ptype='info', level=None, ptc=True)[source]¶ Create Note at the provided level
-
Framework.Utils.testcase_Utils.
pReportRequirements
(requirement_id)[source]¶ Report the requirement-id to the xml result file
-
Framework.Utils.testcase_Utils.
pStep
(step_txt='')[source]¶ create a step tag in testcase result xml file
-
Framework.Utils.testcase_Utils.
pSubKeyword
(subkey_txt='')[source]¶ Adds the provided txt as a note to the test case xml result file under the current tag and also prints the txt to the console. :Arguments:
- txt (string) = a text to be written to result file and printed to
- the console.
Returns: None
-
Framework.Utils.testcase_Utils.
pSubStep
(substep_txt='')[source]¶ Creates a substep tag in test case result xml file
-
Framework.Utils.testcase_Utils.
pTestResult
(text, resultfile)[source]¶ report test case reult in result xml file
-
Framework.Utils.testcase_Utils.
pTestcase
()[source]¶ Creates a root tag in the testcase result xml file
-
Framework.Utils.testcase_Utils.
reportKeywordStatus
(status, kw_name)[source]¶ Reports the status of a Keyword to the testcase xml result file base don the received status On receiving a True reports keyword as Passed On receiving a False reports keyword as Failure On receiving a Skip reports skips the keyword execution
Arguments: - status = (bool) True or False
Returns: None
-
Framework.Utils.testcase_Utils.
reportStatus
(status, text='', level='Keyword')[source]¶ Reports the status of a Keyword to the testcase xml result file base don the received status On receiving a True reports keyword as Passed On receiving a False reports keyword as Failure On receiving a Skip reports skips the keyword execution
Arguments: - status = (bool) True or False
- text = (string) any useful description
- level = (string) only supported value currently is Keyword
Returns: None
-
Framework.Utils.testcase_Utils.
reportWarning
(status, text='', level='subStep')[source]¶ Reports the status of a substep to the testcase xml result file base don the received status On receiving a True reports substep as Passed On receiving a False raises a warning On receiving a Skip reports skips the substep execution
Arguments: - status = (bool) True or False
- text = (string) any useful description
- level = (string) only supported value currently is subStep
Returns: None
-
Framework.Utils.testcase_Utils.
report_substep_status
(status)[source]¶ Reports the status of a substep to the test case xml result file based on the received status On receiving a True reports substep as Passed On receiving a False raises a warning On receiving a Skip reports substep execution as skipped
Arguments: - status(bool) = status of the executed substep (True or False)
Returns: None
-
Framework.Utils.testcase_Utils.
reportsubkeywordstatus
(status, text='', level='Subkeyword')[source]¶ - Reports the status of a Keyword to the testcase xml result file baseid on
- the received status
On receiving a True reports keyword as Passed On receiving a False reports keyword as Failure On receiving a Skip reports skips the keyword execution
Arguments: - status = (bool) True or False
- text = (string) any useful description
- level = (string) Default: SubKeyword
Returns: None
-
Framework.Utils.testcase_Utils.
update_arguments
(args)[source]¶ adds step_num attribute to the step tag in test case result xml file
Framework.Utils.xml_Utils module¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Framework.Utils.xml_Utils.
compare_xml
(xml1, xml2, output_file=False, sorted_json=True, remove_namespaces=False, tag_list=[], attrib_list=[])[source]¶ This will compare two xml files or strings by converting to json and then sorting and by default giving the sorted files and writing the difference to a diff file.
- Arguments:
- xml1 : The first xml among the two xml’s which
- needs to be compared
- xml2 : The second xml among the two xml’s
- which needs to be compared
- output_file : It contains the difference between
- the two sorted json objects
- sorted_json : By default we are returning the sorted json
- files and if the user selects sorted_json as False, not returning the fileS
- remove_namespaces: If the user specifies remove_namespaces
- as True will remove namespaces and then compare xml’s
- tag_list: If user specifies tag names in tag_list,
- will remove those tags and then compare xml’s
7. attrib_list: If user specifies attribute names in the attrib_list, will remove those attributes and then compare xml’s
- Returns:
- Returns a tuple that contains
- comparison status two sorted json files or two None depends on sorted_json value output file path or diff_output depends on output_file value
-
Framework.Utils.xml_Utils.
compare_xml_using_xpath
(response, list_of_xpath, list_of_expected_api_responses)[source]¶ Will get each xpath in list of xpath and get the value of that xpath in xml response Compares the value with the expected_api_response If all values matches returns True else False
-
Framework.Utils.xml_Utils.
convert_dom_to_string
(element)[source]¶ Converts a dom element into a string
-
Framework.Utils.xml_Utils.
convert_element_to_string
(element)[source]¶ Converts the provided xml element to string
-
Framework.Utils.xml_Utils.
convert_xml_to_list_of_dict
(file_name)[source]¶ Takes xml file path as input and converts to list of dictionaries Arguments:
file_name : It takes xml file path as input- Returns:
- list_of_dict: list of dictionaries where keys are tag names and values are respective text of the tag.
-
Framework.Utils.xml_Utils.
create_element
(tagname='', text='', **kwargs)[source]¶ create an xml element with given name and a dict of attribute
-
Framework.Utils.xml_Utils.
create_subelement
(parent, tag, attrib)[source]¶ Creates a subelement with given tag and attributes under the parent element
-
Framework.Utils.xml_Utils.
del_attributes_from_xml
(xml, attrib_list=[])[source]¶ It deletes the attributes either by their names or xpath
- Arguments:
- 1.xml: It takes xml file path or xml string as input 2.attrib_list: It contains list of attributes which needs to be removed
- Returns:
- It returns xml string
-
Framework.Utils.xml_Utils.
del_tag_from_element
(ele, tag)[source]¶ Delete a subelement with specific tag from an xml element object return the deleted subelement if pass return False if subelement not found
It deletes the tags either by their names or xpath
- Arguments:
- 1.xml: It takes xml file path or xml string as input 2.tag_list: It contains list of tags which needs to be removed
- Returns:
- It returns xml string
-
Framework.Utils.xml_Utils.
getChildAttributebyParentTag
(datafile, pnode, cnode, cattrib)[source]¶ Find the attribute in child node by traversing through the parent node in the given file datafile = xml file searched pnode = parent node cnode = child node cattrob = child node attrib
-
Framework.Utils.xml_Utils.
getChildElementWithSpecificXpath
(start, xpath)[source]¶ This method takes a xml file or parent element as input and finds the first child containing specified xpath
Returns the child element.
Arguments: start = xml file or parent element xpath = a valid xml path value as supported by python, refer https://docs.python.org/2/library/xml.etree.elementtree.html
-
Framework.Utils.xml_Utils.
getChildElementsListWithSpecificXpath
(parent, xpath)[source]¶ This method takes a parent element as input and finds all the children containing specified xpath
Returns a list of child elements.
Arguments: parent = parent element xpath = a valid xml path value as supported by python, refer https://docs.python.org/2/library/xml.etree.elementtree.html
-
Framework.Utils.xml_Utils.
getChildElementsListWithTagAttribValueMatch
(parent, tag, attrib, value)[source]¶ This method takes a parent element as input and finds all the sub elements (children) containing specified tag and an attribute with the specified value.
Returns a list of child elements.
Arguments: parent = parent element tag = tag value of the sub-element(child) to be searched for. attrib = attribute name for the sub-element with above given tag should have. value = attribute value that the sub-element with above given tag, attribute should have.
-
Framework.Utils.xml_Utils.
getChildNodeTextaslist
(parentnode, childnode)[source]¶ Get all child node text of the parent node and return as a list
-
Framework.Utils.xml_Utils.
getChildTextbyOtherChild
(datafile, pnode, cnode, cvalue, rnode)[source]¶ Searches XML file for the parent node. Finds the 1st child node and checks its value if value is a match, then search for second child and return its value datafile = xml file searched pnode = parent node cnode = child node cvalue = child node value rnode = reference node or False if doesn’t exist
-
Framework.Utils.xml_Utils.
getChildTextbyParentAttribute
(datafile, pnode, patt, pattval, cnode)[source]¶ Seraches XML file for the parent node with a specific value. Finds the child node and returns its text datafile = xml file searched pnode = parent node patt = parent node attribute patval = parent node attribute value cnode = child node
-
Framework.Utils.xml_Utils.
getChildTextbyParentTag
(datafile, pnode, cnode)[source]¶ Seraches XML file for the first parent. Finds the child node and returns its text datafile = xml file searched pnode = parent node cnode = child node
-
Framework.Utils.xml_Utils.
getConfigElementTextWithSpecificXpath
(datafile, xpath)[source]¶ This method takes an xml document as input and finds the first sub element (parent/children) containing specified xpath which should be a filepath to a netconf config file
Returns the element text attribute
Arguments: parent = parent element xpath = a valid xml path value as supported by python, refer https://docs.python.org/2/library/xml.etree.elementtree.html
-
Framework.Utils.xml_Utils.
getElementListWithSpecificXpath
(datafile, xpath)[source]¶ This method takes an xml document as input and finds all the sub elements (parent/children) containing specified xpath
Returns a list of matching elements.
Arguments: parent = parent element xpath = a valid xml path value as supported by python, refer https://docs.python.org/2/library/xml.etree.elementtree.html
-
Framework.Utils.xml_Utils.
getElementStringWithSpecificXpath
(datafile, xpath)[source]¶ This method takes an xml document as input and finds the first sub element (parent/children) containing specified xpath
Returns the element as a string
Arguments: parent = parent element xpath = a valid xml path value as supported by python, refer https://docs.python.org/2/library/xml.etree.elementtree.html
-
Framework.Utils.xml_Utils.
getElementWithTagAttribValueMatch
(start, tag, attrib, value)[source]¶ - When start is an xml datafile, it finds the root and first element with:
- tag, attrib, value.
- Or when it’s an xml element, it finds the first child element with:
- tag, attrib, value.
If there is not a match, it returns False.
-
Framework.Utils.xml_Utils.
getElementsListWithTagAttribValueMatch
(datafile, tag, attrib, value)[source]¶ This method takes an xml document as input and finds all the sub elements (parent/children) containing specified tag and an attribute with the specified value.
Returns a list of matching elements.
Arguments: datafile = input xml file to be parsed. tag = tag value of the sub-element(parent/child) to be searched for. attrib = attribute name for the sub-element with above given tag should have. value = attribute value that the sub-element with above given tag, attribute should have.
-
Framework.Utils.xml_Utils.
getNodeCount
(filename, node)[source]¶ Get the Number of subnodes under the node specified in the xml file
-
Framework.Utils.xml_Utils.
getNodeListbyAttribute
(parentnode, childnode, attribute)[source]¶ Traverse through all the child node from the parent node and get the attribute from each child node and return all the attrubute as a list
-
Framework.Utils.xml_Utils.
getNodeValuebyAttribute
(filename, node, attribute)[source]¶ Get Node value from the Attribute from the xml fle
-
Framework.Utils.xml_Utils.
getNodebyParentandChildrenMatch
(datafile, pnode, cnode, cvalue, rnode, rvalue, lnode)[source]¶ Searches XML file for the parent node. Finds the 1st child node and checks its value if value is a match, then search for second child and check if its value matches. If that is a match, then obtain the value of the third child datafile = xml file searched pnode = parent node cnode = child node cvalue = child node value rnode = reference node rvalue = refernce node value lnode = lastnode
-
Framework.Utils.xml_Utils.
getValueListbyTagFromString
(response, tag)[source]¶ Given a response object, return the list of value tag present in the object
-
Framework.Utils.xml_Utils.
getValuebyAttribute
(filename, attribute, tag)[source]¶ Get the value of the attribute in a tag from the xml file
-
Framework.Utils.xml_Utils.
getValuebyTag
(filename, tag)[source]¶ Get the value from the tag name from the xml file
-
Framework.Utils.xml_Utils.
getValuebyTagFromResponse
(response, tag)[source]¶ Given a xml response object, returns the value for a particular tag
-
Framework.Utils.xml_Utils.
getValuebyTagFromStringWithXpath
(response, xpathString, ns)[source]¶ Given a response object, return the value from the xpath and namespace combination
-
Framework.Utils.xml_Utils.
get_all_child_nodes
(parent_node)[source]¶ Takes a minidom parent node as input and returns a list of all child nodes
-
Framework.Utils.xml_Utils.
get_attributevalue_from_directchildnode
(parentnode, childname, attribute)[source]¶ Takes a parent node element as input Searches for the first child with the provided name under the parent node If child is present returns the value for the requested child attribute (the returns None if the child does not have that attributte) Returns False if child is not found under the parent
-
Framework.Utils.xml_Utils.
get_child_node_list
(parentnode)[source]¶ Returns the list of children under to a provided parent node
-
Framework.Utils.xml_Utils.
get_child_with_matching_tag
(parent, tag_name)[source]¶ Find whether Child node with tag = tag_name exists, if exists then return the child node
Gets the list of elements with matching tag_name
-
Framework.Utils.xml_Utils.
get_children_as_dict
(parent)[source]¶ For a given parent object, return all children as a dictionary with the childs tag as key
-
Framework.Utils.xml_Utils.
get_document_root
(filename)[source]¶ Returns the root element of a xml document
-
Framework.Utils.xml_Utils.
get_element_by_attribute
(xml_file, tag_name, attr_name, attr_value)[source]¶ Gets the element with matching tag_name, attribute name and attribute value
-
Framework.Utils.xml_Utils.
get_elements_by_tagname_ignore_ns
(filename, element_tag)[source]¶ “Parses an xml using minidom and gets all the elements with matching tag names in the file, ignores namespaces in the tag names
-
Framework.Utils.xml_Utils.
get_first_child
(node)[source]¶ Gets the first child of a given node Returns None if there is no child for the node.
-
Framework.Utils.xml_Utils.
get_last_child
(node)[source]¶ Gets the last child of a given node Returns None if there is no child for the node.
-
Framework.Utils.xml_Utils.
get_last_level_children
(node, tag)[source]¶ Find and return the last level children
-
Framework.Utils.xml_Utils.
get_matching_firstlevel_children_from_node
(node, child_tag)[source]¶ Takes a xml file as input and returns a list of first child elements to the root that matches the provided tag
-
Framework.Utils.xml_Utils.
get_matching_firstlevel_children_from_root
(filename, child_tag)[source]¶ Takes a xml file as input and returns a list of first child elements to the root that matches the provided tag
-
Framework.Utils.xml_Utils.
get_node
(filename, node_name)[source]¶ Gets seraches for a node under the root and returns the node
-
Framework.Utils.xml_Utils.
get_node_list_iterative
(filename, node_name)[source]¶ Find all matching subelements and returns iterable elements
-
Framework.Utils.xml_Utils.
get_text_from_direct_child
(parentnode, childname)[source]¶ Takes a parent node element as input Searches for the first child with the the provided name under the parent node If child is present return the text of the child (returned text will be empty if the child has no text Returns False if child is not found under the parent
-
Framework.Utils.xml_Utils.
list_path_responses_datafile
(datafile, system_name)[source]¶ Returns the path_list and responses_list path_list contains list of response_path tags under the comparison_mode under the system with given system_name in the datafile responses_list contains list of response_value tags under the expected_api_response under the system with given system_name in datafile
-
Framework.Utils.xml_Utils.
nodeExists
(filename, node)[source]¶ Find whether the Node exists in the xml file
-
Framework.Utils.xml_Utils.
recursive_delete_among_children
(root, element)[source]¶ - It performs a recursive operation among the children in the xml file
- and finds the child that matches with the element and deletes it.
- Arguments:
- 1.parent: It takes the root element in the xml file as input 2.element: It is the tag which we want to delete
- Returns:
- True
-
Framework.Utils.xml_Utils.
removenms
(xml)[source]¶ - It accepts the xml file path or string as input and remove
- the name spaces.
- Arguments:
- xml: An input xml file path or xml string in which the name spaces
- needs to be removed
- Returns:
- xml_string
-
Framework.Utils.xml_Utils.
safe_subelement
(parent, tagname, text='', **kwargs)[source]¶ create or overwrite a child element under the parent
-
Framework.Utils.xml_Utils.
verifyNodesValueMatch
(datafile, pnode, cnode, cvalue, rnode, rvalue, bnode, bvalue, dnode=None, dvalue=None)[source]¶ Searches XML file for the parent node. Finds the 1st child node and checks its value if value is a match, then search for second child and check if its value matches datafile = xml file searched pnode = parent node cnode = child node cvalue = child node value rnode = reference node rvalue = refernce node value
-
Framework.Utils.xml_Utils.
verifyParentandChildrenMatch
(datafile, pnode, cnode, cvalue, rnode, rvalue)[source]¶ Searches XML file for the parent node. Finds the 1st child node and checks its value if value is a match, then search for second child and check if its value matches datafile = xml file searched pnode = parent node cnode = child node cvalue = child node value rnode = reference node rvalue = refernce node value
Module contents¶
Copyright 2017, Fujitsu Network Communications, Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.