Upgrade Peewee to latest 3.x

This requires a number of small changes in the data model code, as well as additional testing.
This commit is contained in:
Brad Ison 2018-04-06 13:48:01 -04:00 committed by Joseph Schorr
parent 70b7ee4654
commit d3d9cca182
26 changed files with 220 additions and 193 deletions

View file

@ -7,8 +7,7 @@ import os
import argparse
from datetime import datetime, timedelta, date
from peewee import (SqliteDatabase, create_model_tables, drop_model_tables, savepoint_sqlite,
savepoint)
from peewee import SqliteDatabase
from itertools import count
from uuid import UUID, uuid4
from threading import Event
@ -210,6 +209,7 @@ def finished_database_for_testing(testcase):
any changes should be discarded.
"""
testcases[testcase]['savepoint'].__exit__(True, None, None)
testcases[testcase]['atomic'].__exit__(True, None, None)
def setup_database_for_testing(testcase, with_storage=False, force_rebuild=False):
""" Called when a testcase has started using the database, indicating that
@ -242,15 +242,16 @@ def setup_database_for_testing(testcase, with_storage=False, force_rebuild=False
db_initialized_for_testing.set()
# Create a savepoint for the testcase.
test_savepoint = savepoint(db) if IS_TESTING_REAL_DATABASE else savepoint_sqlite(db)
testcases[testcase] = {}
testcases[testcase]['savepoint'] = test_savepoint
testcases[testcase]['atomic'] = db.manual_commit()
testcases[testcase]['atomic'].__enter__()
testcases[testcase]['savepoint'] = db.savepoint()
testcases[testcase]['savepoint'].__enter__()
def initialize_database():
create_model_tables(all_models)
db.create_tables(all_models)
Role.create(name='admin')
Role.create(name='write')
@ -447,7 +448,7 @@ def wipe_database():
if not IS_TESTING_REAL_DATABASE and not isinstance(db.obj, SqliteDatabase):
raise RuntimeError('Attempted to wipe production database!')
drop_model_tables(all_models, fail_silently=True)
db.drop_tables(all_models)
def populate_database(minimal=False, with_storage=False):