Fixup sqlite engine for tests
According to http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#pysqlite-serializable
This commit is contained in:
parent
faed30afcb
commit
c7be47780f
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue