コード例 #1
0
ファイル: pgplugintest.py プロジェクト: sblaes/DbMigrations
 def testInvalidDatabase(self):
     conf = Config()
     conf.fromMap(testConfig)
     creator = MigrationCreator('asdf', locationInTestspace())
     target = creator.createMigration()
     migrator = MigrationApplier(locationInTestspace(), conf)
     self.assertRaises(BaseException, migrator.applyMigration, target)
コード例 #2
0
ファイル: configtest.py プロジェクト: sblaes/DbMigrations
 def testFromMapWithoutPrefix(self):
     conf = Config()
     conf['hello'] = 'world'
     env = {'hello':'jello', 'foo':'bar'}
     conf.fromMap(env)
     self.assertTrue('hello' in conf)
     self.assertTrue('foo' in conf)
     self.assertEqual('jello', conf['hello'])
     self.assertEqual('bar', conf['foo'])
コード例 #3
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testPipesAdvancedOutput(self):
     command = "create table xxx (yyy integer primary key);"
     creator = MigrationCreator("migration_test", locationInTestspace())
     target = creator.createMigration(version=42, advanced=True, body="#!/bin/bash\necho -n '" + command + "' ")
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeDatabasePlugin(self)
     migrator.applyMigrations([target])
     migrator.plugin.assertCurrentVersion(42)
     migrator.plugin.assertCommandWasExecuted(command)
コード例 #4
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testAdvancedMigration(self):
     creator = MigrationCreator("migration_test", locationInTestspace())
     target = creator.createMigration(
         version=42, advanced=True, body="""#!/bin/bash\necho Hello World > testspace/test_output\n"""
     )
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeDatabasePlugin(self)
     migrator.applyMigrations([target])
     migrator.plugin.assertCurrentVersion(42)
     self.assertFileExists("test_output")
コード例 #5
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testDirectAppy(self):
     command = "create table xxx (yyy integer primary key);"
     creator = MigrationCreator("migration_test", locationInTestspace())
     target = creator.createMigration()
     self.assertFolderExists("migration_test", target)
     writeToFile(locationInTestspace("migration_test", target, "up"), command)
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeDatabasePlugin(self)
     migrator.applySingleMigration(target)
     migrator.plugin.assertCommandWasExecuted(command)
コード例 #6
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testEmptyUpFile(self):
     creator = MigrationCreator("migration_test", locationInTestspace())
     target1 = creator.createMigration(version=17, body="""select * from __mig_version__""")
     target2 = creator.createMigration(version=23, body="""""")
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeDatabasePlugin(self)
     self.assertRaisesRegexp(
         RuntimeError, "Invalid migration: Up file is empty", migrator.applyMigrations, ([target1, target2])
     )
     migrator.plugin.assertCurrentVersion(17)
コード例 #7
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testAppliesOutOfOrderMigrations(self):
     creator = MigrationCreator("migration_test", locationInTestspace())
     target1 = creator.createMigration(version=23, body="select 1")
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeMultiPlugin(self)
     migrator.applySingleMigration(target1)
     target2 = creator.createMigration(version=17, body="select 2")
     migrator.applyMigrations([target1, target2])
     migrator.plugin.assertCurrentVersion(23)
     migrator.plugin.assertCommandWasExecuted("select 1")
     migrator.plugin.assertCommandWasExecuted("select 2")
コード例 #8
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testRollback(self):
     command = "create table xxx (yyy integer primary key); alter blah blah blah;"
     target = MigrationCreator("migration_test", locationInTestspace()).createMigration()
     self.assertFolderExists("migration_test", target)
     writeToFile(locationInTestspace("migration_test", target, "up"), command)
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeDatabasePlugin(self)
     try:
         migrator.applyMigration(target)
     except:
         pass
     migrator.plugin.assertNoCommandWasExecuted()
コード例 #9
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testAppliesNoopMigrations(self):
     creator = MigrationCreator("migration_test", locationInTestspace())
     target1 = creator.createMigration(version=23, body="select 1")
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeMultiPlugin(self)
     migrator.applyMigrations([target1])
     migrator.plugin.assertCurrentVersion(23)
     migrator.plugin.assertCommandWasExecuted("select 1")
     migrator.dry_run = True
     migrator.applyMigrations([creator.createMigration(version=27, body="select 2")])
     migrator.plugin.assertCurrentVersion(23)
     migrator.plugin.assertCommandWasNotExecuted("select 2")
コード例 #10
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testTwoMigrationsTogether(self):
     command0 = "create table xxx (yyy integer primary key);"
     command1 = "create table aaa (bbb integer primary key);"
     creator = MigrationCreator("migration_test", locationInTestspace())
     targets = []
     targets.append(creator.createMigration(version=1, body=command0))
     targets.append(creator.createMigration(version=2, body=command1))
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeDatabasePlugin(self)
     migrator.applyMigrations(targets)
     migrator.plugin.assertCurrentVersion(2)
     migrator.plugin.assertCommandWasExecuted(command0)
     migrator.plugin.assertCommandWasExecuted(command1)
コード例 #11
0
ファイル: configtest.py プロジェクト: sblaes/DbMigrations
 def testFromMapWithPrefix(self):
     conf = Config()
     env = {'prefix_hello':'world', 'nonprefix_foo':'bar'}
     conf.fromMap(env, 'prefix_')
     self.assertFalse(conf.has('prefix_hello'))
     self.assertFalse(conf.has('nonprefix_foo'))
     self.assertTrue(conf.has('hello'))
     self.assertFalse(conf.has('foo'))
     self.assertEqual('world', conf.get('hello'))
コード例 #12
0
ファイル: appliertest.py プロジェクト: sblaes/DbMigrations
 def testSecondMigrationFails(self):
     command0 = "create table xxx (yyy integer primary key);"
     command1 = "alter blah blah blah;"
     creator = MigrationCreator("migration_test", locationInTestspace())
     targets = []
     targets.append(creator.createMigration(version=1, body=command0))
     targets.append(creator.createMigration(version=2, body=command1))
     conf = Config()
     conf.fromMap(testConfig)
     migrator = MigrationApplier(locationInTestspace(), conf)
     migrator.plugin = FakeDatabasePlugin(self, failOn=command1)
     try:
         migrator.applyMigrations(targets)
     except:  # Error is expected
         pass
     migrator.plugin.assertCurrentVersion(1)
     migrator.plugin.assertCommandWasExecuted(command0)
     migrator.plugin.assertCommandWasNotExecuted(command1)
コード例 #13
0
ファイル: configtest.py プロジェクト: sblaes/DbMigrations
 def testFromMapLowercase(self):
     conf = Config()
     env = {'prefix_hElLo':'world'}
     conf.fromMap(env, 'prefix_')
     self.assertFalse(conf.has('hElLo'))
     self.assertTrue(conf.has('hello'))
     self.assertEqual('world', conf.get('hello'))
コード例 #14
0
ファイル: configtest.py プロジェクト: sblaes/DbMigrations
 def testPrecedence(self):
     bucket = {'database':'mydb', 'options':{}, 'basedir':'.', 'prefix':'MIG_', 'host':'localhost', 'port':5432, 'user':'******'}
     env = {'database':'otherdb'}
     conf = Config()
     conf.initAll(Bunch(bucket), env)
     self.assertEqual('mydb', conf['database'])
コード例 #15
0
ファイル: configtest.py プロジェクト: sblaes/DbMigrations
 def testPutAndGet(self):
     conf = Config()
     conf.put('hello', 'world')
     self.assertTrue(conf.has('hello'))
     self.assertEqual('world', conf.get('hello'))