Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
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)
Example #7
0
 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
Example #8
0
 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
Example #9
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)
Example #10
0
    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)
Example #11
0
 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)
Example #12
0
 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)
Example #13
0
    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)
Example #14
0
    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)
Example #15
0
    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)
Example #16
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)
Example #17
0
    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)
Example #18
0
    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)
Example #19
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)
Example #20
0
    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)
Example #21
0
    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)
Example #22
0
    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)
Example #23
0
    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)
Example #24
0
    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)
Example #25
0
    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
Example #26
0
    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
Example #27
0
 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)
Example #28
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)
Example #29
0
 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)
Example #30
0
 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)
Example #31
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)
Example #32
0
 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)
Example #33
0
    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)
Example #34
0
 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)
Example #35
0
 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)
Example #36
0
 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)
Example #37
0
    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)
Example #38
0
 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)
Example #39
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)
Example #40
0
 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)
Example #41
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)
Example #42
0
 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)
Example #43
0
 def test_valid_chain(self):
     AlterUtil.create_alters([1, 2])
     AlterUtil.run_alters()
     sys.argv = make_argv([])
     self.checkCommand.run()
Example #44
0
 def test_valid_chain(self):
     AlterUtil.create_alters([1, 2])
     AlterUtil.run_alters()
     sys.argv = make_argv([])
     self.checkCommand.run()