Пример #1
0
 def setUp(self):
     EnvironmentUtil.setup_fresh_test_env()
     self.context = CommandContext.via({'type': 'memory-db'})
     self.downCommand = DownCommand(self.context)
     self.newCommand = NewCommand(self.context)
     self.upCommand = UpCommand(self.context)
     self.checkCommand = CheckCommand(self.context)
Пример #2
0
 def setUp(self):
     EnvironmentUtil.setup_fresh_test_env()
     self.context = CommandContext.via({
       'type': 'memory-db'})
     self.downCommand = DownCommand(self.context)
Пример #3
0
class DownTest(unittest.TestCase):

    def setUp(self):
        EnvironmentUtil.setup_fresh_test_env()
        self.context = CommandContext.via({
          'type': 'memory-db'})
        self.downCommand = DownCommand(self.context)

    def tearDown(self):
        EnvironmentUtil.teardown_fresh_test_env()

    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_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_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_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 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_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_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_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)
Пример #4
0
class DownTest(unittest.TestCase):
    def setUp(self):
        EnvironmentUtil.setup_fresh_test_env()
        self.context = CommandContext.via({'type': 'memory-db'})
        self.downCommand = DownCommand(self.context)

    def tearDown(self):
        EnvironmentUtil.teardown_fresh_test_env()

    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_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_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_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 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_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_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_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)