How to use reset_time method in locust

Best Python code snippet using locust

operator_date_interval_parser.py

Source:operator_date_interval_parser.py Github

copy

Full Screen

...22 match = PERIOD_LAST_X_DAYS_REGEX.match(value)23 if match:24 return True25 return False26def reset_time(date):27 return date.replace(hour=0, minute=0, second=0, microsecond=0)28def get_interval_date_filter(value):29 if not is_interval_date_value(value):30 return31 now = datetime.utcnow()32 match = PERIOD_LAST_X_DAYS_REGEX.match(value)33 if match:34 start = now - timedelta(days=match.group(1))35 return (start,)36 start = end = None37 if value == 'yesterday':38 start = now - timedelta(days=1)39 start = reset_time(start)40 end = now41 end = reset_time(end)42 elif value == 'lastWeek':43 start = now - timedelta(weeks=1)44 start = start - timedelta(days=start.weekday())45 start = reset_time(start)46 end = now - timedelta(days=6-now.weekday())47 end = reset_time(end)48 elif value == 'last2Weeks':49 start = now - timedelta(weeks=2)50 start = start - timedelta(days=start.weekday())51 start = reset_time(start)52 end = now - timedelta(days=6-now.weekday())53 end = reset_time(end)54 elif value == 'lastMonth':55 start = now - relativedelta(months=1)56 start = start.replace(start.year, start.month, 1)57 start = reset_time(start)58 end = now.replace(now.year, now.month, 1)59 end = reset_time(end)60 elif value == 'last3Month':61 start = now - relativedelta(months=3)62 start = start.replace(start.year, start.month, 1)63 start = reset_time(start)64 end = now.replace(now.year, now.month, 1)65 end = reset_time(end)66 elif value == 'lastYear':67 start = now - relativedelta(years=1)68 start = start.replace(start.year, 1, 1)69 start = reset_time(start)70 end = now.replace(now.year, 1, 1)71 end = reset_time(end)...

Full Screen

Full Screen

check_rate_limit.py

Source:check_rate_limit.py Github

copy

Full Screen

...20 remain = int(remain)21 except ValueError:22 return 023 return remain24def get_reset_time(headers):25 """26 Get the reset header.27 """28 reset_time = headers.get("X-Rate-Limit-Reset", None)29 if reset_time is None:30 reset_time = headers.get("X-RateLimit-Reset", None)31 if reset_time is None:32 return None33 try:34 reset_time = int(reset_time)35 except ValueError:36 return None37 return reset_time38def get_server_time(headers):39 """40 Get the server time.41 """42 # Get the server time.43 try:44 server_time = headers["date"]45 server_time = datetime.strptime(server_time, SERVER_TIME_FMT)46 server_time = calendar.timegm(server_time.timetuple())47 except (KeyError, ValueError):48 return None49 return server_time50def check_rate_limit(headers):51 """52 Return the number of seconds to sleep off the rate limit.53 """54 # Check if we have hit the rate limit55 # In case the header was not found,56 # assume rate limit was hit57 remain = get_remaining(headers)58 # We still have more api calls left59 if remain > 0:60 return 061 reset_time = get_reset_time(headers)62 server_time = get_server_time(headers)63 # If we dont have either of the headers return default64 if reset_time is None or server_time is None:65 return const.API_RETRY_AFTER66 # Return recommended seconds to sleep67 sleep_time = reset_time - server_time68 sleep_time = max(sleep_time, 0)...

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 locust 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