def test_strips_text(self): # The set method should strip the string before setting the field. target = make_target() field = StrippableText(__name__='test', strip_text=True) self.assertTrue(field.strip_text) field.set(target, ' testing ') self.assertEqual('testing', target.test)
def test_default_constructor(self): # If strip_text is not set, or set to false, then the text is not # stripped when set. target = make_target() field = StrippableText(__name__='test') self.assertFalse(field.strip_text) field.set(target, ' testing ') self.assertEqual(' testing ', target.test)
def test_strips_text_trailing_only(self): # The set method strips the trailing whitespace. target = make_target() field = StrippableText( __name__='test', strip_text=True, trailing_only=True) self.assertTrue(field.trailing_only) field.set(target, ' testing ') self.assertEqual(' testing', target.test)
def test_strips_text_trailing_only(self): # The set method strips the trailing whitespace. target = make_target() field = StrippableText(__name__='test', strip_text=True, trailing_only=True) self.assertTrue(field.trailing_only) field.set(target, ' testing ') self.assertEqual(' testing', target.test)
def test_setting_with_none(self): # The set method is given None, the attribute is set to None target = make_target() field = StrippableText(__name__='test', strip_text=True) field.set(target, None) self.assertIs(None, target.test)
def test_validate_max_contraints(self): # The minimum length constraint tests the stripped string. field = StrippableText( __name__='test', strip_text=True, max_length=2) self.assertEqual(None, field.validate(u' a '))
def test_validate_min_contraints(self): # The minimum length constraint tests the stripped string. field = StrippableText(__name__='test', strip_text=True, min_length=1) self.assertRaises(TooShort, field.validate, u' ')
def test_validate_max_contraints(self): # The minimum length constraint tests the stripped string. field = StrippableText(__name__='test', strip_text=True, max_length=2) self.assertEqual(None, field.validate(u' a '))