Best Python code snippet using Testify_python
test_validators.py
Source:test_validators.py
...7 def test_cpf_registration(self):8 from Products.validation import validation9 v = validation.validatorFor('isCPF')10 self.failUnlessEqual(v('81057807559'), 1)11 self.failIfEqual(v('8105780755x'), 1)12 def test_cnpj_registration(self):13 from Products.validation import validation14 v = validation.validatorFor('isCNPJ')15 self.failUnlessEqual(v('90.656.353/0001-37'), 1)16 self.failIfEqual(v('90.656.353/0001-36'), 1)17 def test_cep_registration(self):18 from Products.validation import validation19 v = validation.validatorFor('isCEP')20 self.failUnlessEqual(v('05417-010'), 1)21 self.failIfEqual(v('05417'), 1)22 def test_phone_registration(self):23 from Products.validation import validation24 v = validation.validatorFor('isBrPhone')25 self.failUnlessEqual(v('(11)38982121'), 1)26 self.failIfEqual(v('113898-212121'), 1)27 self.failUnlessEqual(v('11987772121'), 1)28 self.failIfEqual(v('11887772121'), 1)29 self.failIfEqual(v('21987772121'), 1)30class TestCPFValidator(unittest.TestCase):31 layer = INTEGRATION_TESTING32 def setUp(self):33 from Products.validation import validation34 portal = self.layer['portal']35 self.portal = portal36 self.v = validation.validatorFor('isCPF')37 def test_cpf_unformatted(self):38 self.failUnlessEqual(self.v('81057807559'), 1)39 self.failIfEqual(self.v('81057807554'), 1)40 self.failIfEqual(self.v('810578075xx'), 1)41 def test_cpf_formatted(self):42 self.failUnlessEqual(self.v('810.578.075-59'), 1)43 self.failUnlessEqual(self.v('810.578.075/59'), 1)44 self.failIfEqual(self.v('810.578.075-54'), 1)45 self.failIfEqual(self.v('810.578.075/xx'), 1)46 def test_cpf_wrong_size(self):47 self.failIfEqual(self.v('8105780755'), 1)48 self.failIfEqual(self.v('810.5782075/59'), 1)49 self.failIfEqual(self.v('810.578.075-542'), 1)50 self.failIfEqual(self.v('8103578.075399'), 1)51class TestCNPJValidator(unittest.TestCase):52 layer = INTEGRATION_TESTING53 def setUp(self):54 from Products.validation import validation55 portal = self.layer['portal']56 self.portal = portal57 self.v = validation.validatorFor('isCNPJ')58 def test_cnpj_unformatted(self):59 self.failUnlessEqual(self.v('90656353000137'), 1)60 self.failUnlessEqual(self.v('00000000000191'), 1)61 self.failIfEqual(self.v('90656353000134'), 1)62 self.failIfEqual(self.v('10000000000191'), 1)63 def test_cnpj_formatted(self):64 self.failUnlessEqual(self.v('90.656.353/0001-37'), 1)65 self.failUnlessEqual(self.v('00.000.000/0001-91'), 1)66 self.failIfEqual(self.v('90.656.353/0001-34'), 1)67 self.failIfEqual(self.v('10.000.000/0001-91'), 1)68 def test_cnpj_wrong_size(self):69 self.failIfEqual(self.v('9065635300017'), 1)70 self.failIfEqual(self.v('90.656.35300001-37'), 1)71 self.failIfEqual(self.v('000000000000191'), 1)72 self.failIfEqual(self.v('00.000.0000001-911'), 1)73 self.failIfEqual(self.v('90.656.3530/000134'), 1)74 self.failIfEqual(self.v('10.000.000/0001-921'), 1)75class TestCEPValidator(unittest.TestCase):76 layer = INTEGRATION_TESTING77 def setUp(self):78 from Products.validation import validation79 portal = self.layer['portal']80 self.portal = portal81 self.v = validation.validatorFor('isCEP')82 def test_cep_unformatted(self):83 self.failUnlessEqual(self.v('05421001'), 1)84 self.failUnlessEqual(self.v('03087000'), 1)85 self.failIfEqual(self.v('0308700x'), 1)86 self.failIfEqual(self.v('0542100x'), 1)87 def test_cep_formatted(self):88 self.failUnlessEqual(self.v('05421-001'), 1)89 self.failUnlessEqual(self.v('03087-000'), 1)90 self.failIfEqual(self.v('03087-00x'), 1)91 self.failIfEqual(self.v('05421-00x'), 1)92class TestPhoneValidator(unittest.TestCase):93 layer = INTEGRATION_TESTING94 def setUp(self):95 from Products.validation import validation96 portal = self.layer['portal']97 self.portal = portal98 self.v = validation.validatorFor('isBrPhone')99 def test_phone_unformatted(self):100 self.failUnlessEqual(self.v('1138982121'), 1)101 self.failUnlessEqual(self.v('1120953000'), 1)102 self.failUnlessEqual(self.v('08007764832'), 1)103 self.failUnlessEqual(self.v('03007897771'), 1)104 self.failIfEqual(self.v('38982121'), 1)105 self.failIfEqual(self.v('2920953000'), 1)106 self.failIfEqual(self.v('18007764832'), 1)107 self.failIfEqual(self.v('33007897771'), 1)108 def test_phone_formatted(self):109 self.failUnlessEqual(self.v('(11)3898.2121'), 1)110 self.failUnlessEqual(self.v('(11)2095.3000'), 1)111 self.failUnlessEqual(self.v('0800-776-4832'), 1)112 self.failUnlessEqual(self.v('0300-789-7771'), 1)113 self.failIfEqual(self.v('3898-2121'), 1)114 self.failIfEqual(self.v('(29)2095.3000'), 1)115 self.failIfEqual(self.v('1800-776-4832'), 1)116 self.failIfEqual(self.v('3300-789-7771'), 1)117 def test_phone_with_international_codes(self):118 self.failIfEqual(self.v('+55(11)3898.2121'), 1)119 self.failIfEqual(self.v('+55(11)2095.3000'), 1)120 self.failIfEqual(self.v('+550800-776-4832'), 1)121 self.failIfEqual(self.v('+550300-789-7771'), 1)122 self.failIfEqual(self.v('+553898-2121'), 1)123 self.failIfEqual(self.v('+55(29)2095.3000'), 1)124 self.failIfEqual(self.v('+551800-776-4832'), 1)125 self.failIfEqual(self.v('+553300-789-7771'), 1)126 def test_phone_with_letters(self):127 self.failIfEqual(self.v('(11)3333PORTO'), 1)128 self.failIfEqual(self.v('113333PORTO'), 1)129 self.failIfEqual(self.v('11-3333-PORTO'), 1)130def test_suite():...
test_validation.py
Source:test_validation.py
...36 self.failUnlessEqual(v('https://be.brussels:8080/manage'), 1)37 self.failUnlessEqual(v('irc://tiran@irc.freenode.net:6667/#plone'), 1)38 self.failUnlessEqual(v('fish://tiran:password@myserver/~/'), 1)39 self.failUnlessEqual(v('http://\n'), u"Validation failed(isURL): 'http://\n' is not a valid url.")40 self.failIfEqual(v('../foo/bar'), 1)41 def test_isEmail(self):42 v = validation.validatorFor('isEmail')43 self.failUnlessEqual(v('test@test.com'), 1)44 self.failUnlessEqual(v('test@be.brussels'), 1)45 self.failIfEqual(v('@foo.bar'), 1)46 self.failUnlessEqual(v('me'), u"Validation failed(isEmail): 'me' is not a valid email address.")47 def test_isMailto(self):48 v = validation.validatorFor('isMailto')49 self.failUnlessEqual(v('mailto:test@test.com'), 1)50 self.failUnlessEqual(v('mailto:test@be.brussels'), 1)51 self.failIfEqual(v('test@test.com'), 1)52 self.failIfEqual(v('mailto:@foo.bar'), 1)53 self.failIfEqual(v('@foo.bar'), 1)54 self.failIfEqual(v('mailto:'), 1)55 self.failUnlessEqual(v('me'), u"Validation failed(isMailto): 'me' is not a valid email address.")56 def test_isUnixLikeName(self):57 v = validation.validatorFor('isUnixLikeName')58 self.failUnlessEqual(v('abcd'), 1)59 self.failUnless(v('a_123456'), 1)60 self.failIfEqual(v('123'), 1)61 self.failIfEqual(v('ab.c'), 1)62 self.failUnlessEqual(v('ab,c'), u"Validation failed(isUnixLikeName): 'ab,c' this name is not a valid identifier")63 self.failIfEqual(v('aaaaaaaab'), 1) # too long64 def test_isValidId(self):65 v = validation.validatorFor("isValidId")66 self.failUnlessEqual(v("a b", object()), u"Spaces are not allowed in ids")67 # TODO: more tests require a site68def test_suite():69 from unittest import TestSuite, makeSuite70 suite = TestSuite()71 suite.addTest(makeSuite(TestValidation))72 doctests = (73 'Products.validation.validators.ExpressionValidator',74 )75 for module in doctests:76 suite.addTest(doctest.DocTestSuite(module))77 return suite
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!!