'Ensure that covered indexes can be used'

def test_covered_index(self):

    class Test(Document, ):
        a = IntField()
        b = IntField()
        meta = {'indexes': ['a'], 'allow_inheritance': False}
    Test.drop_collection()
    obj = Test(a=1)
    obj.save()
    IS_MONGODB_3 = (get_mongodb_version()[0] >= 3)
    query_plan = Test.objects(id=obj.id).exclude('a').explain()
    if (not IS_MONGODB_3):
        self.assertFalse(query_plan['indexOnly'])
    else:
        self.assertEqual(query_plan.get('queryPlanner').get('winningPlan').get('inputStage').get('stage'), 'IDHACK')
    query_plan = Test.objects(id=obj.id).only('id').explain()
    if (not IS_MONGODB_3):
        self.assertTrue(query_plan['indexOnly'])
    else:
        self.assertEqual(query_plan.get('queryPlanner').get('winningPlan').get('inputStage').get('stage'), 'IDHACK')
    query_plan = Test.objects(a=1).only('a').exclude('id').explain()
    if (not IS_MONGODB_3):
        self.assertTrue(query_plan['indexOnly'])
    else:
        self.assertEqual(query_plan.get('queryPlanner').get('winningPlan').get('inputStage').get('stage'), 'IXSCAN')
        self.assertEqual(query_plan.get('queryPlanner').get('winningPlan').get('stage'), 'PROJECTION')
    query_plan = Test.objects(a=1).explain()
    if (not IS_MONGODB_3):
        self.assertFalse(query_plan['indexOnly'])
    else:
        self.assertEqual(query_plan.get('queryPlanner').get('winningPlan').get('inputStage').get('stage'), 'IXSCAN')
        self.assertEqual(query_plan.get('queryPlanner').get('winningPlan').get('stage'), 'FETCH')
