@@ -920,6 +920,12 @@ class LogEntry(Document):
920920
921921 def test_list_validation (self ):
922922 """Ensure that a list field only accepts lists with valid elements."""
923+ AccessLevelChoices = (
924+ ('a' , u'Administration' ),
925+ ('b' , u'Manager' ),
926+ ('c' , u'Staff' ),
927+ )
928+
923929 class User (Document ):
924930 pass
925931
@@ -934,6 +940,7 @@ class BlogPost(Document):
934940 authors_as_lazy = ListField (LazyReferenceField (User ))
935941 generic = ListField (GenericReferenceField ())
936942 generic_as_lazy = ListField (GenericLazyReferenceField ())
943+ access_list = ListField (choices = AccessLevelChoices , display_sep = ', ' )
937944
938945 User .drop_collection ()
939946 BlogPost .drop_collection ()
@@ -951,6 +958,17 @@ class BlogPost(Document):
951958 post .tags = ('fun' , 'leisure' )
952959 post .validate ()
953960
961+ post .access_list = 'a,b'
962+ self .assertRaises (ValidationError , post .validate )
963+
964+ post .access_list = ['c' , 'd' ]
965+ self .assertRaises (ValidationError , post .validate )
966+
967+ post .access_list = ['a' , 'b' ]
968+ post .validate ()
969+
970+ self .assertEqual (post .get_access_list_display (), u'Administration, Manager' )
971+
954972 post .comments = ['a' ]
955973 self .assertRaises (ValidationError , post .validate )
956974 post .comments = 'yay'
0 commit comments