def test_no_keepalive_returns_new_connection(self):
        mgr = sqlitecon.SQLiteConnectionManager(":memory:", keepalive=False)
        with mgr.get_connection() as conn:
            conn.execute("CREATE TABLE words(word TEXT)")
            conn.execute("INSERT INTO words VALUES (?)", ("hello",))

        with mgr.get_connection() as conn:
            self.assertRaises(sqlite3.OperationalError, conn.execute,
                              "SELECT * FROM words")
    def test_keepalive_returns_same_connection(self):
        mgr = sqlitecon.SQLiteConnectionManager(":memory:", keepalive=True)
        with mgr.get_connection() as conn:
            conn.execute("CREATE TABLE words(word TEXT)")
            conn.execute("INSERT INTO words VALUES (?)", ("hello",))

        with mgr.get_connection() as conn:
            results = conn.execute("SELECT * FROM words")
            self.assertEqual("hello", results.next()["word"])
    def setUp(self):
        if not FLAGS.verbose_tests:
            logging.disable(logging.CRITICAL)
        self.db = sqlite_log_db.SQLiteLogDB(
            sqlitecon.SQLiteConnectionManager(":memory:", keepalive=True))
        self.temp_db = sqlite_temp_db.SQLiteTempDB(
            sqlitecon.SQLiteConnectionManager(":memory:", keepalive=True))

        default_state = client_pb2.MonitorState()
        default_state.verified_sth.CopyFrom(self._DEFAULT_STH)
        self.state_keeper = InMemoryStateKeeper(default_state)
        self.verifier = mock.Mock()
        self.hasher = merkle.TreeHasher()

        # Make sure the DB knows about the default log server.
        log = client_pb2.CtLogMetadata()
        log.log_server = "log_server"
        self.db.add_log(log)
 def setUp(self):
     self.database = sqlite_cert_db.SQLiteCertDB(
         sqlitecon.SQLiteConnectionManager(":memory:", keepalive=True))
 def setUp(self):
     self.database_dir = tempfile.mkdtemp()
     self.factory = sqlite_temp_db.SQLiteTempDBFactory(
         sqlitecon.SQLiteConnectionManager(":memory:", keepalive=True),
         self.database_dir)
     self.temp_stores = set()
Exemplo n.º 6
0
                                               columns,
                                               order_by="timestamp")

    def run(self):
        """Set up the HTTP server and loop forever."""
        httpd = simple_server.make_server(self.host, self.port, self)
        logging.info("Serving on http://%s:%d" % (self.host, self.port))
        httpd.serve_forever()


if __name__ == "__main__":
    sys.argv = FLAGS(sys.argv)
    logging.basicConfig(level=FLAGS.log_level)

    sqlite_log_db = sqlite_log_db.SQLiteLogDB(
        sqlitecon.SQLiteConnectionManager(FLAGS.ct_sqlite_db))

    if not os.path.exists(FLAGS.ct_sqlite_temp_dir):
        logging.info("Creating directory for temporary data at %s" %
                     FLAGS.ct_sqlite_temp_dir)
        os.makedirs(FLAGS.ct_sqlite_temp_dir)

    if not os.path.exists(FLAGS.monitor_state_dir):
        logging.info("Creating directory for monitor state at %s" %
                     FLAGS.monitor_state_dir)
        os.makedirs(FLAGS.monitor_state_dir)

    sqlite_temp_db_factory = sqlite_temp_db.SQLiteTempDBFactory(
        sqlitecon.SQLiteConnectionManager(FLAGS.ct_sqlite_temp_dir + "/meta"),
        FLAGS.ct_sqlite_temp_dir)
 def test_get_connection(self):
     mgr = sqlitecon.SQLiteConnectionManager(":memory:")
     self.assertIsInstance(mgr.get_connection(), sqlitecon.SQLiteConnection)