6
from nfss import db_migrate as dbm
9
class DBMigrationTests(unittest.TestCase):
11
def test_get_settings_returns_dict_on_no_file(self):
12
with self.assertRaises(IOError):
13
dbm.get_db_settings('/this/path/does/not/exist')
15
def test_get_settings_returns_dict_on_bad_json(self):
16
with tempfile.NamedTemporaryFile(mode='w') as f:
20
with self.assertRaises(ValueError):
21
dbm.get_db_settings(f.name)
23
def test_get_settings_works_on_example_json(self):
24
with tempfile.NamedTemporaryFile(mode='w') as f:
26
'{"database": "ci-airline-nfss-restish", '
27
'"allowed-units": "ci-airline-nfss-restish/0", '
28
'"state": "standalone", '
29
'"schema_user": "db_2_ci_airline_nfss_restish_schema", '
30
'"schema_password": "secret", '
31
'"private-address": "10.0.3.236", '
32
'"host": "10.0.3.236", '
33
'"user": "db_2_ci_airline_nfss_restish", '
34
'"password": "secret", '
40
"database": "ci-airline-nfss-restish",
41
"allowed-units": "ci-airline-nfss-restish/0",
42
"state": "standalone",
43
"schema_user": "db_2_ci_airline_nfss_restish_schema",
44
"schema_password": "secret",
45
"private-address": "10.0.3.236",
47
"user": "db_2_ci_airline_nfss_restish",
53
dbm.get_db_settings(f.name)
56
def test_get_maximum_version_works_with_single_patch(self):
57
with patch.object(dbm, 'get_all_patch_paths') as p:
58
p.return_value = ['000-foo.sql']
60
self.assertEqual(0, dbm.get_maximum_version())
62
def test_get_maximum_version_works_with_many_patches(self):
63
with patch.object(dbm, 'get_all_patch_paths') as p:
64
p.return_value = ['000-foo.sql', '001-bar.sql', '002-baz.sql']
66
self.assertEqual(2, dbm.get_maximum_version())