def test_21_upgrade_baseline_current(capsys): """Verify baseline-current and baseline-info and get_version()""" try: os.unlink(TEST_DB_FILE) except: pass config = pydbvolve.initialize(TEST_CONFIG_FILE, 'upgrade', 'r1.1.0', True, False) assert (config is not None) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', pydbvolve.LATEST_VERSION, True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', pydbvolve.CURRENT_VERSION, True, False) assert (rc == 0) curr = pydbvolve.get_current(config) assert curr is not None base = pydbvolve.get_baseline(config) assert base is not None assert curr['version'] == base['version'] os.unlink(TEST_DB_FILE)
def test_18_bad_upgrade_downgrade(): """Verify run_migration exectuion""" try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', '100.100.200', True, False) assert (rc != 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'downgrade', '100.100.200', True, False) assert (rc != 0) os.unlink(TEST_DB_FILE)
def test_19_upgrade_downgrade_without_baseline(): """Verify run_migration exectuion""" try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', pydbvolve.LATEST_VERSION, True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'downgrade', 'r0.0.0', True, False) assert (rc == 0) os.unlink(TEST_DB_FILE)
def test_22_downgrade_baseline(capsys): """Verify downgrade-baseline""" try: os.unlink(TEST_DB_FILE) except: pass config = pydbvolve.initialize(TEST_CONFIG_FILE, 'upgrade', 'r1.1.0', True, False) assert (config is not None) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', 'r1.2.9', True, False, chatty=False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', pydbvolve.CURRENT_VERSION, True, False) assert (rc == 0) curr = pydbvolve.get_current(config) assert curr is not None base = pydbvolve.get_current(config) assert curr is not None assert curr['version'] == 'r1.2.9' assert curr['version'] == base['version'] rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', pydbvolve.LATEST_VERSION, True, False) assert (rc == 0) curr = pydbvolve.get_current(config) assert curr is not None assert curr['version'] != 'r1.2.9' rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'downgrade', pydbvolve.BASELINE_VERSION, True, False) assert (rc == 0) curr = pydbvolve.get_current(config) assert curr is not None assert curr['version'] == 'r1.2.9' os.unlink(TEST_DB_FILE)
def test_11_run_migration_bad_command(): """Verify that run_migration detects a bad command""" try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'BAD_COMMAND_STRING', 'r1.0.0', True, False) assert (rc != 0) # test second path (which should not be hit, but you never know...) pydbvolve.VALID_ACTIONS.add('BAD_COMMAND_STRING') rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'BAD_COMMAND_STRING', 'r1.0.0', True, False) assert (rc != 0) importlib.reload(pydbvolve) os.unlink(TEST_DB_FILE)
def test_17_get_info(): try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.0.0', True, False) assert (rc == 0) rc = True try: pydbvolve.run_migration(TEST_CONFIG_FILE, 'info', 'current', True, False) except: rc = False assert (rc) os.unlink(TEST_DB_FILE)
def test_20_downgrade_without_upgrade(capsys): """Verify run_migration exectuion""" try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'downgrade', 'r0.0.0', True, False) assert (rc == 30) os.unlink(TEST_DB_FILE)
def test_16_post_exec_trap_exception(): def raise_it(*args, **kwargs): raise Exception("Something") try: os.unlink(TEST_DB_FILE) except: pass pydbvolve.post_execution = raise_it rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.0.0', True, False) assert (rc != 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.0.0', True, True) assert (rc != 0) importlib.reload(pydbvolve) os.unlink(TEST_DB_FILE)
def test_12_run_migration_bad_config(): """Verify that run_migration detects a bad config""" def bad_init_1(*args, **kwargs): return None def bad_init_2(*args, **kwargs): return {'a': 1} rc = pydbvolve.run_migration(TEST_CONFIG_FILE + 'bad', 'BAD_COMMAND_STRING', 'r1.0.0', True, False) assert (rc != 0) pydbvolve.initialize = bad_init_1 rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'BAD_COMMAND_STRING', 'r1.0.0', True, False) assert (rc != 0) pydbvolve.initialize = bad_init_2 rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'BAD_COMMAND_STRING', 'r1.0.0', True, False) assert (rc != 0) importlib.reload(pydbvolve)
def test_10_run_migration_bad_migration_table(): """Verify run_migration exectuion detects bad structure""" try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.0.0', True, False) assert (rc == 0) conn = sqlite3.connect(TEST_DB_FILE) conn.execute("drop table __migrations__;") conn.execute(""" create table __migrations__ (bad text, cols text); """) conn.close() rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.0.0', True, False) assert (rc != 0) os.unlink(TEST_DB_FILE)
def test_14_migration_log(): """Verify migration_log execution""" try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.0.0', True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', pydbvolve.LATEST_VERSION, True, False) assert (rc == 0) rc = True try: pydbvolve.run_migration(TEST_CONFIG_FILE, 'log', 'all', True, False) except: rc = False assert (rc) os.unlink(TEST_DB_FILE)
def test_13_run_migration(capsys): """Verify run_migration exectuion""" try: os.unlink(TEST_DB_FILE) except: pass rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.2.0', True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'upgrade', pydbvolve.LATEST_VERSION, True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'verify', 'r1.3.1', True, False) assert (rc == 0) config = pydbvolve.initialize(TEST_CONFIG_FILE, 'verify', 'r1.3.1', True, False) all_migrations = pydbvolve.get_migration_data(config) all_versions = set(m['version'] for m in all_migrations) assert ('r0.0.0' not in all_versions) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'downgrade', 'r1.2.0', True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'verify', 'r1.2.0', True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'downgrade', 'r1.1.0', True, True) assert (rc != 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'baseline', 'r1.3.0', True, False) assert (rc == 0) rc = pydbvolve.run_migration(TEST_CONFIG_FILE, 'downgrade', 'r1.1.0', True, True) assert (rc != 0) os.unlink(TEST_DB_FILE)