Merge pull request #2063 from bagerard/improve_test

Improve minor things in the tests
This commit is contained in:
Bastien Gérard 2019-05-26 22:33:40 +02:00 committed by GitHub
commit da3773bfe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 27 deletions

View File

@ -409,7 +409,7 @@ class IndexesTest(unittest.TestCase):
self.assertEqual(2, User.objects.count())
info = User.objects._collection.index_information()
self.assertEqual(info.keys(), ['_id_'])
self.assertEqual(list(info.keys()), ['_id_'])
User.ensure_indexes()
info = User.objects._collection.index_information()

View File

@ -3204,7 +3204,7 @@ class InstanceTest(MongoDBTestCase):
p2.name = 'alon2'
p2.save()
p3 = Person.objects().only('created_on')[0]
self.assertEquals(orig_created_on, p3.created_on)
self.assertEqual(orig_created_on, p3.created_on)
class Person(Document):
created_on = DateTimeField(default=lambda: datetime.utcnow())
@ -3213,10 +3213,10 @@ class InstanceTest(MongoDBTestCase):
p4 = Person.objects()[0]
p4.save()
self.assertEquals(p4.height, 189)
self.assertEqual(p4.height, 189)
# However the default will not be fixed in DB
self.assertEquals(Person.objects(height=189).count(), 0)
self.assertEqual(Person.objects(height=189).count(), 0)
# alter DB for the new default
coll = Person._get_collection()
@ -3224,17 +3224,17 @@ class InstanceTest(MongoDBTestCase):
if 'height' not in person:
coll.update_one({'_id': person['_id']}, {'$set': {'height': 189}})
self.assertEquals(Person.objects(height=189).count(), 1)
self.assertEqual(Person.objects(height=189).count(), 1)
def test_from_son(self):
# 771
class MyPerson(self.Person):
meta = dict(shard_key=["id"])
p = MyPerson.from_json('{"name": "name", "age": 27}', created=True)
self.assertEquals(p.id, None)
self.assertEqual(p.id, None)
p.id = "12345" # in case it is not working: "OperationError: Shard Keys are immutable..." will be raised here
p = MyPerson._from_son({"name": "name", "age": 27}, created=True)
self.assertEquals(p.id, None)
self.assertEqual(p.id, None)
p.id = "12345" # in case it is not working: "OperationError: Shard Keys are immutable..." will be raised here
def test_from_son_created_False_without_id(self):
@ -3312,7 +3312,7 @@ class InstanceTest(MongoDBTestCase):
u_from_db = User.objects.get(name='user')
u_from_db.height = None
u_from_db.save()
self.assertEquals(u_from_db.height, None)
self.assertEqual(u_from_db.height, None)
# 864
self.assertEqual(u_from_db.str_fld, None)
self.assertEqual(u_from_db.int_fld, None)
@ -3326,7 +3326,7 @@ class InstanceTest(MongoDBTestCase):
u.save()
User.objects(name='user').update_one(set__height=None, upsert=True)
u_from_db = User.objects.get(name='user')
self.assertEquals(u_from_db.height, None)
self.assertEqual(u_from_db.height, None)
def test_not_saved_eq(self):
"""Ensure we can compare documents not saved.

View File

@ -1372,7 +1372,7 @@ class FieldTest(MongoDBTestCase):
brother = Brother(name="Bob", sibling=sister)
brother.save()
self.assertEquals(Brother.objects[0].sibling.name, sister.name)
self.assertEqual(Brother.objects[0].sibling.name, sister.name)
def test_reference_abstract_class(self):
"""Ensure that an abstract class instance cannot be used in the
@ -2045,8 +2045,8 @@ class FieldTest(MongoDBTestCase):
Dog().save()
Fish().save()
Human().save()
self.assertEquals(Animal.objects(_cls__in=["Animal.Mammal.Dog", "Animal.Fish"]).count(), 2)
self.assertEquals(Animal.objects(_cls__in=["Animal.Fish.Guppy"]).count(), 0)
self.assertEqual(Animal.objects(_cls__in=["Animal.Mammal.Dog", "Animal.Fish"]).count(), 2)
self.assertEqual(Animal.objects(_cls__in=["Animal.Fish.Guppy"]).count(), 0)
def test_sparse_field(self):
class Doc(Document):

View File

@ -320,16 +320,16 @@ class FileTest(MongoDBTestCase):
files = db.fs.files.find()
chunks = db.fs.chunks.find()
self.assertEquals(len(list(files)), 1)
self.assertEquals(len(list(chunks)), 1)
self.assertEqual(len(list(files)), 1)
self.assertEqual(len(list(chunks)), 1)
# Deleting the docoument should delete the files
testfile.delete()
files = db.fs.files.find()
chunks = db.fs.chunks.find()
self.assertEquals(len(list(files)), 0)
self.assertEquals(len(list(chunks)), 0)
self.assertEqual(len(list(files)), 0)
self.assertEqual(len(list(chunks)), 0)
# Test case where we don't store a file in the first place
testfile = TestFile()
@ -337,15 +337,15 @@ class FileTest(MongoDBTestCase):
files = db.fs.files.find()
chunks = db.fs.chunks.find()
self.assertEquals(len(list(files)), 0)
self.assertEquals(len(list(chunks)), 0)
self.assertEqual(len(list(files)), 0)
self.assertEqual(len(list(chunks)), 0)
testfile.delete()
files = db.fs.files.find()
chunks = db.fs.chunks.find()
self.assertEquals(len(list(files)), 0)
self.assertEquals(len(list(chunks)), 0)
self.assertEqual(len(list(files)), 0)
self.assertEqual(len(list(chunks)), 0)
# Test case where we overwrite the file
testfile = TestFile()
@ -358,15 +358,15 @@ class FileTest(MongoDBTestCase):
files = db.fs.files.find()
chunks = db.fs.chunks.find()
self.assertEquals(len(list(files)), 1)
self.assertEquals(len(list(chunks)), 1)
self.assertEqual(len(list(files)), 1)
self.assertEqual(len(list(chunks)), 1)
testfile.delete()
files = db.fs.files.find()
chunks = db.fs.chunks.find()
self.assertEquals(len(list(files)), 0)
self.assertEquals(len(list(chunks)), 0)
self.assertEqual(len(list(files)), 0)
self.assertEqual(len(list(chunks)), 0)
def test_image_field(self):
if not HAS_PIL:

View File

@ -91,7 +91,7 @@ class QuerySetTest(unittest.TestCase):
results = list(people)
self.assertIsInstance(results[0], self.Person)
self.assertIsInstance(results[0].id, (ObjectId, str, unicode))
self.assertIsInstance(results[0].id, ObjectId)
self.assertEqual(results[0], user_a)
self.assertEqual(results[0].name, 'User A')
@ -5609,8 +5609,8 @@ class QuerySetTest(unittest.TestCase):
Animal(is_mamal=False).save()
Cat(is_mamal=True, whiskers_length=5.1).save()
ScottishCat(is_mamal=True, folded_ears=True).save()
self.assertEquals(Animal.objects(folded_ears=True).count(), 1)
self.assertEquals(Animal.objects(whiskers_length=5.1).count(), 1)
self.assertEqual(Animal.objects(folded_ears=True).count(), 1)
self.assertEqual(Animal.objects(whiskers_length=5.1).count(), 1)
def test_loop_over_invalid_id_does_not_crash(self):
class Person(Document):