1 from dmigrations.tests.common import *
2 from dmigrations.migration_loader import *
6 test_migrations_dir = os.path.join(
7 os.path.realpath(os.path.dirname(__file__)), 'test_migrations'
10 class MigrationLoaderTest(TestCase):
11 def test_valid_migration(self):
12 "Valid migrations should load correctly"
13 path = os.path.join(test_migrations_dir, 'valid_migration.py')
14 migration = load_migration_from_path(path)
15 self.assert_(isinstance(migration, BaseMigration))
17 def test_valid_custom_migration(self):
18 "Valid migrations using a custom subclass should load correctly"
19 path = os.path.join(test_migrations_dir, 'valid_custom_migration.py')
20 migration = load_migration_from_path(path)
21 self.assert_(isinstance(migration, BaseMigration))
23 def test_invalid_no_migrations(self):
24 "Raise error if no migration found in a file"
25 path = os.path.join(test_migrations_dir, 'invalid_no_migrations.py')
26 self.assertRaises(BadMigrationError, load_migration_from_path, path)
28 def test_invalid_migration_not_subclass(self):
29 "Raise error if discovered migration does not subclass BaseMigration"
30 path = os.path.join(test_migrations_dir, 'invalid_migration_not_subclass.py')
31 self.assertRaises(BadMigrationError, load_migration_from_path, path)
33 def test_migration_knows_file(self):
34 "A migration should know which file it was loaded from"
35 path = os.path.join(test_migrations_dir, 'valid_migration.py')
36 migration = load_migration_from_path(path)
37 self.assert_equal(migration.filepath, path)
38 self.assert_equal(migration.name, 'valid_migration')