allow field choices to be specified as a set

This commit is contained in:
Stefan Wojcik
2017-02-15 08:45:37 -05:00
parent ed34c2ca68
commit 8299ab1698
2 changed files with 23 additions and 4 deletions

View File

@@ -3205,8 +3205,22 @@ class FieldTest(unittest.TestCase):
shirt.size = "XS"
self.assertRaises(ValidationError, shirt.validate)
def test_choices_as_set(self):
"""Ensure that sets can be used as field choices"""
class Shirt(Document):
size = StringField(choices={'S', 'M', 'L', 'XL', 'XXL'})
Shirt.drop_collection()
shirt = Shirt()
shirt.validate()
shirt.size = "S"
shirt.validate()
shirt.size = "XS"
self.assertRaises(ValidationError, shirt.validate)
def test_choices_validation_documents(self):
"""
Ensure fields with document choices validate given a valid choice.