'Test the init_cursor method
Cases:
1. no last checkpoint, no collection dump
2. no last checkpoint, collection dump ok and stuff to dump
3. no last checkpoint, nothing to dump, stuff in oplog
4. no last checkpoint, nothing to dump, nothing in oplog
5. no last checkpoint, no collection dump, stuff in oplog
6. last checkpoint exists
7. last checkpoint is behind'

def test_init_cursor(self):

    self.opman.oplog = self.primary_conn['test']['emptycollection']
    self.opman.collection_dump = False
    self.assertTrue(all(((doc['op'] == 'n') for doc in self.opman.init_cursor()[0])))
    self.assertEqual(self.opman.checkpoint, None)
    self.opman.collection_dump = True
    (cursor, cursor_empty) = self.opman.init_cursor()
    self.assertEqual(cursor, None)
    self.assertTrue(cursor_empty)
    self.assertEqual(self.opman.checkpoint, None)
    self.opman.oplog = self.primary_conn['local']['oplog.rs']
    collection = self.primary_conn['test']['test']
    collection.insert_one({'i': 1})
    collection.delete_one({'i': 1})
    time.sleep(3)
    last_ts = self.opman.get_last_oplog_timestamp()
    (cursor, cursor_empty) = self.opman.init_cursor()
    self.assertFalse(cursor_empty)
    self.assertEqual(self.opman.checkpoint, last_ts)
    self.assertEqual(self.opman.read_last_checkpoint(), last_ts)
    self.opman.checkpoint = None
    self.opman.oplog_progress = LockingDict()
    self.opman.collection_dump = False
    collection.insert_one({'i': 2})
    (cursor, cursor_empty) = self.opman.init_cursor()
    for doc in cursor:
        last_doc = doc
    self.assertEqual(last_doc['o']['i'], 2)
    self.assertIsNone(self.opman.checkpoint)
    collection.insert_many([{'i': (i + 500)} for i in range(1000)])
    entry = list(self.primary_conn['local']['oplog.rs'].find(skip=200, limit=(-2)))
    self.opman.update_checkpoint(entry[0]['ts'])
    (cursor, cursor_empty) = self.opman.init_cursor()
    self.assertEqual(next(cursor)['ts'], entry[1]['ts'])
    self.assertEqual(self.opman.checkpoint, entry[0]['ts'])
    self.assertEqual(self.opman.read_last_checkpoint(), entry[0]['ts'])
    self.opman.update_checkpoint(bson.Timestamp(1, 0))
    (cursor, cursor_empty) = self.opman.init_cursor()
    self.assertTrue(cursor_empty)
    self.assertEqual(cursor, None)
    self.assertEqual(self.opman.checkpoint, bson.Timestamp(1, 0))
