Make absolutely sure we have foreign keys enabled on all tests

This commit is contained in:
Joseph Schorr 2018-09-24 11:10:26 -04:00
parent 3dc9ddc6b3
commit 5422386de4

View file

@ -135,6 +135,7 @@ def appconfig(database_uri):
@pytest.fixture()
def initialized_db(appconfig):
""" Configures the database for the database found in the appconfig. """
under_test_real_database = bool(os.environ.get('TEST_DATABASE_URI'))
# Configure the database.
configure(appconfig)
@ -144,8 +145,12 @@ def initialized_db(appconfig):
model._basequery.get_public_repo_visibility()
model.log.get_log_entry_kinds()
if not under_test_real_database:
# Make absolutely sure foreign key constraints are on.
db.obj.execute_sql('PRAGMA foreign_keys = ON;')
assert db.obj.execute_sql('PRAGMA foreign_keys;').fetchone()[0] == 1
# If under a test *real* database, setup a savepoint.
under_test_real_database = bool(os.environ.get('TEST_DATABASE_URI'))
if under_test_real_database:
with db.transaction():
test_savepoint = db.savepoint()