Merge pull request #1716 from MongoEngine/revert-1645-inc_cov
Revert "add tests to increase code coverage"
This commit is contained in:
commit
b705f5b743
@ -312,27 +312,6 @@ 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.
|
||||||
@ -355,7 +334,7 @@ class FieldTest(MongoDBTestCase):
|
|||||||
def test_string_validation(self):
|
def test_string_validation(self):
|
||||||
"""Ensure that invalid values cannot be assigned to string fields."""
|
"""Ensure that invalid values cannot be assigned to string fields."""
|
||||||
class Person(Document):
|
class Person(Document):
|
||||||
name = StringField(max_length=20, min_length=5)
|
name = StringField(max_length=20)
|
||||||
userid = StringField(r'[0-9a-z_]+$')
|
userid = StringField(r'[0-9a-z_]+$')
|
||||||
|
|
||||||
person = Person(name=34)
|
person = Person(name=34)
|
||||||
@ -373,10 +352,6 @@ class FieldTest(MongoDBTestCase):
|
|||||||
person = Person(name='Name that is more than twenty characters')
|
person = Person(name='Name that is more than twenty characters')
|
||||||
self.assertRaises(ValidationError, person.validate)
|
self.assertRaises(ValidationError, person.validate)
|
||||||
|
|
||||||
# Test max length validation on name
|
|
||||||
person = Person(name='aa')
|
|
||||||
self.assertRaises(ValidationError, person.validate)
|
|
||||||
|
|
||||||
person.name = 'Shorter name'
|
person.name = 'Shorter name'
|
||||||
person.validate()
|
person.validate()
|
||||||
|
|
||||||
@ -462,10 +437,6 @@ class FieldTest(MongoDBTestCase):
|
|||||||
doc.age = 'ten'
|
doc.age = 'ten'
|
||||||
self.assertRaises(ValidationError, doc.validate)
|
self.assertRaises(ValidationError, doc.validate)
|
||||||
|
|
||||||
# Test max_value validation
|
|
||||||
doc.value = 200
|
|
||||||
self.assertRaises(ValidationError, doc.validate)
|
|
||||||
|
|
||||||
def test_float_validation(self):
|
def test_float_validation(self):
|
||||||
"""Ensure that invalid values cannot be assigned to float fields.
|
"""Ensure that invalid values cannot be assigned to float fields.
|
||||||
"""
|
"""
|
||||||
@ -548,11 +519,6 @@ 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()
|
||||||
|
@ -429,10 +429,6 @@ class GeoQueriesTest(MongoDBTestCase):
|
|||||||
roads = Road.objects.filter(line__geo_within=polygon).count()
|
roads = Road.objects.filter(line__geo_within=polygon).count()
|
||||||
self.assertEqual(1, roads)
|
self.assertEqual(1, roads)
|
||||||
|
|
||||||
sphere = [[-1, 42,], 2]
|
|
||||||
roads = Road.objects.filter(line__geo_within_sphere=sphere).count()
|
|
||||||
self.assertEqual(0, roads)
|
|
||||||
|
|
||||||
roads = Road.objects.filter(line__geo_within={"$geometry": polygon}).count()
|
roads = Road.objects.filter(line__geo_within={"$geometry": polygon}).count()
|
||||||
self.assertEqual(1, roads)
|
self.assertEqual(1, roads)
|
||||||
|
|
||||||
|
@ -1861,10 +1861,6 @@ 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)
|
||||||
@ -1886,12 +1882,6 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
post.reload()
|
post.reload()
|
||||||
self.assertTrue('mongo' in post.tags)
|
self.assertTrue('mongo' in post.tags)
|
||||||
|
|
||||||
# Push with arrays
|
|
||||||
BlogPost.objects.update(push__tags=['python', 'scala'])
|
|
||||||
post.reload()
|
|
||||||
self.assertTrue('python' in post.tags)
|
|
||||||
self.assertTrue('scala' in post.tags)
|
|
||||||
|
|
||||||
BlogPost.objects.update_one(push_all__tags=['db', 'nosql'])
|
BlogPost.objects.update_one(push_all__tags=['db', 'nosql'])
|
||||||
post.reload()
|
post.reload()
|
||||||
self.assertTrue('db' in post.tags and 'nosql' in post.tags)
|
self.assertTrue('db' in post.tags and 'nosql' in post.tags)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user