Example #1
0
 def tearDown(self):
     engine = sqlalchemy.create_engine(self.db_uri + '/postgres')
     conn = engine.connect()
     conn.execute("commit")
     # close all active connections
     conn.execute("SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'counter_test' AND pid <> pg_backend_pid()")
     conn.execute("commit")
     conn.execute("drop database "  + self.db_name)
     conn.close()
Example #2
0
def setup_db():
    """Set up the local and test databases."""
    (base_uri, local_db) = application.config['SQLALCHEMY_DATABASE_URI'].rsplit('/', 1)
    engine = sqlalchemy.create_engine('/'.join([base_uri, DEFAULT_DB]))
    conn = engine.connect()
    conn.execute('commit')
    conn.execute(CREATE_DB % local_db)
    conn.execute('commit')
    test_db = local_db + '_test'
    conn.execute(CREATE_DB % test_db)
    conn.close()
Example #3
0
def setup_db():
    (base_uri, local_db) = settings.SQLALCHEMY_DATABASE_URI.rsplit('/', 1)
    engine = sqlalchemy.create_engine('/'.join([base_uri, DEFAULT_DB]))
    conn = engine.connect()
    conn.execute('commit')
    # The dbname part of the database URI for the selected configuration.
    conn.execute(CREATE_DB % local_db)
    conn.execute('commit')
    # By convention, the name as the normal db but with "_test" appended.
    test_db = local_db + "_test"
    conn.execute(CREATE_DB % test_db)
    conn.close()
def addFileLogging():
    if LOG_SQL:
        engine = sqlalchemy.create_engine(SQLALCHEMY_DATABASE_URI, echo=True)
        logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
    
    from logging.handlers import RotatingFileHandler
    # file location, maximum size of the file, and number of backups to be kept 
    file_handler = RotatingFileHandler('tmp/log.log', 'a', 1 * 1024 * 1024, 10)
    # format like 2013-07-13 13:01:54,083 in location
    file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
    
    # file logging level
    file_handler.setLevel(logging.INFO)
    app.logger.addHandler(file_handler)
Example #5
0
 def setUp(self):
     # we need to use the root user
     # to be able to create the new database
     self.db_username = os.environ['DB_USERNAME']
     self.db_password = os.environ['DB_PASSWORD']
     self.db_name = os.environ['DATABASE_NAME'] + '_test'
     self.db_uri = 'postgresql://%s:%s@%s:5432' % (self.db_username, self.db_password, DB_HOST)
     engine = sqlalchemy.create_engine(self.db_uri + '/postgres')
     conn = engine.connect()
     conn.execute("commit")
     conn.execute("create database "  + self.db_name)
     conn.close()
     self.app_factory = self.create_app()
     self.app = self.app_factory.test_client()
     with self.app_factory.app_context():
         db.create_all()