Esempio n. 1
0
 def test_it_should_get_all_migrations_in_dir(self):
     db_migrate = SimpleDBMigrate(self.config)
     migrations = db_migrate.get_all_migrations()
     self.assertNotEqual(None, migrations)
     self.assertEqual(len(self.test_migration_files), len(migrations))
     for migration in migrations:
         self.assertTrue(migration.abspath in self.test_migration_files)
 def test_it_should_get_all_migrations_in_dir(self):
     db_migrate = SimpleDBMigrate(self.config)
     migrations = db_migrate.get_all_migrations()
     self.assertNotEqual(None, migrations)
     self.assertEqual(len(self.test_migration_files), len(migrations))
     for migration in migrations:
         self.assertTrue(migration.abspath in self.test_migration_files)
Esempio n. 3
0
 def test_it_should_get_migration_from_version_number(self):
     db_migrate = SimpleDBMigrate(self.config)
     migration = db_migrate.get_migration_from_version_number(
         '20090214115100')
     self.assertEqual('20090214115100', migration.version)
     self.assertEqual('20090214115100_01_test_migration.migration',
                      migration.file_name)
    def test_it_should_not_read_files_again_on_subsequent_calls(self, is_file_name_valid_mock):
        db_migrate = SimpleDBMigrate(self.config)
        db_migrate.get_all_migrations()
        self.assertEqual((len(self.test_migration_files) * 2), is_file_name_valid_mock.call_count)

        #make the second call
        db_migrate.get_all_migrations()
        self.assertEqual((len(self.test_migration_files) * 2), is_file_name_valid_mock.call_count)
Esempio n. 5
0
    def test_it_should_get_all_migration_versions_available(self):
        db_migrate = SimpleDBMigrate(self.config)
        migrations = db_migrate.get_all_migrations()
        expected_versions = []
        for migration in migrations:
            expected_versions.append(migration.version)

        all_versions = db_migrate.get_all_migration_versions()

        self.assertEqual(len(all_versions), len(expected_versions))
        for version in all_versions:
            self.assertTrue(version in expected_versions)
    def test_it_should_get_all_migration_versions_available(self):
        db_migrate = SimpleDBMigrate(self.config)
        migrations = db_migrate.get_all_migrations()
        expected_versions = []
        for migration in migrations:
            expected_versions.append(migration.version)

        all_versions = db_migrate.get_all_migration_versions()

        self.assertEqual(len(all_versions), len(expected_versions))
        for version in all_versions:
            self.assertTrue(version in expected_versions)
Esempio n. 7
0
    def test_it_should_get_only_valid_migrations_in_dir(self, is_file_name_valid_mock):
        def side_effect(args):
            return args != '20090214115100_01_test_migration.migration'
        is_file_name_valid_mock.side_effect = side_effect

        db_migrate = SimpleDBMigrate(self.config)
        migrations = db_migrate.get_all_migrations()
        self.assertEqual(len(self.test_migration_files) - 1, len(migrations))
        for migration in migrations:
            self.assertTrue(migration.abspath in self.test_migration_files)
            self.assertFalse(migration.file_name == '20090214115100_01_test_migration.migration')

        self.assertEqual((len(self.test_migration_files) * 2) - 1, is_file_name_valid_mock.call_count)
    def test_it_should_get_only_valid_migrations_in_dir(self, is_file_name_valid_mock):
        def side_effect(args):
            return args != '20090214115100_01_test_migration.migration'
        is_file_name_valid_mock.side_effect = side_effect

        db_migrate = SimpleDBMigrate(self.config)
        migrations = db_migrate.get_all_migrations()
        self.assertEqual(len(self.test_migration_files) - 1, len(migrations))
        for migration in migrations:
            self.assertTrue(migration.abspath in self.test_migration_files)
            self.assertFalse(migration.file_name == '20090214115100_01_test_migration.migration')

        self.assertEqual((len(self.test_migration_files) * 2) - 1, is_file_name_valid_mock.call_count)
Esempio n. 9
0
 def test_it_should_raise_error_if_has_an_invalid_dir_on_migrations_dir_list(
         self):
     self.config.update("database_migrations_dir",
                        ['invalid_path_it_does_not_exist'])
     db_migrate = SimpleDBMigrate(self.config)
     self.assertRaisesWithMessage(
         Exception, "directory not found ('%s')" %
         os.path.abspath('invalid_path_it_does_not_exist'),
         db_migrate.get_all_migrations)
