def testMatchWithUmlaut(self): fieldFormat = fields.ChoiceFieldFormat("geschlecht", False, None, u"\"männlich\", \"weiblich\"", _anyFormat) self.assertEquals(fieldFormat.validated(u"männlich"), u"männlich") self.assertRaises(fields.FieldValueError, fieldFormat.validated, u"unbekannt")
def testMatchingChoice(self): fieldFormat = fields.ChoiceFieldFormat("color", False, None, "red,grEEn, blue ", _anyFormat) self.assertEquals(fieldFormat.validated("red"), "red") # Value without blanks around it. self.assertEquals(fieldFormat.validated("grEEn"), "grEEn") # Value with blanks around it. self.assertEquals(fieldFormat.validated("blue"), "blue") # Disregard upper/lower case. self.assertRaises(fields.FieldValueError, fieldFormat.validated, "gReen") self.assertRaises(fields.FieldValueError, fieldFormat.validated, "")
def testPossiblyEmptyFieldWithLength(self): fieldFormat = fields.ChoiceFieldFormat("optional_color", True, ":5", "red, green, blue", _anyFormat) self.assertEquals(fieldFormat.validated("red"), "red") self.assertEquals(fieldFormat.validated(""), "")
def testMatchingOnlyChoice(self): fieldFormat = fields.ChoiceFieldFormat("color", False, None, "red", _anyFormat) self.assertEquals(fieldFormat.validated("red"), "red")
def testImproperChoice(self): fieldFormat = fields.ChoiceFieldFormat("color", False, None, "red,green, blue ", _anyFormat) self.assertRaises(fields.FieldValueError, fieldFormat.validated, "tree")