'Test write_oplog_progress under several circumstances'

def test_write_oplog_progress(self):

    try:
        os.unlink('temp_oplog.timestamp')
    except OSError:
        pass
    open('temp_oplog.timestamp', 'w').close()
    conn = Connector(mongo_address=self.repl_set.uri, oplog_checkpoint='temp_oplog.timestamp', **connector_opts)
    self.assertEqual(conn.write_oplog_progress(), None)
    conn.oplog_progress.get_dict()[1] = Timestamp(12, 34)
    conn.write_oplog_progress()
    data = json.load(open('temp_oplog.timestamp', 'r'))
    self.assertEqual(1, int(data[0]))
    self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(12, 34))
    self.assertFalse(os.path.exists(('temp_oplog.timestamp' + '~')))
    conn.oplog_progress.get_dict()[1] = Timestamp(44, 22)
    conn.write_oplog_progress()
    config_file = open('temp_oplog.timestamp', 'r')
    data = json.load(config_file)
    self.assertEqual(1, int(data[0]))
    self.assertEqual(long_to_bson_ts(int(data[1])), Timestamp(44, 22))
    config_file.close()
    os.unlink('temp_oplog.timestamp')
