utils¶
dataset¶
- toolium.utils.dataset.convert_file_to_base64(file_path)[source]¶
Return the content of a file given its path encoded in Base64. If a base path was previously set by using the set_file_path() function, the file path specified must be relative to that path.
- Parameters
path (file) – file path using slash as separator (e.g. “resources/files/doc.txt”)
- Returns
string with the file content encoded in Base64
- toolium.utils.dataset.get_file(file_path)[source]¶
Return the content of a file given its path. If a base path was previously set by using the set_file_path() function, the file path specified must be relative to that path.
- Parameters
path (file) – file path using slash as separator (e.g. “resources/files/doc.txt”)
- Returns
string with the file content
- toolium.utils.dataset.get_message_property(param, language_terms, language_key)[source]¶
Return the message for the given param, using it as a key in the list of language properties. Dot notation is used (e.g. “home.button.send”).
- Parameters
param – message key
language_terms – dict with language terms
language_key – language key
- Returns
the message mapped to the given key in the given language
- toolium.utils.dataset.get_translation_by_poeditor_reference(reference, poeditor_terms)[source]¶
Return the translation(s) for the given POEditor reference from the given terms in poeditor_terms.
- Parameters
reference – POEditor reference
poeditor_terms – poeditor terms
- Returns
list of strings with the translations from POEditor or string with the translation if only one was found
- toolium.utils.dataset.get_value_from_context(param, context)[source]¶
Find the value of the given param using it as a key in the context storage dictionary (context.storage) or in the context object itself. The key might be comprised of dotted tokens. In such case, the searched key is the first token. The rest of the tokens are considered nested properties/objects. So, for example, in the basic case, “last_request_result” could be used as key that would be searched into context storage or the context object itself. In a dotted case, “last_request.result” is searched as a “last_request” key in the context storage or as a property of the context object whose name is last_request. In both cases, when found, “result” is considered (and resolved) as a property into the returned value.
There is not limit in the nested levels of dotted tokens, so a key like a.b.c.d will be tried to be resolved as:
- context.storage[‘a’].b.c.d
or
context.a.b.c.d
- Parameters
param – key to be searched (e.g. “last_request_result” / “last_request.result”)
context – Behave context object
- Returns
mapped value
- toolium.utils.dataset.hide_passwords(key, value)[source]¶
Return asterisks when the given key is a password that should be hidden.
- Parameters
key – key name
value – value
- Returns
hidden value
- toolium.utils.dataset.map_json_param(param, config, copy=True)[source]¶
Find the value of the given param using it as a key in the given dictionary. Dot notation is used, so for example “service.vamps.user” could be used to retrieve the email in the following config example: {
- “services”:{
- “vamps”:{
“user”: “cyber-sec-user@11paths.com”, “password”: “MyPassword”
}
}
}
- Parameters
param – key to be searched (dot notation is used, e.g. “service.vamps.user”).
config – configuration dictionary
copy – boolean value to indicate whether to work with a copy of the given dictionary or not,
in which case, the dictionary content might be changed by this function (True by default) :return: mapped value
- toolium.utils.dataset.map_one_param(param)[source]¶
Analyze the pattern in the given string and find out its transformed value. Available tags and replacement values:
[CONF:xxxx] Value from the config dict in project_config global variable for the key xxxx (dot notation is used for keys, e.g. key_1.key_2.0.key_3) [LANG:xxxx] String from the texts dict in language_terms global variable for the key xxxx, using the language specified in language global variable (dot notation is used for keys, e.g. button.label) [POE:xxxx] Definition(s) from the POEditor terms list in poeditor_terms global variable for the term xxxx [TOOLIUM:xxxx] Value from the toolium config in toolium_config global variable for the key xxxx (key format is section_option, e.g. Driver_type) [CONTEXT:xxxx] Value from the behave context storage dict in behave_context global variable for the key xxxx, or value of the behave context attribute xxxx, if the former does not exist [ENV:xxxx] Value of the OS environment variable xxxx [FILE:xxxx] String with the content of the file in the path xxxx [BASE64:xxxx] String with the base64 representation of the file content in the path xxxx
- Parameters
param – string parameter
- Returns
transformed value or the original string if no transformation could be applied
- toolium.utils.dataset.map_param(param, context=None)[source]¶
Transform the given string by replacing specific patterns containing keys with their values, which can be obtained from the Behave context or from environment files or variables. See map_one_param function for a description of the available tags and replacement logic.
- Parameters
param – string parameter
context – Behave context object (deprecated parameter)
- Returns
string with the applied replacements
- toolium.utils.dataset.map_toolium_param(param, config)[source]¶
Find the value of the given param using it as a key in the given toolium configuration. The param is expected to be in the form <section>_<property>, so for example “TextExecution_environment” could be used to retrieve the value of this toolium property (i.e. the string “QA”): [TestExecution] environment: QA
- Parameters
param – key to be searched (e.g. “TextExecution_environment”)
config – toolium config object
- Returns
mapped value
- toolium.utils.dataset.replace_param(param, language='es', infer_param_type=True)[source]¶
Apply transformations to the given param based on specific patterns. Available replacements:
[STRING_WITH_LENGTH_XX] Generates a fixed length string [INTEGER_WITH_LENGTH_XX] Generates a fixed length integer [STRING_ARRAY_WITH_LENGTH_XX] Generates a fixed length array of strings [INTEGER_ARRAY_WITH_LENGTH_XX] Generates a fixed length array of integers [JSON_WITH_LENGTH_XX] Generates a fixed length JSON [MISSING_PARAM] Generates a None object [NULL] Generates a None object [TRUE] Generates a boolean True [FALSE] Generates a boolean False [EMPTY] Generates an empty string [B] Generates a blank space [RANDOM] Generates a random value [RANDOM_PHONE_NUMBER] Generates a random phone number following the pattern +34654XXXXXX [TIMESTAMP] Generates a timestamp from the current time [DATETIME] Generates a datetime from the current time [NOW] Similar to DATETIME without milliseconds; the format depends on the language [NOW(%Y-%m-%dT%H:%M:%SZ)] Same as NOW but using an specific format by the python strftime function of the datetime module [NOW + 2 DAYS] Similar to NOW but two days later [NOW - 1 MINUTES] Similar to NOW but one minute earlier [NOW(%Y-%m-%dT%H:%M:%SZ) - 7 DAYS] Similar to NOW but seven days before and with the indicated format [TODAY] Similar to NOW without time; the format depends on the language [TODAY + 2 DAYS] Similar to NOW, but two days later [STR:xxxx] Cast xxxx to a string [INT:xxxx] Cast xxxx to an int [FLOAT:xxxx] Cast xxxx to a float [LIST:xxxx] Cast xxxx to a list [DICT:xxxx] Cast xxxx to a dict [UPPER:xxxx] Converts xxxx to upper case [LOWER:xxxx] Converts xxxx to lower case
If infer_param_type is True and the result of the replacement process is a string, this function also tries to infer and cast the result to the most appropriate data type, attempting first the direct conversion to a Python built-in data type and then, if not possible, the conversion to a dict/list parsing the string as a JSON object/list.
- Parameters
param – parameter value
language – language to configure date format for NOW and TODAY (‘es’ or other)
infer_param_type – whether to infer and change the data type of the result or not
- Returns
data with the correct replacements
download_files¶
driver_utils¶
driver_wait_utils¶
path_utils¶
- toolium.utils.path_utils.get_valid_filename(s, max_length=100)[source]¶
Returns the given string converted to a string that can be used for a clean filename. Removes leading and trailing spaces; converts anything that is not an alphanumeric, dash or underscore to underscore; converts behave examples separator ` – @` to underscore. It also cuts the resulting name to max_length.
@see https://github.com/django/django/blob/master/django/utils/text.py
poeditor¶
- toolium.utils.poeditor.assert_poeditor_response_code(response_data, status_code)[source]¶
Check status code returned in POEditor response
- Parameters
response_data – data received in poeditor API response as a dictionary
status_code – expected status code
- toolium.utils.poeditor.download_poeditor_texts(context=None, file_type='json')[source]¶
Executes all steps to download texts from POEditor and saves them to a file in output dir
- Parameters
context – behave context (deprecated)
file_type – file type (only json supported)
- Returns
N/A
- toolium.utils.poeditor.export_poeditor_project(project_info, lang, file_type)[source]¶
Export all texts in project to a given file type
- Parameters
project_info – project info
lang – language configured in POEditor project that will be exported
file_type – There are more available formats to download but only one is supported now: json
- Returns
poeditor terms
- toolium.utils.poeditor.get_all_terms(project_info, lang)[source]¶
Get all terms for a given language configured in POEditor
- Parameters
project_info – project_info
lang – a valid language configured in POEditor project
- Returns
the list of terms
- toolium.utils.poeditor.get_country_from_config_file()[source]¶
Gets the country to use later from config checking if it’s a valid one in POEditor
- Returns
country
- toolium.utils.poeditor.get_poeditor_api_token()[source]¶
Get POEditor API token from environment property or configuration property
- Returns
POEditor API token
- toolium.utils.poeditor.get_poeditor_file_path()[source]¶
Get configured POEditor file path or default file path
- Returns
POEditor file path
- toolium.utils.poeditor.get_poeditor_language_codes(project_info)[source]¶
Get language codes available for a given project ID
- Parameters
project_info – project info
- Returns
project language codes
- toolium.utils.poeditor.get_poeditor_project_info_by_name(project_name=None)[source]¶
Get POEditor project info from project name from config or parameter
- Parameters
project_name – POEditor project name
- Returns
project info
- toolium.utils.poeditor.get_poeditor_projects()[source]¶
Get the list of the projects configured in POEditor
- Returns
POEditor projects list
- toolium.utils.poeditor.get_valid_lang(language_codes, lang=None)[source]¶
Check if language provided is a valid one configured and returns the POEditor matched lang
- Parameters
language_codes – valid POEditor language codes
lang – a language from config or from lang parameter
- Returns
lang matched from POEditor
- toolium.utils.poeditor.load_poeditor_texts(context=None)[source]¶
Download POEditor texts and save in output folder if the config exists or use previously downloaded texts
- Parameters
context – behave context (deprecated parameter)
- toolium.utils.poeditor.save_downloaded_file(poeditor_terms)[source]¶
Saves POEditor terms to a file in output dir
- Parameters
poeditor_terms – POEditor terms
- toolium.utils.poeditor.search_terms_with_string(context=None, lang=None)[source]¶
Saves POEditor terms for a given existing language in that project
- Parameters
context – behave context (deprecated)
lang – a valid language existing in that POEditor project
- Returns
N/A (saves it to context.poeditor_terms)
- toolium.utils.poeditor.send_poeditor_request(endpoint, method, params, status_code)[source]¶
Send a request to the POEditor API
- Parameters
endpoint – endpoint path
method – HTTP method to be used in the request
params – parameters to be sent in the request
code – expected status code
- Returns
response