def test_enums(self): """ Test that if a field has an enum constraint and if the data doesn't fit the error message should give the list of the possible values. :return: """ descriptor = { "name": "Enum", "title": "Test Enum message", "type": "string", "format": "default", "constraints": { "required": False, "enum": ["val1", "val2", "val3"] } } f = SchemaField(descriptor) valid_values = ['val1', 'val2', 'val3', ''] # non required should accept blank for v in valid_values: self.assertIsNone(f.validation_error(v)) wrong_values = ['xxx'] for v in wrong_values: msg = f.validation_error(v) self.assertTrue(msg) # test that the error message contains each of the enum values. for vv in f.constraints['enum']: self.assertTrue(msg.find(vv) >= 0)