Esempio n. 10
0
    def test_it_should_not_read_files_again_on_subsequent_calls(self, is_file_name_valid_mock):
        db_migrate = SimpleDBMigrate(self.config)
        db_migrate.get_all_migrations()
        self.assertEqual((len(self.test_migration_files) * 2), is_file_name_valid_mock.call_count)

        #make the second call
        db_migrate.get_all_migrations()
        self.assertEqual((len(self.test_migration_files) * 2), is_file_name_valid_mock.call_count)
 def test_it_should_get_migration_from_version_number(self):
     db_migrate = SimpleDBMigrate(self.config)
     migration = db_migrate.get_migration_from_version_number('20090214115100')
     self.assertEqual('20090214115100', migration.version)
     self.assertEqual('20090214115100_01_test_migration.migration', migration.file_name)
 def test_it_should_get_the_latest_version_available(self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertEqual('20090214115600', db_migrate.latest_version_available())
 def test_it_should_not_inform_that_migration_version_exists_just_matching_the_beggining_of_version_number(self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertFalse(db_migrate.check_if_version_exists('2009'))
 def test_it_should_use_get_all_migrations_versions_method_to_check_if_migration_version_exists(self, get_all_migration_versions_mock):
     db_migrate = SimpleDBMigrate(self.config)
     db_migrate.check_if_version_exists('20090214115100')
     self.assertEqual(1, get_all_migration_versions_mock.call_count)
Esempio n. 15
0
 def test_it_should_not_inform_that_migration_version_exists_just_matching_the_beggining_of_version_number(
         self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertFalse(db_migrate.check_if_version_exists('2009'))
Esempio n. 16
0
 def test_it_should_raise_error_if_do_not_have_any_valid_migration(
         self, is_file_name_valid_mock):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertRaisesWithMessage(Exception, "no migration files found",
                                  db_migrate.get_all_migrations)
 def test_it_should_use_get_all_migrations_method_to_get_all_migration_versions_available(self, get_all_migrations_mock):
     db_migrate = SimpleDBMigrate(self.config)
     db_migrate.get_all_migration_versions()
     self.assertEqual(1, get_all_migrations_mock.call_count)
Esempio n. 18
0
 def test_it_should_use_get_all_migrations_versions_method_to_get_migration_from_version_number(
         self, get_all_migrations_mock):
     db_migrate = SimpleDBMigrate(self.config)
     db_migrate.get_migration_from_version_number('20090214115100')
     self.assertEqual(1, get_all_migrations_mock.call_count)
Esempio n. 19
0
 def test_it_should_not_get_migration_from_invalid_version_number(self):
     db_migrate = SimpleDBMigrate(self.config)
     migration = db_migrate.get_migration_from_version_number(
         '***invalid***')
     self.assertEqual(None, migration)
Esempio n. 20
0
 def test_it_should_check_if_migration_version_exists(self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertTrue(db_migrate.check_if_version_exists('20090214115100'))
     self.assertFalse(db_migrate.check_if_version_exists('19000101000000'))
Esempio n. 21
0
 def test_it_should_use_get_all_migrations_versions_method_to_get_the_latest_version_available(
         self, get_all_migrations_mock):
     db_migrate = SimpleDBMigrate(self.config)
     db_migrate.latest_version_available()
     self.assertEqual(1, get_all_migrations_mock.call_count)
Esempio n. 22
0
 def test_it_should_get_the_latest_version_available(self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertEqual('20090214115600',
                      db_migrate.latest_version_available())
 def test_it_should_not_get_migration_from_invalid_version_number(self):
     db_migrate = SimpleDBMigrate(self.config)
     migration = db_migrate.get_migration_from_version_number('***invalid***')
     self.assertEqual(None, migration)
 def test_it_should_use_get_all_migrations_versions_method_to_get_migration_from_version_number(self, get_all_migrations_mock):
     db_migrate = SimpleDBMigrate(self.config)
     db_migrate.get_migration_from_version_number('20090214115100')
     self.assertEqual(1, get_all_migrations_mock.call_count)
Esempio n. 25
0
 def test_it_should_use_utf8_as_default_script_encoding_from_configuration(
         self):
     self.config.remove('database_script_encoding')
     db_migrate = SimpleDBMigrate(self.config)
     self.assertEqual('utf-8', db_migrate._script_encoding)
Esempio n. 26
0
 def test_it_should_get_all_migration_versions_up_to_a_version(self):
     db_migrate = SimpleDBMigrate(self.config)
     migration_versions = db_migrate.get_all_migration_versions_up_to(
         '20090214115200')
     self.assertEqual(1, len(migration_versions))
     self.assertEqual('20090214115100', migration_versions[0])
 def test_it_should_check_if_migration_version_exists(self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertTrue(db_migrate.check_if_version_exists('20090214115100'))
     self.assertFalse(db_migrate.check_if_version_exists('19000101000000'))
Esempio n. 28
0
 def test_it_should_use_migrations_dir_from_configuration(self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertEqual(self.config.get("database_migrations_dir"),
                      db_migrate._migrations_dir)
Esempio n. 29
0
 def test_it_should_use_get_all_migrations_versions_method_to_check_if_migration_version_exists(
         self, get_all_migration_versions_mock):
     db_migrate = SimpleDBMigrate(self.config)
     db_migrate.check_if_version_exists('20090214115100')
     self.assertEqual(1, get_all_migration_versions_mock.call_count)
 def test_it_should_get_all_migration_versions_up_to_a_version(self):
     db_migrate = SimpleDBMigrate(self.config)
     migration_versions = db_migrate.get_all_migration_versions_up_to('20090214115200')
     self.assertEqual(1, len(migration_versions))
     self.assertEqual('20090214115100', migration_versions[0])
Esempio n. 31
0
 def test_it_should_use_script_encoding_from_configuration(self):
     db_migrate = SimpleDBMigrate(self.config)
     self.assertEqual(self.config.get('database_script_encoding'),
                      db_migrate._script_encoding)