Example #1
0
 def test_should_return_feedback_to_user_when_no_have_migration_to_run(
         self):
     Version().set_current("0.0.5")
     output = shell("pymigration -u")
     self.assertEqual(
         "Running command: pymigration -u\nNo migrations need to be executed, already in 0.0.5 version.",
         output)
Example #2
0
def pymigration():

    parser = ArgumentParser(description="Parameters to migrate.")
    parser.add_argument("-u", "--up", dest="up", default=False, action="store_true",
                      help="Execute python methods to upgrade schema of system.")

    parser.add_argument("--no-exec", default=True, dest="execute", action="store_false",
                        help="If you want only see the list of migrantions command.")

    parser.add_argument("-d", "--down", dest="down", default=False, action="store_true",
                      help="Execute python methods to downgrade schema of system.")

    parser.add_argument("-c", "--current-version", dest="current_version", default=False,
                      help="Version of actual migration.", action="store_true")

    parser.add_argument("-v", "--version", dest="version", default=False,
                      help="Displays pymigration's version and exit.", action="store_true")

    parser.add_argument("-t", "--to", dest="version_to", default=None,
                    help="Migrate to specific version .")

    args = parser.parse_args()


    migrations = DiscovererMigration(**vars(args))
    terminal_message = TerminalMessages(migrations, **vars(args))

    if args.version:
        print version

    if args.down:
        migrations = list(migrations.down_migrations())
        try:
            if migrations:
                for migration in migrations:
                    migration.down()
                    terminal_message.make_message("down", migration)
            else:
                print "No migrations need to be executed, already in %s version." % Version().get_current()
        except Exception, e:
            terminal_message.error_message("down", migration, e)
            sys.exit()
        if args.execute:
            Version().set_current("0")
Example #3
0
    def test_should_use_command_to_version_and_raise_exception(self):
        Version().set_current("0.0.3")
        output = shell("pymigration --to 0.0.4")
        self.assertTextEqual(
            """Running command: pymigration --to 0.0.4
\x1b[31m
0.0.4           - exception.py
                  Test for raise a exception
                  up - Starting exeception

integer division or modulo by zero\x1b[0m""", output)
Example #4
0
    def test_should_use_command_down_and_raise_exception(self):
        Version().set_current("0.0.4")
        output = shell("pymigration -d")
        self.assertTextEqual(
            """Running command: pymigration -d
\x1b[31m
0.0.4           - exception.py
                  Test for raise a exception
                  down - Rollback and raise exception

integer division or modulo by zero\x1b[0m""", output)
Example #5
0
 def tearDown(self):
     Version().set_current("0.0.1")
Example #6
0
 def setUp(self):
     Version().set_current("0.0.1")
Example #7
0
 def setUp(self):
     self.version = Version()
Example #8
0
class TestVersion(UnitTestCase):

    def setUp(self):
        self.version = Version()

    def test_should_get_current_version_in_configuration(self):
        self.assertEqual("0.0.1", self.version.get_current())

    def test_should_get_current_version_in_current_version_dot_txt(self):
        original_current_version = pymigrations.conf.current_version
        del pymigrations.conf.current_version
        pymigrations.conf.folder = "%s/pymigrations" % pymigrations.conf.abs_path
        self.assertEqual("0.0.1", self.version.get_current())
        pymigrations.conf.current_version = original_current_version

    def test_should_get_method_set_the_current_version_in_configuration(self):
        original_current_version = pymigrations.conf.current_version()
        self.version.set_current("0.0.2")
        self.assertEqual("0.0.2", self.version.get_current())
        self.version.set_current(original_current_version)

    def test_should_set_the_current_version_in_dot_txt(self):
        original_set_current_version = pymigrations.conf.set_current_version
        original_current_version = pymigrations.conf.current_version
        del pymigrations.conf.current_version
        del pymigrations.conf.set_current_version
        old_version = self.version.get_current()
        self.version.set_current(version="0.0.3")
        new_version = self.version.get_current()

        self.assertNotEqual(new_version, old_version)
        self.version.set_current(version="0.0.1")
        pymigrations.conf.current_version = original_current_version
        pymigrations.conf.current_version = original_set_current_version
Example #9
0
                print "No migrations need to be executed, already in %s version." % Version().get_current()
        except Exception, e:
            terminal_message.error_message("down", migration, e)
            sys.exit()
        if args.execute:
            Version().set_current("0")

    if args.up:
        migrations = list(migrations.up_migrations())
        try:
            if migrations:
                for migration in migrations:
                    migration.up()
                    terminal_message.make_message("up", migration)
            else:
                print "No migrations need to be executed, already in %s version." % Version().get_current()
        except Exception, e:
            terminal_message.error_message("up", migration, e)

    if args.current_version:
        terminal_message.current_version()

    if args.version_to:
        for migration in migrations.to_migrations():
            if migrations.is_up():
                try:
                    migration.up()
                    terminal_message.make_message("up", migration)
                except Exception, e:
                    terminal_message.error_message("up", migration, e)
                    sys.exit()
Example #10
0
 def setUp(self):
     self.version = Version()
Example #11
0
class TestVersion(UnitTestCase):
    def setUp(self):
        self.version = Version()

    def test_should_get_current_version_in_configuration(self):
        self.assertEqual("0.0.1", self.version.get_current())

    def test_should_get_current_version_in_current_version_dot_txt(self):
        original_current_version = pymigrations.conf.current_version
        del pymigrations.conf.current_version
        pymigrations.conf.folder = "%s/pymigrations" % pymigrations.conf.abs_path
        self.assertEqual("0.0.1", self.version.get_current())
        pymigrations.conf.current_version = original_current_version

    def test_should_get_method_set_the_current_version_in_configuration(self):
        original_current_version = pymigrations.conf.current_version()
        self.version.set_current("0.0.2")
        self.assertEqual("0.0.2", self.version.get_current())
        self.version.set_current(original_current_version)

    def test_should_set_the_current_version_in_dot_txt(self):
        original_set_current_version = pymigrations.conf.set_current_version
        original_current_version = pymigrations.conf.current_version
        del pymigrations.conf.current_version
        del pymigrations.conf.set_current_version
        old_version = self.version.get_current()
        self.version.set_current(version="0.0.3")
        new_version = self.version.get_current()

        self.assertNotEqual(new_version, old_version)
        self.version.set_current(version="0.0.1")
        pymigrations.conf.current_version = original_current_version
        pymigrations.conf.current_version = original_set_current_version