getting file size for all dict files to be downloaded. coming to be 400mb or so.
[worddb.git] / libs / dmigrations / tests / .svn / text-base / migration_db.py.svn-base
blob31c6c9e74a7c960db26865d6ed4e741b129b6f42
1 from common import *
2 from dmigrations.migration_db import MigrationDb
4 import os
6 class MigrationDbTest(TestCase):
7   def set_up(self):
8     self.mock_migrations_dir = os.path.join(os.path.dirname(__file__), "mock_migrations_dir")
10   def test_migrations_sorted_by_numbers_not_ascii(self):
11     db = MigrationDb(migrations=[
12       "04_blah",
13       "03_blah",
14       "002_bar",
15       "12_blah",
16       "01_foo",
17       "011_blah",
18     ])
19     self.assert_equal([
20         "01_foo",
21         "002_bar",
22         "03_blah",
23         "04_blah",
24         "011_blah",
25         "12_blah",
26       ], db.list()
27     )
29   def test_migrations_can_be_initialized_from_directory(self):
30     db = MigrationDb(directory=self.mock_migrations_dir)
31     db.warn = WarningsMocker()
32     
33     self.assert_equal([
34         "001_foo",
35         "002_bar",
36         "005_DEV_hello",
37         "009_one",
38         "09_two",
39       ], db.list()
40     )
42   def test_dups_and_missing_numbers_ok(self):
43     db = MigrationDb(migrations = [
44       "9_sweet",
45       "8_blah_one",
46       "7_blah",
47       "10_gah",
48       "8_blah_three",
49       "1_foo",
50       "8_blah_two",
51     ])
52     self.assert_equal([
53         "1_foo",
54         "7_blah",
55         "8_blah_one",
56         "8_blah_three",
57         "8_blah_two",
58         "9_sweet",
59         "10_gah",
60       ], db.list()
61     )
62     
63   def test_nonpy_and_nonnumber_are_ignored(self):
64     db = MigrationDb()
65     db.populate_migrations_from_ls(["1_foo.py", "1_bar.pyc", "4-ohhi.py", "-9_kitty.py", "1_bar.html", ".", ".boo", "..", "123.py.gz", "hello_45.py", "__init__.py", "___init__.pyc", "hello.py", "hello.pyc"])
66     self.assert_equal([
67          "1_foo",
68       ], db.list()
69     )
71   def test_dup_warnings(self):
72     db = MigrationDb()
73     db.warn = WarningsMocker()
74     db.populate_migrations_from_ls([
75       "17_foo.py",
76       "017_bar.py",
77       "0018_foo.py",
78       "00018_foo.py",
79       "180_hello.py",
80     ])
81     self.assert_equal(
82       [
83       u'There are multiple migrations with the same number 17: 017_bar, 17_foo',
84       u'There are multiple migrations with the same number 18: 00018_foo, 0018_foo'
85       ],
86       db.warn.warnings
87     )
89   def test_is_dev_migration(self):
90     db = MigrationDb()
91     self.assert_equal(False, db.is_dev_migration("1_foo"))
92     self.assert_equal(False, db.is_dev_migration("1DEV_foo"))
93     self.assert_equal(False, db.is_dev_migration("1_DEVELOPER_foo"))
95     self.assert_equal(True, db.is_dev_migration("1_DEV_foo"))
96     self.assert_equal(True, db.is_dev_migration("005_DEV_bar"))
97     self.assert_equal(True, db.is_dev_migration("1__DEV__foo"))
99   def test_load_migration_object(self):
100     db = MigrationDb(directory=self.mock_migrations_dir)
101     db.warn = WarningsMocker()
103     for name in ['001_foo', '0001', '001', '01', '1', 1]:
104       self.assert_attrs(db.load_migration_object(name),
105         name = '001_foo',
106         dev = False,
107         sql_up = "INSERT INTO mock VALUES (1)",
108       )
110     for name in ['002_bar', '0002', '002', '02', '2', 2]:
111       self.assert_attrs(db.load_migration_object(name),
112         name = '002_bar',
113         dev = False,
114         sql_up = "INSERT INTO mock VALUES (2)",
115       )
117     for name in ['005_DEV_hello', '0005', '005', '05', '5', 5]:
118       self.assert_attrs(db.load_migration_object(name),
119         name = '005_DEV_hello',
120         dev = True,
121         sql_up = "INSERT INTO mock VALUES (5)",
122       )
124     for name in ['3', '02_foo', '2_foo', 3]:
125       self.assert_raises(NoSuchMigrationError, lambda: db.load_migration_object(name))
127   def test_load_migration_object_with_dups(self):
128     db = MigrationDb(directory=self.mock_migrations_dir)
129     db.warn = WarningsMocker()
131     self.assert_attrs(db.load_migration_object('009_one'),
132       name = '009_one',
133       dev = False,
134       sql_up = "INSERT INTO mock VALUES (9, 1)",
135     )
137     self.assert_attrs(db.load_migration_object('09_two'),
138       name = '09_two',
139       dev = False,
140       sql_up = "INSERT INTO mock VALUES (9, 2)",
141     )
143     for name in ['0009', '009', '09', '9', 9]:
144       self.assert_raises(AmbiguousMigrationNameError, lambda: db.load_migration_object(name))
146   def test_find_unique_migration_by_number(self):
147     db = MigrationDb(directory=self.mock_migrations_dir)
148     db.warn = WarningsMocker()
150     self.assert_equal("001_foo", db.find_unique_migration_by_number(1))
151     self.assert_equal("002_bar", db.find_unique_migration_by_number(2))
152     self.assert_equal(None, db.find_unique_migration_by_number(3))
153     self.assert_raises(AmbiguousMigrationNameError, lambda: db.find_unique_migration_by_number(9))
155   def test_migration_path(self):
156     db = MigrationDb(directory=self.mock_migrations_dir)
157     db.warn = WarningsMocker()
158     
159     self.assert_equal(self.mock_migrations_dir + '/010_foo.py', db.migration_path('foo'))