Fix full database test script to not fail randomly
- Switches database schema creation to alembic, which solves the MySQL issue (and makes sure we test migrations as well) - Adds a few time.sleep(1) to work around MySQL's second-precision issue when adding items to queues and then immediately retrieving them - Disables the storage proxy tests when running against non-SQLite databases, as it causes failures with the multiple process and multiple transactions - Changes initdb to support only populating the database, as well as fixing a few small items around the test data when working with non-SQLite data
This commit is contained in:
parent
244bf2a070
commit
e6ee538e15
5 changed files with 41 additions and 19 deletions
22
initdb.py
22
initdb.py
|
@ -222,8 +222,10 @@ def setup_database_for_testing(testcase, with_storage=False, force_rebuild=False
|
|||
logger.debug('Setting up DB for testing.')
|
||||
|
||||
# Setup the database.
|
||||
wipe_database()
|
||||
initialize_database()
|
||||
if os.environ.get('SKIP_DB_SCHEMA', '') != 'true':
|
||||
wipe_database()
|
||||
initialize_database()
|
||||
|
||||
populate_database(with_storage=with_storage)
|
||||
|
||||
models_missing_data = find_models_missing_data()
|
||||
|
@ -414,6 +416,20 @@ def wipe_database():
|
|||
def populate_database(minimal=False, with_storage=False):
|
||||
logger.debug('Populating the DB with test data.')
|
||||
|
||||
# Note: databases set up with "real" schema (via Alembic) will not have these types
|
||||
# type, so we it here it necessary.
|
||||
try:
|
||||
ImageStorageLocation.get(name='local_eu')
|
||||
ImageStorageLocation.get(name='local_us')
|
||||
except ImageStorageLocation.DoesNotExist:
|
||||
ImageStorageLocation.create(name='local_eu')
|
||||
ImageStorageLocation.create(name='local_us')
|
||||
|
||||
try:
|
||||
NotificationKind.get(name='test_notification')
|
||||
except NotificationKind.DoesNotExist:
|
||||
NotificationKind.create(name='test_notification')
|
||||
|
||||
new_user_1 = model.user.create_user('devtable', 'password', 'jschorr@devtable.com')
|
||||
new_user_1.verified = True
|
||||
new_user_1.stripe_id = TEST_STRIPE_ID
|
||||
|
@ -423,7 +439,7 @@ def populate_database(minimal=False, with_storage=False):
|
|||
logger.debug('Skipping most db population because user requested mininal db')
|
||||
return
|
||||
|
||||
UserRegion.create(user=new_user_1, location=1)
|
||||
UserRegion.create(user=new_user_1, location=ImageStorageLocation.get(name='local_us'))
|
||||
model.release.set_region_release('quay', 'us', 'v0.1.2')
|
||||
|
||||
model.user.create_confirm_email_code(new_user_1, new_email='typo@devtable.com')
|
||||
|
|
Reference in a new issue