Best Python code snippet using lettuce-tools_python
handlers.py
Source:handlers.py
...84 def options(self, *args, **kwargs):85 """86 Called for ajax calls for most browsers in X-Origin87 """88 self.serve_response(200, [])89 def serve_success(self, result, extra_fields={}):90 """Serve up a 200 response"""91 self.serve_response(200, result, extra_fields=extra_fields)92 def serve_404(self, msg='Endpoint Not Found'):93 """Serve up a 404 Response """94 self.serve_response(404, [], messages=msg)95 def serve_error(self, exception, status=500):96 """Serve up a Exception Response"""97 # TODO: Pass in exception stack98 # TODO: Figure out how to communicate retryable exceptions, etc99 exc_type, exc_value, exc_traceback = sys.exc_info()100 formatted_lines = traceback.format_exc().splitlines()101 self.serve_response(status, formatted_lines, messages=[unicode(exception)])102 logging.exception(exception)103 def serve_response(self, status, result, messages=None, extra_fields={}):104 """Serve the response"""105 allow_header_values = "Authorization, Origin, X-Requested-With, Content-Type, Accept"106 if (not isinstance(messages, list)):107 messages = [messages]108 self.response.set_status(status)109 # Determine origin bits110 request_origin = self.request.headers.get('Origin') or self.request.referer111 response_origin = API_DEFAULT_ORIGIN112 origin_in_whitelist = rest_utils.is_origin_in_whitelist(request_origin)113 if origin_in_whitelist:114 response_origin = request_origin # Input origin is good, so passthru115 # TODO: Validate that extra_fields doesn't contain bad props - collisions116 payload = extra_fields117 payload.update({'status': status, 'results': result, 'messages': messages})...
access.py
Source:access.py
...16 response = login_form(request)17 if todo == 'reg':18 response = register_form(request)19 if not response:20 response = serve_response('login.html')21 request.session.save_cookie(response, expires=cookie_expires(), max_age=cookie_lifespan())22 return response23def login_form(request):24 username = request.form.get('username')25 password = request.form.get('passwd')26 user = get_user(username)27 if user and user.is_valid_pw(password):28 request.login(username)29 return redirect(url_for('index'))30 flashMsg = 'Invalid credentials.'31 return serve_response('login.html', flashMsg=flashMsg)32def register_form(request):33 # getting and checking input34 username = request.form.get('username', None)35 pw1 = request.form.get('passwd', None)36 pw2 = request.form.get('passwd2', None)37 if not (username and pw1 and pw2):38 return serve_response('login.html', flashMsg='All fields are required.')39 if ' ' in username:40 return serve_response('login.html', flashMsg='Username cannot contain spaces.')41 if get_user(username):42 return serve_response('login.html', flashMsg='Username exists! Please choose another username.')43 if pw1 != pw2:44 return serve_response('login.html', flashMsg='Passwords don\'t match.')45 # create user46 user = User(username, pw1)47 session.commit()48 return login_form(request)49def logout(request):50 request.logout()51 response = redirect(url_for('index'))52 request.session.save_cookie(response, expires=0, max_age=0)...
simple.py
Source:simple.py
1from myapp.lib.memoize import memoize2from myapp.lib.utils import serve_response, serve_text3@memoize('view_simple_search')4def search(request):5 return serve_response('search.html')6@memoize('view_simple_about')7def about(request):8 return serve_response('about.html')9@memoize('view_simple_help')10def help(request):11 return serve_response('help.html')12@memoize('view_simple_links')13def links(request):14 return serve_response('links.html')15@memoize('view_simple_robots')16def robots(request):17 txt = 'User-agent: * \nDisallow: /login \nDisallow: /api/ \nAllow: /'18 return serve_text(txt)19def code(request):20 return serve_text('bla')21 22def not_found(request, error):...
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!!