How to use validate_text method in mailosaur-python

Best Python code snippet using mailosaur-python_python

models.py

Source:models.py Github

copy

Full Screen

...84 parent = Parent.objects.filter(email=email).values()85 if len(parent):86 return True87 return False88def validate_text(text, min_length=2):89 if text.isalpha == False:90 return 091 elif len(text) < min_length:92 return 193 elif len(text) > min_length:94 return 295def validate_email(email):96 regex = re.compile(r'^[a-zA-Z0-9.+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]+$')97 if re.search(regex, email):98 if not is_duplicate_email(email):99 return 2100 return 1101 return 0102def teacher_validator(postData):103 errors = {}104 if validate_text(postData['fname']) == 0:105 errors["first_name"] = "You must enter a name"106 if validate_text(postData['fname']) == 1:107 errors["fname_length"] = "first name is too short"108 if validate_text(postData['lname']) == 0:109 errors["last_name"] = "You must enter a last name"110 # if validate_text(postData["lname"]) == 1:111 # errors["lname_length"] = "last name is too short"112 if validate_text(postData['occupation']) == 0:113 errors["occupation"] = "You must enter your occupation information"114 if validate_text(postData['occupation']) == 1:115 errors["occupation_length"] = "the data you entered is too short"116 if validate_text(postData['specialization']) == 0:117 errors["specialization"] = "You must enter your specialization info"118 if validate_text(postData['specialization']) == 1:119 errors["specialization_length"] = "the data you entered is too short"120 return errors121def parent_validator(postData):122 errors = {}123 if validate_text(postData['fname']) == 1:124 errors["fname"] = "This name is too short!"125 if validate_text(postData['fname']) == 0:126 errors["fname_letters"] = "A name must be Abc characters only! Sorry Elon Musk!"127 if validate_text(postData['lname']) == 1:128 errors["lname"] = "This name is too short!"129 if validate_text(postData['lname']) == 0:130 errors["lname_letters"] = "A name must be Abc characters only!"131 if validate_email(postData['email']) == 0:132 errors["email"] = "Invalid email"133 if validate_email(postData['email']) == 1:134 errors["email_exists"] = "This email already exists"135 if validate_text(postData['password'], min_length=8) == 1:136 errors["password"] = "Password is too short!"137 if validate_text(postData['occupation'], min_length=5) == 1:138 errors["occupation"] = "Occupation must be at least 5 charcters"139 return errors140def child_validator(postData):141 errors = {}142 if validate_text(postData['fname']) == 1:143 errors["fname"] = "This name is too short!"144 if validate_text(postData['fname']) == 0:145 errors["fname_letters"] = "A name must be Abc characters only! Sorry Elon Musk!"146 return errors147def is_available(day, time, id):148 lessons = Lesson.objects.filter(149 day=day, time=time, teacher=Teacher.objects.get(id=id))150 print(lessons)151 if len(lessons) > 0:152 return False153 return True154def is_lesson_available(day, time, id):155 lessons = Lesson.objects.filter(156 day=day, time=time, teacher=Teacher.objects.get(id=id))157 print(lessons)158 print(lessons[0].child)159 if lessons[0].child is None:160 return True161 return False162def child_is_available(child, day, time):163 lessons = Lesson.objects.filter(day=day, time=time, child=child)164 print(lessons)165 if len(lessons) > 0:166 return False167 return True168def lesson_validator(postData, id):169 errors = {}170 if len(postData['title']) < 2:171 errors['title'] = "Title should have at least many characters"172 if validate_text(postData['description'], min_length=5) == 1:173 errors['description'] = "Description should have at least 5 characters"174 if is_available(postData['day'], postData['time'], id) == False:175 errors['time'] = "You already have a lesson at this time!"...

Full Screen

Full Screen

test_string.py

Source:test_string.py Github

copy

Full Screen

1import unittest2from validation import validate_text, validate_bytes3class ValidateTextTestCase(unittest.TestCase):4 def test_valid(self): # type: () -> None5 validate_text(u"hello world")6 def test_bytestring(self):7 with self.assertRaises(TypeError):8 validate_text(b"hello world")9 def test_min_length(self): # type: () -> None10 validate_text(u"123456", min_length=6)11 with self.assertRaises(ValueError):12 validate_text(u"123456", min_length=7)13 def test_max_length(self): # type: () -> None14 validate_text(u"123456", max_length=6)15 with self.assertRaises(ValueError):16 validate_text(u"123456", max_length=5)17 def test_pattern(self): # type: () -> None18 validate_text(u"a----b", pattern=r"a-*b")19 with self.assertRaises(ValueError):20 validate_text(u"begin end", pattern=r"end")21 with self.assertRaises(ValueError):22 validate_text(u"begin end", pattern=r"begin")23 def test_required(self): # type: () -> None24 validate_text(None, required=False)25 with self.assertRaises(TypeError):26 validate_text(None)27 def test_closure(self): # type: () -> None28 validator = validate_text(min_length=4)29 validator(u"12345")30 with self.assertRaises(ValueError):31 validator(u"123")32 def test_repr(self): # type: () -> None33 validator = validate_text(pattern='hello world', required=False)34 self.assertEqual(35 repr(validator),36 'validate_text(pattern=\'hello world\', required=False)',37 )38 validator = validate_text(min_length=4, max_length=10)39 self.assertEqual(40 repr(validator),41 'validate_text(min_length=4, max_length=10)',42 )43class ValidateBytesTestCase(unittest.TestCase):44 def test_valid(self): # type: () -> None45 validate_bytes(b"deadbeaf")46 def test_unicode(self):47 with self.assertRaises(TypeError):48 validate_bytes(u"hello world")49 def test_min_length(self): # type: () -> None50 validate_bytes(b"123456", min_length=6)51 with self.assertRaises(ValueError):52 validate_bytes(b"123456", min_length=7)53 def test_max_length(self): # type: () -> None54 validate_bytes(b"123456", max_length=6)55 with self.assertRaises(ValueError):...

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 mailosaur-python 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