Example #1
0
def get_db():
    """Create a database connection and attach it to g"""
    if not hasattr(app, "engine"):
        init_engine(app)

    if not hasattr(g, "shadowdb"):
        shadowdb.Base.metadata.create_all(app.engine)
        Session = sessionmaker(bind=app.engine)
        g.session = Session()
        g.shadowdb = shadowdb.ShadowDB(g.session)

    return g.shadowdb
Example #2
0
 def setUp(self):
     self.temp_dir = tempfile.TemporaryDirectory()
     server.app.config['DB_URI'] = 'sqlite:///:memory:'
     server.app.config['UPLOAD_FOLDER'] = self.temp_dir.name
     server.init_engine(server.app)
     self.app = server.app.test_client()