[fix]pass test case and fix field type error

This commit is contained in:
Bo.Yi 2017-07-06 16:07:51 +08:00
parent e6a30f899c
commit 820b5cbb86
2 changed files with 6 additions and 4 deletions

View File

@ -1080,9 +1080,11 @@ class BaseDocument(object):
"""Return the display value for a choice field"""
value = getattr(self, field.name)
if field.choices and isinstance(field.choices[0], (list, tuple)):
if value is None:
return None
sep = getattr(field, 'display_sep', u' ')
values = value if field.__name__ == 'ListField' else [value]
values = value if field.__class__.__name__ == 'ListField' else [value]
return sep.join([
dict(field.choices).get(val, val)
for val in values])
for val in values or []])
return value

View File

@ -957,10 +957,10 @@ class FieldTest(MongoDBTestCase):
post.validate()
post.access_list = 'a,b'
self.assertRaises(ValidationError, post.validate())
self.assertRaises(ValidationError, post.validate)
post.access_list = ['c', 'd']
self.assertRaises(ValidationError, post.validate())
self.assertRaises(ValidationError, post.validate)
post.access_list = ['a', 'b']
post.validate()