How to use _find_param_date_expressions method in toolium

Best Python code snippet using toolium_python

dataset.py

Source:dataset.py Github

copy

Full Screen

...118 new_param = param_types[key]119 param_replaced = True120 break121 return new_param, param_replaced122def _find_param_date_expressions(param):123 """124 Finds in a param one or several date expressions. 125 For example, for a param like "it happened on [NOW - 1 MONTH] of the last year and will happen [TODAY('%d/%m')]",126 this method returns an array with two string elements: "[NOW - 1 MONTH]" and [TODAY('%d/%m')]"127 The kind of expressions to search are based on these rules:128 - expression is sorrounded by [ and ]129 - first word of the expression is either NOW or TODAY130 - when first word is NOW, it can have an addtional format for the date between parenthesis, 131 like NOW(%Y-%m-%dT%H:%M:%SZ). The definition of the format is the same as considered by the132 python strftime function of the datetime module133 - and optional offset can be given by indicating how many days, hours, etc.. to add or remove to the current datetime.134 This part of the expression includes a +/- symbol plus a number and a unit135 Some valid expressions are:136 [NOW]137 [TODAY]138 [NOW(%Y-%m-%dT%H:%M:%SZ)]139 [NOW(%Y-%m-%dT%H:%M:%SZ) - 180 DAYS]140 [NOW(%H:%M:%S) + 4 MINUTES]141 :param param: parameter value142 :param language: language to configure date format for NOW and TODAY143 :return: An array with all the matching date expressions found in the param144 """145 return re.findall(r"\[(?:NOW(?:\((?:[^\(\)]*)\))?|TODAY)(?:\s*[\+|-]\s*\d+\s*\w+\s*)?\]", param)146def _replace_param_replacement(param, language):147 """148 Replace param with a new param value.149 Available replacements: [EMPTY], [B], [RANDOM], [TIMESTAMP], [DATETIME], [NOW], [TODAY]150 :param param: parameter value151 :param language: language to configure date format for NOW and TODAY152 :return: tuple with replaced value and boolean to know if replacement has been done153 """154 date_format = '%d/%m/%Y %H:%M:%S' if language == 'es' else '%Y/%m/%d %H:%M:%S'155 date_day_format = '%d/%m/%Y' if language == 'es' else '%Y/%m/%d'156 alphanums = ''.join([string.ascii_lowercase, string.digits]) # abcdefghijklmnopqrstuvwxyz0123456789157 replacements = {158 '[EMPTY]': '',159 '[B]': ' ',160 # make sure random is not made up of digits only, by forcing the first char to be a letter161 '[RANDOM]': ''.join([r.choice(string.ascii_lowercase), *(r.choice(alphanums) for i in range(7))]),162 '[RANDOM_PHONE_NUMBER]': ''.join(['+', '3', '4', '6', '5', '4'] + [str(r.randint(0, 9)) for i in range(1, 7)]),163 '[TIMESTAMP]': str(int(datetime.datetime.timestamp(datetime.datetime.utcnow()))),164 '[DATETIME]': str(datetime.datetime.utcnow()),165 '[NOW]': str(datetime.datetime.utcnow().strftime(date_format)),166 '[TODAY]': str(datetime.datetime.utcnow().strftime(date_day_format))167 }168 169 # append date expressions found in param to the replacement dict 170 date_expressions = _find_param_date_expressions(param)171 for date_expr in date_expressions:172 replacements[date_expr] = _replace_param_date(date_expr, language)[0]173 new_param = param174 param_replaced = False175 for key in replacements.keys():176 if key in new_param:177 new_param = new_param.replace(key, replacements[key])178 param_replaced = True179 return new_param, param_replaced180def _replace_param_transform_string(param):181 """182 Transform param value according to the specified prefix.183 Available transformations: DICT, LIST, INT, FLOAT, STR, UPPER, LOWER184 :param param: parameter value...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful