Improve coverage in fields test

This commit is contained in:
Bastien Gérard
2019-05-16 22:31:24 +02:00
parent c82f0c937d
commit bb1089e03d
4 changed files with 35 additions and 6 deletions

View File

@@ -208,10 +208,7 @@ class TestCachedReferenceField(MongoDBTestCase):
('pj', "PJ")
)
name = StringField()
tp = StringField(
choices=TYPES
)
tp = StringField(choices=TYPES)
father = CachedReferenceField('self', fields=('tp',))
Person.drop_collection()
@@ -222,6 +219,9 @@ class TestCachedReferenceField(MongoDBTestCase):
a2 = Person(name='Wilson Junior', tp='pf', father=a1)
a2.save()
a2 = Person.objects.with_id(a2.id)
self.assertEqual(a2.father.tp, a1.tp)
self.assertEqual(dict(a2.to_mongo()), {
"_id": a2.pk,
"name": u"Wilson Junior",
@@ -374,6 +374,9 @@ class TestCachedReferenceField(MongoDBTestCase):
self.assertEqual(o.to_mongo()['animal']['tag'], 'heavy')
self.assertEqual(o.to_mongo()['animal']['owner']['t'], 'u')
# Check to_mongo with fields
self.assertNotIn('animal', o.to_mongo(fields=['person']))
# counts
Ocorrence(person="teste 2").save()
Ocorrence(person="teste 3").save()