def test_isNotLinkSpam(self): v = validation.validatorFor('isNotLinkSpam') good = """I am link free and proud of it""" bad1 = """<a href="mylink">Bad.</a>""" bad2 = """http://bad.com""" bad3 = """www.Bad.com""" bad = (bad1,bad2,bad3) class Mock(object): validate_no_link_spam = 1 mock = Mock() kw = {'field':mock} self.failUnlessEqual(v(good, **kw), 1) for b in bad: self.failIfEqual(v(b, **kw), 1, '"%s" should be considered a link.' % b)
def test_isNotTooLong2(self): v = validation.validatorFor('isNotTooLong') v.maxlength = 10 self.failUnlessEqual(v('abc'), 1) self.failIfEqual(v('abcdefghijklmnopqrstuvwxyz'), 1) # there was a bug where widget.maxlength could possibly be defined as # '' which means calling int(widget.maxlength) would fail class Mock(object): pass field = Mock() field.widget = Mock() field.widget.maxlength = '' self.failUnlessEqual(v('abc', field=field), 1)
def test_isNotLinkSpam(self): v = validation.validatorFor('isNotLinkSpam') good = """I am link free and proud of it""" bad1 = """<a href="mylink">Bad.</a>""" bad2 = """http://bad.com""" bad3 = """www.Bad.com""" bad = (bad1, bad2, bad3) class Mock(object): validate_no_link_spam = 1 mock = Mock() kw = {'field': mock} self.failUnlessEqual(v(good, **kw), 1) for b in bad: self.failIfEqual(v(b, **kw), 1, '"%s" should be considered a link.' % b)
def test_isNotTooLong(self): v = validation.validatorFor('isNotTooLong') self.failUnlessEqual(v('', maxlength=20), 1) self.failUnlessEqual(v('1234567890', maxlength=20), 1) self.failUnlessEqual(v('1234567890', maxlength=10), 1) self.failUnlessEqual(v('1234567890', maxlength=0), 1) self.failIfEqual(v('1234567890', maxlength=9), 1) self.failIfEqual(v('1234567890', maxlength=1), 1) self.failUnlessEqual(v('cons\xc3\xa9quence', maxlength=11), 1)
def test_inExNumericRange(self): v = validation.validatorFor('inExNumericRange') self.failUnlessEqual(v(10, minval=1, maxval=20), 1) self.failUnlessEqual(v('10', minval=1, maxval=20), 1) self.failUnlessEqual(v('1', minval=1, maxval=20), 1) self.failUnlessEqual(v('20', minval=1, maxval=20), 1) self.failIfEqual(v(0, minval=1, maxval=5), 1) self.failIfEqual(v(6, minval=1, maxval=5), 1) self.failIfEqual(v(4, minval=5, maxval=3), 1)
def test_inExNumericRange(self): v = validation.validatorFor("inExNumericRange") self.failUnlessEqual(v(10, minval=1, maxval=20), 1) self.failUnlessEqual(v("10", minval=1, maxval=20), 1) self.failUnlessEqual(v("1", minval=1, maxval=20), 1) self.failUnlessEqual(v("20", minval=1, maxval=20), 1) self.failIfEqual(v(0, minval=1, maxval=5), 1) self.failIfEqual(v(6, minval=1, maxval=5), 1) self.failIfEqual(v(4, minval=5, maxval=3), 1)
def test_isNotTooLong(self): v = validation.validatorFor("isNotTooLong") self.failUnlessEqual(v("", maxlength=20), 1) self.failUnlessEqual(v("1234567890", maxlength=20), 1) self.failUnlessEqual(v("1234567890", maxlength=10), 1) self.failUnlessEqual(v("1234567890", maxlength=0), 1) self.failIfEqual(v("1234567890", maxlength=9), 1) self.failIfEqual(v("1234567890", maxlength=1), 1)
def test_isNotTooLong(self): from Products.validation import validation v = validation.validatorFor('isNotTooLong') self.failUnlessEqual(v('', maxlength=20), 1) self.failUnlessEqual(v('1234567890', maxlength=20), 1) self.failUnlessEqual(v('1234567890', maxlength=10), 1) self.failUnlessEqual(v('1234567890', maxlength=0), 1) self.failIfEqual(v('1234567890', maxlength=9), 1) self.failIfEqual(v('1234567890', maxlength=1), 1)
def test_isCommaSeparatedEmails(self): v = validation.validatorFor('pfgv_isCommaSeparatedEmails') self.failUnlessEqual(v('[email protected],[email protected]'), 1) self.failUnlessEqual(v('[email protected], [email protected]'), 1) self.failIfEqual(v('[email protected]; [email protected]'), 1)
def test_isUnchecked(self): v = validation.validatorFor('isUnchecked') self.failUnlessEqual(v('0'), 1) self.failIfEqual(v('1'), 1)
def test_isEmail(self): v = validation.validatorFor('isEmail') self.failUnlessEqual(v('*****@*****.**'), 1) self.failUnlessEqual(v('*****@*****.**'), 1) self.failIfEqual(v('@there.com'), 1)
def test_isCommaSeparatedEmails(self): v = validation.validatorFor("pfgv_isCommaSeparatedEmails") self.failUnlessEqual(v("[email protected],[email protected]"), 1) self.failUnlessEqual(v("[email protected], [email protected]"), 1) self.failIfEqual(v("[email protected]; [email protected]"), 1)
def test_isEmail(self): v = validation.validatorFor("isEmail") self.failUnlessEqual(v("*****@*****.**"), 1) self.failUnlessEqual(v("*****@*****.**"), 1) self.failIfEqual(v("@there.com"), 1)
def test_isUnchecked(self): v = validation.validatorFor("isUnchecked") self.failUnlessEqual(v("0"), 1) self.failIfEqual(v("1"), 1)
def test_isUnchecked(self): from Products.validation import validation v = validation.validatorFor('isUnchecked') self.failUnlessEqual(v('0'), 1) self.failIfEqual(v('1'), 1)