示例#1
0
 def testSqliteDb(self):
   db_uri = 'sqlite:' + os.path.join(self.get_temp_dir(), 'db')
   db_module, db_connection_provider = application.get_database_info(db_uri)
   self.assertTrue(hasattr(db_module, 'Date'))
   with contextlib.closing(db_connection_provider()) as conn:
     with conn:
       with contextlib.closing(conn.cursor()) as c:
         c.execute('create table peeps (name text)')
         c.execute('insert into peeps (name) values (?)', ('justine',))
   _, db_connection_provider = application.get_database_info(db_uri)
   with contextlib.closing(db_connection_provider()) as conn:
     with contextlib.closing(conn.cursor()) as c:
       c.execute('select name from peeps')
       self.assertEqual(('justine',), c.fetchone())
示例#2
0
 def testSqliteDb(self):
   db_uri = 'sqlite:' + os.path.join(self.get_temp_dir(), 'db')
   db_module, db_connection_provider = application.get_database_info(db_uri)
   self.assertTrue(hasattr(db_module, 'Date'))
   with contextlib.closing(db_connection_provider()) as conn:
     with conn:
       with contextlib.closing(conn.cursor()) as c:
         c.execute('create table peeps (name text)')
         c.execute('insert into peeps (name) values (?)', ('justine',))
   _, db_connection_provider = application.get_database_info(db_uri)
   with contextlib.closing(db_connection_provider()) as conn:
     with contextlib.closing(conn.cursor()) as c:
       c.execute('select name from peeps')
       self.assertEqual(('justine',), c.fetchone())
 def set_up_db(self):
   self.db_path = os.path.join(self.get_temp_dir(), 'db.db')
   self.db_uri = 'sqlite:' + self.db_path
   db_module, db_connection_provider = application.get_database_info(
       self.db_uri)
   context = base_plugin.TBContext(
       db_module=db_module,
       db_connection_provider=db_connection_provider,
       db_uri=self.db_uri)
   self.core_plugin = core_plugin.CorePlugin(context)
   self.plugin = scalars_plugin.ScalarsPlugin(context)
示例#4
0
 def _start_db_based_server(self):
     db_module, db_connection_provider = application.get_database_info(
         self.db_uri)
     context = base_plugin.TBContext(
         assets_zip_provider=get_test_assets_zip_provider(),
         db_module=db_module,
         db_connection_provider=db_connection_provider,
         db_uri=self.db_uri,
         window_title='title foo')
     self.db_based_plugin = core_plugin.CorePlugin(context)
     app = application.TensorBoardWSGI([self.db_based_plugin])
     self.db_based_server = werkzeug_test.Client(app, wrappers.BaseResponse)
示例#5
0
 def testTransactionRollback(self):
   db_uri = 'sqlite:' + os.path.join(self.get_temp_dir(), 'db')
   _, db_connection_provider = application.get_database_info(db_uri)
   with contextlib.closing(db_connection_provider()) as conn:
     with conn:
       with contextlib.closing(conn.cursor()) as c:
         c.execute('create table peeps (name text)')
     try:
       with conn:
         with contextlib.closing(conn.cursor()) as c:
           c.execute('insert into peeps (name) values (?)', ('justine',))
         raise IOError('hi')
     except IOError:
       pass
     with contextlib.closing(conn.cursor()) as c:
       c.execute('select name from peeps')
       self.assertIsNone(c.fetchone())
示例#6
0
 def testTransactionRollback(self):
   db_uri = 'sqlite:' + os.path.join(self.get_temp_dir(), 'db')
   _, db_connection_provider = application.get_database_info(db_uri)
   with contextlib.closing(db_connection_provider()) as conn:
     with conn:
       with contextlib.closing(conn.cursor()) as c:
         c.execute('create table peeps (name text)')
     try:
       with conn:
         with contextlib.closing(conn.cursor()) as c:
           c.execute('insert into peeps (name) values (?)', ('justine',))
         raise IOError('hi')
     except IOError:
       pass
     with contextlib.closing(conn.cursor()) as c:
       c.execute('select name from peeps')
       self.assertIsNone(c.fetchone())
示例#7
0
 def startDbBasedServer(self, temp_dir):
     self.db_uri = 'sqlite:' + os.path.join(temp_dir, 'db.sqlite')
     db_module, db_connection_provider = application.get_database_info(
         self.db_uri)
     if db_connection_provider is not None:
         with contextlib.closing(db_connection_provider()) as db_conn:
             schema = db.Schema(db_conn)
             schema.create_tables()
             schema.create_indexes()
     context = base_plugin.TBContext(
         assets_zip_provider=get_test_assets_zip_provider(),
         db_module=db_module,
         db_connection_provider=db_connection_provider,
         db_uri=self.db_uri,
         window_title='title foo')
     self.db_based_plugin = core_plugin.CorePlugin(context)
     app = application.TensorBoardWSGI([self.db_based_plugin])
     self.db_based_server = werkzeug_test.Client(app, wrappers.BaseResponse)
示例#8
0
 def testTransactionRollback_doesntDoAnythingIfIsolationLevelIsNone(self):
   # NOTE: This is a terrible idea. Don't do this.
   db_uri = ('sqlite:' + os.path.join(self.get_temp_dir(), 'db') +
             '?isolation_level=null')
   _, db_connection_provider = application.get_database_info(db_uri)
   with contextlib.closing(db_connection_provider()) as conn:
     with conn:
       with contextlib.closing(conn.cursor()) as c:
         c.execute('create table peeps (name text)')
     try:
       with conn:
         with contextlib.closing(conn.cursor()) as c:
           c.execute('insert into peeps (name) values (?)', ('justine',))
         raise IOError('hi')
     except IOError:
       pass
     with contextlib.closing(conn.cursor()) as c:
       c.execute('select name from peeps')
       self.assertEqual(('justine',), c.fetchone())
示例#9
0
 def testTransactionRollback_doesntDoAnythingIfIsolationLevelIsNone(self):
   # NOTE: This is a terrible idea. Don't do this.
   db_uri = ('sqlite:' + os.path.join(self.get_temp_dir(), 'db') +
             '?isolation_level=null')
   _, db_connection_provider = application.get_database_info(db_uri)
   with contextlib.closing(db_connection_provider()) as conn:
     with conn:
       with contextlib.closing(conn.cursor()) as c:
         c.execute('create table peeps (name text)')
     try:
       with conn:
         with contextlib.closing(conn.cursor()) as c:
           c.execute('insert into peeps (name) values (?)', ('justine',))
         raise IOError('hi')
     except IOError:
       pass
     with contextlib.closing(conn.cursor()) as c:
       c.execute('select name from peeps')
       self.assertEqual(('justine',), c.fetchone())