Best Python code snippet using locust
operator_date_interval_parser.py
Source: operator_date_interval_parser.py
...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)...
check_rate_limit.py
Source: check_rate_limit.py
...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)...
Check out the latest blogs from LambdaTest on this topic:
Joseph, who has been working as a Quality Engineer, was assigned to perform web automation for the company’s website.
Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Websites and web apps are growing in number day by day, and so are the expectations of people for a pleasant web experience. Even though the World Wide Web (WWW) was invented only in 1989 (32 years back), this technology has revolutionized the world we know back then. The best part is that it has made life easier for us. You no longer have to stand in long queues to pay your bills. You can get that done within a few minutes by visiting their website, web app, or mobile app.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!