How to use has_errors method in localstack

Best Python code snippet using localstack_python

validators.py

Source:validators.py Github

copy

Full Screen

1import re2import time34email_expr = re.compile(r'^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$', re.IGNORECASE)5def form_validation (mandatory_fields, date_fields, time_fields, REQUEST):6 has_errors = False7 #@TODO reverse cycling oder mandatory_fields --> REQUEST.form8 for k,v in REQUEST.form.items():9 if k in mandatory_fields:10 if k == 'email' and v:11 if not email_expr.match(v):12 REQUEST.set('%s_notvalid' % k, True)13 has_errors = True14 if not v:15 REQUEST.set('%s_error' % k, True)16 has_errors = True17 if k in date_fields and v:18 try:19 temp = time.strptime(v, "%d/%m/%Y")20 except:21 REQUEST.set('%s_notvalid' % k, True)22 has_errors = True23 if k in time_fields and v:24 try:25 temp = time.strptime(v, "%H:%M")26 except:27 REQUEST.set('%s_notvalid' % k, True)28 has_errors = True2930 event_1 = REQUEST.get('event_1', False)31 event_2 = REQUEST.get('event_2', False)32 event_3 = REQUEST.get('event_3', False)33 if event_3 and (event_1 or event_2):34 REQUEST.set('event_error', True)35 has_errors = True36 if event_2 and not event_1:37 REQUEST.set('event_error', True)38 has_errors = True39 if not (event_1 or event_2 or event_3):40 REQUEST.set('no_event_error', True)41 has_errors = True4243 topic_1 = int(REQUEST.get('topic_1', False))44 topic_2 = int(REQUEST.get('topic_2', False))45 topic_3 = int(REQUEST.get('topic_3', False))46 topic_4 = int(REQUEST.get('topic_4', False))47 if topic_1 + topic_2 + topic_3 + topic_4 != 10:48 REQUEST.set('topic_error', True)49 has_errors = True5051 if has_errors:52 REQUEST.set('request_error', True)53 return not has_errors545556def registration_validation(REQUEST):57 """ Validates the new meeting registration fields """58 has_errors = False5960 title = REQUEST.form.get('title', '')61 administrative_email = REQUEST.form.get('administrative_email', '')62 start_date = REQUEST.form.get('start_date', '')63 end_date = REQUEST.form.get('end_date', '')6465 if not title:66 REQUEST.set('title_error', True)67 has_errors = True68 if not administrative_email:69 REQUEST.set('administrative_email_error', True)70 has_errors = True71 if not start_date:72 REQUEST.set('start_date_error', True)73 has_errors = True74 if not end_date:75 REQUEST.set('end_date_error', True)76 has_errors = True77 if administrative_email:78 for email_address in administrative_email:79 if email_address and not email_expr.match(email_address):80 REQUEST.set('administrative_email_invalid', True)81 has_errors = True82 if start_date:83 date = str2date(start_date)84 if date is None:85 REQUEST.set('start_date_invalid', True)86 has_errors = True87 if end_date:88 date = str2date(end_date)89 if date is None:90 REQUEST.set('end_date_invalid', True)91 has_errors = True92 if start_date and end_date and not has_errors:93 if str2date(start_date) > str2date(end_date):94 REQUEST.set('date_interval_invalid', True)95 has_errors = True96 if has_errors:97 REQUEST.set('request_error', True)98 return not has_errors99100def str2date(s, format='%d/%m/%Y'):101 try:102 return time.strptime(s, format)103 except: ...

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