def testPassword(self): def process(pw, val, val2=None): if val2 is None: val2 = val return flpr( formless.Property('password', pw), {'password': [val], 'password____2': [val2]})['password'] s = formless.Password() self.assertEqual(process(s, "Fooo"), "Fooo") self.assertEqual(process(s, "This is a string"), "This is a string") self.assertEqual(process(s, "This is a string"), "This is a string") self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\xc3\xa9sar') s = formless.Password(str=True) self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\u00e9sar') s = formless.Password(required=True) self.assertRaises(formless.ValidateError, process, s, "") s = formless.Password(required=False) self.assertEqual(process(s, "Bar"), "Bar") self.assertEqual(process(s, ""), None) s = formless.Password() self.assertEqual(process(s, ' abc '), ' abc ') s = formless.Password(strip=True, required=True) self.assertEqual(process(s, ' abc '), 'abc') self.assertRaises(formless.ValidateError, process, s, ' ') s = formless.Password(required=False, strip=True) self.assertEqual(process(s, ' abc '), 'abc') self.assertEqual(process(s, ' '), None)
def testPassword(self): def process(pw, val, val2=None): if val2 is None: val2 = val return flpr( formless.Property('password', pw), {'password': [val], 'password____2': [val2]})['password'] s = formless.Password(encoding="latin1") self.assertEqual(process(s, "Fooo"), "Fooo") self.assertEqual(process(s, "This is a string"), "This is a string") self.assertEqual(process(s, "This is a string"), "This is a string") self.assertEqual(process(s, b'C\xc3\xa9sar'), 'C\xc3\xa9sar') self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\xc3\xa9sar') # I'm not sure what functionality was intended here, and I can't # see how it was implemented. Let's assume we don't want it # any more -- MD 2018-08 # s = formless.Password(str=True) # self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\u00e9sar') s = formless.Password(required=True) self.assertRaises(formless.ValidateError, process, s, "") s = formless.Password(required=False) self.assertEqual(process(s, "Bar"), "Bar") self.assertEqual(process(s, ""), None) s = formless.Password() self.assertEqual(process(s, ' abc '), ' abc ') s = formless.Password(strip=True, required=True) self.assertEqual(process(s, ' abc '), 'abc') self.assertRaises(formless.ValidateError, process, s, ' ') s = formless.Password(required=False, strip=True) self.assertEqual(process(s, ' abc '), 'abc') self.assertEqual(process(s, ' '), None)
def password(pword=formless.Password(), integer=formless.Integer()): pass