def test_creates_proper_alter_chain(self): sys.argv = make_argv(['-f', '1']) self.newCommand.run() sleep(0.15) sys.argv = make_argv(['-f', '2']) self.newCommand.run() chain_tail = ChainUtil.build_chain() self.assertTrue(chain_tail.backref is not None) self.assertTrue(chain_tail.backref.backref is None)
def test_up_resumes_after_last_executed_alter(self): AlterUtil.create_alters([1]) sys.argv = make_argv([]) self.upCommand.run() self.assertEqual(len(MemoryDb.data), 1) AlterUtil.create_alters([2]) sys.argv = make_argv([]) self.upCommand.run() self.assertEqual(len(MemoryDb.data), 2)
def test_creates_proper_alter_chain(self): sys.argv = make_argv(["-f", "1"]) self.newCommand.run() sleep(0.15) sys.argv = make_argv(["-f", "2"]) self.newCommand.run() chain_tail = ChainUtil.build_chain() self.assertTrue(chain_tail.backref is not None) self.assertTrue(chain_tail.backref.backref is None)
def test_base_undoes_none_when_no_alters(self): self.assertEqual(len(MemoryDb.data), 0) sys.argv = make_argv(['base']) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 0)
def test_create_up(self): sys.argv = make_argv(["-f", "test-file"]) self.newCommand.run() files = os.walk(os.getcwd()).next()[2] files = [f for f in files if not f.find("test-file") == -1] files = [f for f in files if not f.find("up") == -1] self.assertTrue(len(files) == 1)
def test_ref_does_nothing_when_ref_doesnt_exist(self): AlterUtil.create_alters([1]) sys.argv = make_argv([str(10)]) try: self.upCommand.run() except MissingRefError: pass
def test_create_up(self): sys.argv = make_argv(['-f', 'test-file']) self.newCommand.run() files = os.walk(os.getcwd()).next()[2] files = [f for f in files if not f.find('test-file') == -1] files = [f for f in files if not f.find('up') == -1] self.assertTrue(len(files) == 1)
def test_stop_on_error(self): AlterUtil.create_alters([1, 'error', 2]) sys.argv = make_argv([]) try: self.upCommand.run() except AppliedAlterError: pass self.assertEqual(len(MemoryDb.data), 1)
def test_ref_undoes_all_alters_including_ref(self): AlterUtil.create_alters([1,2,3]) ids = AlterUtil.run_alters() self.assertEqual(len(MemoryDb.data), 3) sys.argv = make_argv([str(ids[1])]) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 1)
def test_ref_undoes_all_alters_including_ref(self): AlterUtil.create_alters([1, 2, 3]) ids = AlterUtil.run_alters() self.assertEqual(len(MemoryDb.data), 3) sys.argv = make_argv([str(ids[1])]) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 1)
def test_all_undoes_all_current_alters_when_alters(self): AlterUtil.create_alters([1]) AlterUtil.run_alters() self.assertEqual(len(MemoryDb.data), 1) sys.argv = make_argv(['all']) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 0)
def test_n_option_runs_down_given_number_of_alters(self): AlterUtil.create_alters([1, 2, 3, 4]) AlterUtil.run_alters() self.assertEqual(len(MemoryDb.data), 4) sys.argv = make_argv(['-n2']) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 2)
def test_base_undoes_none_when_one_alter(self): AlterUtil.create_alters([1]) AlterUtil.run_alters() self.assertEqual(len(MemoryDb.data), 1) sys.argv = make_argv(['base']) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 1)
def test_base_undoes_all_but_last_when_more_than_one(self): AlterUtil.create_alters([1, 2]) AlterUtil.run_alters() self.assertEqual(len(MemoryDb.data), 2) sys.argv = make_argv(['base']) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 1)
def test_ref_undoes_nothing_when_ref_doesnt_exist(self): AlterUtil.create_alters([1, 2, 3, 4]) AlterUtil.run_alters() self.assertEqual(len(MemoryDb.data), 4) sys.argv = make_argv([str(10)]) try: self.downCommand.run() except MissingRefError: pass self.assertEqual(len(MemoryDb.data), 4)
def help_test_missing_alter(self, search, error): AlterUtil.create_alters([1]) AlterUtil.run_alters() alter_files = ChainUtil.get_alter_files() self.assertEqual(len(alter_files), 2) # up and down os.remove([i for i in alter_files if search in i].pop()) try: sys.argv = make_argv([]) self.checkCommand.run() except error: pass
def test_no_arg_does_all_current_alters_when_none(self): self.assertEqual(len(MemoryDb.data), 0) sys.argv = make_argv([]) self.upCommand.run() self.assertEqual(len(MemoryDb.data), 0)
def test_create_files_without_name(self): sys.argv = make_argv([]) self.newCommand.run() files = os.walk(os.getcwd()).next()[2] files = [f for f in files if not f.find('sql') == -1] self.assertTrue(len(files) == 2)
def test_all_undoes_all_current_alters_when_none(self): self.assertEqual(len(MemoryDb.data), 0) sys.argv = make_argv(['all']) self.downCommand.run() self.assertEqual(len(MemoryDb.data), 0)
def test_order_reverse(self): id1, id2 = AlterUtil.create_alters([1, 2]) AlterUtil.run_alters() sys.argv = make_argv(['-r']) result = self.listCommand.run() self.assertEqual([id2, id1], result)
def test_continue_on_error_with_force(self): AlterUtil.create_alters([1, 'error', 2]) sys.argv = make_argv(['-f']) self.upCommand.run() self.assertEqual(len(MemoryDb.data), 3)
def test_no_backref_on_single_alter(self): sys.argv = make_argv(['-f', '1']) self.newCommand.run() chain_tail = ChainUtil.build_chain() self.assertTrue(chain_tail.backref is None)
def test_no_arg_does_all_current_alters_when_alters(self): AlterUtil.create_alters([1]) sys.argv = make_argv([]) self.upCommand.run() self.assertEqual(len(MemoryDb.data), 1)
def test_ref_does_all_alters_including_ref(self): id1, id2 = AlterUtil.create_alters([1,2]) sys.argv = make_argv([str(id1)]) self.upCommand.run() self.assertEqual(len(MemoryDb.data), 1)
def test_no_backref_on_single_alter(self): sys.argv = make_argv(["-f", "1"]) self.newCommand.run() chain_tail = ChainUtil.build_chain() self.assertTrue(chain_tail.backref is None)
def test_ref_does_all_alters_including_ref(self): id1, id2 = AlterUtil.create_alters([1, 2]) sys.argv = make_argv([str(id1)]) self.upCommand.run() self.assertEqual(len(MemoryDb.data), 1)
def test_create_files_without_name(self): sys.argv = make_argv([]) self.newCommand.run() files = os.walk(os.getcwd()).next()[2] files = [f for f in files if not f.find("sql") == -1] self.assertTrue(len(files) == 2)
def test_valid_chain(self): AlterUtil.create_alters([1, 2]) AlterUtil.run_alters() sys.argv = make_argv([]) self.checkCommand.run()