add tests to increase coverage

This commit is contained in:
Erdenezul Batmunkh 2017-09-10 13:09:20 +09:00
parent 70088704e2
commit ba99190f53
2 changed files with 30 additions and 0 deletions

View File

@ -312,6 +312,27 @@ class FieldTest(MongoDBTestCase):
self.assertEqual(1, TestDocument.objects(long_fld__ne=None).count()) self.assertEqual(1, TestDocument.objects(long_fld__ne=None).count())
def test_callable_validation(self):
"""Ensure that callable validation works"""
def check_even(value):
return value % 2 == 0
class Order(Document):
number = IntField(validation=check_even)
Order.drop_collection()
order = Order(number=3)
self.assertRaises(ValidationError, order.validate)
class User(Document):
name = StringField(validation=1)
User.drop_collection()
user = User(name='test')
self.assertRaises(ValidationError, user.validate)
def test_object_id_validation(self): def test_object_id_validation(self):
"""Ensure that invalid values cannot be assigned to an """Ensure that invalid values cannot be assigned to an
ObjectIdField. ObjectIdField.
@ -527,6 +548,11 @@ class FieldTest(MongoDBTestCase):
class User(Document): class User(Document):
name = StringField(db_field='name\0') name = StringField(db_field='name\0')
# db field should be a string
with self.assertRaises(TypeError):
class User(Document):
name = StringField(db_field=1)
def test_decimal_comparison(self): def test_decimal_comparison(self):
class Person(Document): class Person(Document):
money = DecimalField() money = DecimalField()

View File

@ -1861,6 +1861,10 @@ class QuerySetTest(unittest.TestCase):
post = BlogPost(name="Test Post", hits=5, tags=['test']) post = BlogPost(name="Test Post", hits=5, tags=['test'])
post.save() post.save()
BlogPost.objects.update(hits=11)
post.reload()
self.assertEqual(post.hits, 11)
BlogPost.objects.update(set__hits=10) BlogPost.objects.update(set__hits=10)
post.reload() post.reload()
self.assertEqual(post.hits, 10) self.assertEqual(post.hits, 10)