Best Python code snippet using pyatom_python
validators.ts
Source:validators.ts
...6export const validateLoginInput = (7 data: DoctorTypes | PatientTypes | AdminTypes8) => {9 let errors = <DoctorTypes | PatientTypes | AdminTypes>{};10 data.email = !isEmpty(data.email) ? data.email : '';11 data.password = !isEmpty(data.password) ? data.password : '';12 if (Validator.isEmpty(data.email)) {13 errors.email = 'Email field is required';14 } else if (!Validator.isEmail(data.email)) {15 errors.email = 'Email is invalid';16 }17 if (Validator.isEmpty(data.password)) {18 errors.password = 'Password field is required';19 }20 return {21 errors,22 isValid: isEmpty(errors),23 };24};25export const ValidateDoctorRegisterInput = (data: DoctorTypes) => {26 const errors = <DoctorTypes>{};27 data.fullname = !isEmpty(data.fullname) ? data.fullname : '';28 data.email = !isEmpty(data.email) ? data.email : '';29 data.password = !isEmpty(data.password) ? data.password : '';30 data.confirmPassword = !isEmpty(data.confirmPassword)31 ? data.confirmPassword32 : '';33 data.reg_num = !isEmpty(data.reg_num) ? data.reg_num : '';34 data.specialization = !isEmpty(data.specialization)35 ? data.specialization36 : '';37 data.hospital_name = !isEmpty(data.hospital_name) ? data.hospital_name : '';38 data.phone = !isEmpty(data.phone) ? data.phone : '';39 data.age = !isEmpty(data.age) ? data.age : '';40 data.gender = !isEmpty(data.gender) ? data.gender : '';41 data.address = !isEmpty(data.address) ? data.address : '';42 if (Validator.isEmpty(data.fullname)) {43 errors.fullname = 'Name field is required';44 }45 if (Validator.isEmpty(data.address)) {46 errors.address = 'Address field is required';47 }48 if (Validator.isEmpty(data.specialization)) {49 errors.specialization = 'Specialization field is required';50 }51 if (Validator.isEmpty(data.reg_num)) {52 errors.reg_num = 'Registration Number field is required';53 }54 if (Validator.isEmpty(data.hospital_name)) {55 errors.hospital_name = 'Hospital Name field is required';56 }57 if (Validator.isEmpty(data.phone)) {58 errors.phone = 'Contact Number field is required';59 } else if (!Validator.isMobilePhone(data.phone, ['en-IN'])) {60 errors.phone = 'Contact Number is invalid';61 }62 if (Validator.isEmpty(data.email)) {63 errors.email = 'Email field is required';64 } else if (!Validator.isEmail(data.email)) {65 errors.email = 'Email is invalid';66 }67 if (Validator.isEmpty(data.password)) {68 errors.password = 'Password field is required';69 }70 if (Validator.isEmpty(data.confirmPassword)) {71 errors.confirmPassword = 'Confirm password field is required';72 }73 if (!Validator.isLength(data.password, { min: 6, max: 20 })) {74 errors.password = 'Password must be at least 6 characters';75 }76 if (!Validator.equals(data.password, data.confirmPassword)) {77 errors.confirmPassword = 'Passwords must match';78 }79 return {80 errors,81 isValid: isEmpty(errors),82 };83};84export const ValidatePatientRegisterInput = (data: PatientTypes) => {85 const errors = <PatientTypes>{};86 data.fullname = !isEmpty(data.fullname) ? data.fullname : '';87 data.email = !isEmpty(data.email) ? data.email : '';88 data.password = !isEmpty(data.password) ? data.password : '';89 data.phone = !isEmpty(data.phone) ? data.phone : '';90 data.age = !isEmpty(data.age) ? data.age : '';91 data.gender = !isEmpty(data.gender) ? data.gender : '';92 if (Validator.isEmpty(data.fullname)) {93 errors.fullname = 'Name field is required';94 }95 if (Validator.isEmpty(data.phone)) {96 errors.phone = 'Contact Number field is required';97 } else if (!Validator.isMobilePhone(data.phone, ['en-IN'])) {98 errors.phone = 'Please enter valid phone number';99 }100 if (Validator.isEmpty(data.email)) {101 errors.email = 'Email field is required';102 } else if (!Validator.isEmail(data.email)) {103 errors.email = 'Email is invalid';104 }105 if (Validator.isEmpty(data.password)) {106 errors.password = 'Password field is required';107 }108 if (!Validator.isLength(data.password, { min: 6, max: 20 })) {109 errors.password = 'Password must be at least 6 characters';110 }111 if (Validator.isEmpty(data.age)) {112 errors.age = 'Age field is required';113 }114 if (Validator.isEmpty(data.gender)) {115 errors.gender = 'Gender field is required';116 }117 return {118 errors,119 isValid: isEmpty(errors),120 };121};122export const ValidateAdminRegisterInput = (data: AdminTypes) => {123 const errors = <AdminTypes>{};124 data.fullname = !isEmpty(data.fullname) ? data.fullname : '';125 data.email = !isEmpty(data.email) ? data.email : '';126 data.password = !isEmpty(data.password) ? data.password : '';127 data.confirmPassword = !isEmpty(data.confirmPassword)128 ? data.confirmPassword129 : '';130 if (Validator.isEmpty(data.fullname)) {131 errors.fullname = 'Name field is required';132 }133 if (Validator.isEmpty(data.email)) {134 errors.email = 'Email field is required';135 } else if (!Validator.isEmail(data.email)) {136 errors.email = 'Email is invalid';137 }138 if (Validator.isEmpty(data.password)) {139 errors.password = 'Password field is required';140 }141 if (Validator.isEmpty(data.confirmPassword)) {142 errors.confirmPassword = 'Confirm password field is required';143 }144 if (!Validator.isLength(data.password, { min: 6, max: 20 })) {145 errors.password = 'Password must be at least 6 characters';146 }147 if (!Validator.equals(data.password, data.confirmPassword)) {148 errors.confirmPassword = 'Passwords must match';149 }150 return {151 errors,152 isValid: isEmpty(errors),153 };...
validate.py
Source:validate.py
1# -*- coding: utf-8 -*-2import re3class validate:4 def __init__(self):5 pass6 def phone(self, value, isEmpty=False):7 "validate phone"8 reg = '^1[3458]\d{9}$'9 p = re.compile(reg)10 return (value == '' and isEmpty) or p.match(value)11 def mobile(self, value, isEmpty=False):12 "validate mobile"13 reg = '^(\d{3}-|\d{4}-)?(\d{8}|\d{7})$'14 p = re.compile(reg)15 return (value == '' and isEmpty) or p.match(value)16 def contact1(self, value, isEmpty=False):17 "validate contact"18 reg = '^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$'19 p = re.compile(reg)20 return (value == '' and isEmpty) or p.match(value)21 def contact(self, value, isEmpty=False):22 "validate contact"23 return self.phone(value, isEmpty) or self.mobile(value, isEmpty)24 def qq(self, value, isEmpty=False):25 "validate qq"26 reg = '^[1-9]\d{4,12}$'27 p = re.compile(reg)28 return (value == '' and isEmpty) or p.match(str(value))29 def url(self, value, isEmpty=False):30 "validate url"31 reg = '^(http|https):\/\/[A-Za-z0-9%\-_@]+\.[A-Za-z0-9%\-_@]{2,}[A-Za-z0-9\.\/=\?%\-&_~`@[\]:+!;]*$'32 p = re.compile(reg)33 return (value == '' and isEmpty) or p.match(value)34 def ip(self, value, isEmpty=False):35 "validate ip"36 reg = '^(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])$'37 p = re.compile(reg)38 return (value == '' and isEmpty) or p.match(value)39 def int(self, value, isEmpty=False):40 "validate int"41 reg = '^\-?\d+$'42 p = re.compile(reg)43 return (value == '' and isEmpty) or p.match(value)44 def mac(self, value, isEmpty=False):45 "validate mac"46 reg_1 = '[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}'47 reg_2 = '[A-F\d]{2}-[A-F\d]{2}-[A-F\d]{2}-[A-F\d]{2}-[A-F\d]{2}-[A-F\d]{2}'48 p_1 = re.compile(reg_1)49 p_2 = re.compile(reg_2)50 return (value == '' and isEmpty) or p_1.match(value) or p_2.match(value)51 def plus(self, value, isEmpty=False):52 "validate plus"53 reg = '^[1-9]\d*$'54 p = re.compile(reg)55 return (value == '' and isEmpty) or p.match(value)56 def number(self, value, isEmpty=False):57 "validate number"58 reg = '^[0-9]+$'59 p = re.compile(reg)60 return (value == '' and isEmpty) or p.match(value)61 def notsc(self, value, isEmpty=False):62 "validate notsc"63 reg = ur'^[-a-zA-Z0-9_\u4e00-\u9fa5\s]+$'64 p = re.compile(reg)65 return (value == '' and isEmpty) or p.match(value)66 def letter(self, value, isEmpty=False):67 "validate letter"68 reg = '^[a-zA-Z]+$'69 p = re.compile(reg)70 return (value == '' and isEmpty) or p.match(value)71 def letterOrNum(self, value, isEmpty=False):72 "validate letter or number"73 reg = '^[0-9a-zA-Z]+$'74 p = re.compile(reg)75 return (value == '' and isEmpty) or p.match(value)76 def legalityName(self, value, isEmpty=False):77 "validate legalityName"78 reg = '^[-a-zA-Z0-9_]+$'79 p = re.compile(reg)80 return (value == '' and isEmpty) or p.match(value)81 def email(self, value, isEmpty=False):82 "validate email"83 #reg=r"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$"84 reg = r"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"85 p = re.compile(reg)86 return (value == '' and isEmpty) or p.match(value)87 def email1(self, value, isEmpty=False):88 reg = ur'^[_a-zA-Z\d@.-]+$';89 p = re.compile(reg)90 return (value == '' and isEmpty) or p.match(value)91 def period(self, value, isEmpty=False):92 va = value.split(':')93 if len(va) != 2: return False94 try:95 return not (int(va[0]) > 23 or int(va[1]) > 59 or int(va[1]) < 0)96 except:97 return False98 return True99 def onlyLetterUrl(self, value, isEmpty=False):100 "validate onlyLetterUrl"101 reg = r"^[a-zA-Z0-9.:/?#=]+$"102 p = re.compile(reg)...
AutoSavePluginTest.ts
Source:AutoSavePluginTest.ts
...8 const suite = LegacyUnit.createSuite();9 Plugin();10 Theme();11 suite.test('TestCase-TBA: AutoSave: isEmpty true', function (editor) {12 LegacyUnit.equal(editor.plugins.autosave.isEmpty(''), true);13 LegacyUnit.equal(editor.plugins.autosave.isEmpty(' '), true);14 LegacyUnit.equal(editor.plugins.autosave.isEmpty('\t\t\t'), true);15 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p id="x"></p>'), true);16 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p></p>'), true);17 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p> </p>'), true);18 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p>\t</p>'), true);19 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br></p>'), true);20 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br /></p>'), true);21 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" /></p>'), true);22 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br><br></p>'), true);23 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br /><br /></p>'), true);24 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" /><br data-mce-bogus="true" /></p>'), true);25 });26 suite.test('TestCase-TBA: AutoSave: isEmpty false', function (editor) {27 LegacyUnit.equal(editor.plugins.autosave.isEmpty('X'), false);28 LegacyUnit.equal(editor.plugins.autosave.isEmpty(' X'), false);29 LegacyUnit.equal(editor.plugins.autosave.isEmpty('\t\t\tX'), false);30 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p>X</p>'), false);31 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p> X</p>'), false);32 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p>\tX</p>'), false);33 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br>X</p>'), false);34 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br />X</p>'), false);35 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" />X</p>'), false);36 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br><br>X</p>'), false);37 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br /><br />X</p>'), false);38 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<p><br data-mce-bogus="true" /><br data-mce-bogus="true" />X</p>'), false);39 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<h1></h1>'), false);40 LegacyUnit.equal(editor.plugins.autosave.isEmpty('<img src="x" />'), false);41 });42 suite.test('TestCase-TBA: AutoSave: hasDraft/storeDraft/restoreDraft', function (editor) {43 LegacyUnit.equal(editor.plugins.autosave.hasDraft(), false);44 editor.setContent('X');45 editor.undoManager.add();46 editor.plugins.autosave.storeDraft();47 LegacyUnit.equal(editor.plugins.autosave.hasDraft(), true);48 editor.setContent('Y');49 editor.undoManager.add();50 editor.plugins.autosave.restoreDraft();51 LegacyUnit.equal(editor.getContent(), '<p>X</p>');52 editor.plugins.autosave.removeDraft();53 });54 suite.test('TestCase-TBA: AutoSave: recognises location hash change', function (editor) {...
range-test.js
Source:range-test.js
...48 "returns a descending range if step is negative": function(range) {49 assert.deepEqual(range(5, 0, -1), [5, 4, 3, 2, 1]);50 },51 "returns an empty range if start, stop or step are NaN": function(range) {52 assert.isEmpty(range(0, NaN));53 assert.isEmpty(range(1, NaN));54 assert.isEmpty(range(-1, NaN));55 assert.isEmpty(range(0, undefined));56 assert.isEmpty(range(1, undefined));57 assert.isEmpty(range(-1, undefined));58 assert.isEmpty(range(NaN, 0));59 assert.isEmpty(range(NaN, 1));60 assert.isEmpty(range(NaN, -1));61 assert.isEmpty(range(undefined, 0));62 assert.isEmpty(range(undefined, 1));63 assert.isEmpty(range(undefined, -1));64 assert.isEmpty(range(NaN, NaN));65 assert.isEmpty(range(undefined, undefined));66 assert.isEmpty(range(NaN, NaN, NaN));67 assert.isEmpty(range(undefined, undefined, undefined));68 assert.isEmpty(range(0, 10, NaN));69 assert.isEmpty(range(10, 0, NaN));70 assert.isEmpty(range(0, 10, undefined));71 assert.isEmpty(range(10, 0, undefined));72 },73 "returns an empty range if start equals stop": function(range) {74 assert.isEmpty(range(10, 10));75 assert.isEmpty(range(10, 10, 1));76 assert.isEmpty(range(10, 10, -1));77 assert.isEmpty(range(10, 10, -.5));78 assert.isEmpty(range(10, 10, .5));79 assert.isEmpty(range(0, 0));80 assert.isEmpty(range(0, 0, 1));81 assert.isEmpty(range(0, 0, -1));82 assert.isEmpty(range(0, 0, -.5));83 assert.isEmpty(range(0, 0, .5));84 },85 "returns an empty range if stop is less than start and step is positive": function(range) {86 assert.isEmpty(range(20, 10));87 assert.isEmpty(range(20, 10, 2));88 assert.isEmpty(range(20, 10, 1));89 assert.isEmpty(range(20, 10, .5));90 },91 "returns an empty range if stop is greater than start and step is negative": function(range) {92 assert.isEmpty(range(10, 20, -2));93 assert.isEmpty(range(10, 20, -1));94 assert.isEmpty(range(10, 20, -.5));95 }96 }97});...
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!!