Fixup sqlite engine for tests

According to
http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#pysqlite-serializable
This commit is contained in:
Yuriy Taraday 2015-12-30 18:13:13 +03:00
parent faed30afcb
commit c7be47780f
3 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import functools
import json
import flask_sqlalchemy
import sqlalchemy.event
from sqlalchemy import types
db = flask_sqlalchemy.SQLAlchemy()
@ -129,3 +130,15 @@ class EnvironmentSchemaValues(db.Model):
__table_args__ = (
db.UniqueConstraint(environment_id, schema_id, level_value_id),
)
def fix_sqlite():
engine = db.engine
@sqlalchemy.event.listens_for(engine, "connect")
def _connect(dbapi_connection, connection_record):
dbapi_connection.isolation_level = None
@sqlalchemy.event.listens_for(engine, "begin")
def _begin(conn):
conn.execute("BEGIN")

View File

@ -45,6 +45,7 @@ class TestApp(base.TestCase):
self.app = app.build_app()
self.app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///'
with self.app.app_context():
db.fix_sqlite()
db.db.create_all()
self.client = Client(self.app)

View File

@ -24,6 +24,7 @@ class _DBTestCase(base.TestCase):
self.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False # no warning
db.db.init_app(self.app)
with self.app.app_context():
db.fix_sqlite()
db.db.create_all()