From 3462a9d6089ae5de8d71ded847f64480f5642fe1 Mon Sep 17 00:00:00 2001 From: Gunnar Schaefer Date: Wed, 31 Jan 2018 15:46:07 -0600 Subject: [PATCH] Rename database.py --- bin/{database.py => db_upgrade.py} | 0 .../integration_tests/python/test_upgrades.py | 4 +-- tests/unit_tests/python/test_db_upgrade.py | 32 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) rename bin/{database.py => db_upgrade.py} (100%) diff --git a/bin/database.py b/bin/db_upgrade.py similarity index 100% rename from bin/database.py rename to bin/db_upgrade.py diff --git a/tests/integration_tests/python/test_upgrades.py b/tests/integration_tests/python/test_upgrades.py index 748986e58..212170250 100644 --- a/tests/integration_tests/python/test_upgrades.py +++ b/tests/integration_tests/python/test_upgrades.py @@ -9,8 +9,8 @@ def database(mocker): bin_path = os.path.join(os.getcwd(), 'bin') mocker.patch('sys.path', [bin_path] + sys.path) - import database - return database + import db_upgrade + return db_upgrade def test_42(data_builder, api_db, as_admin, database): diff --git a/tests/unit_tests/python/test_db_upgrade.py b/tests/unit_tests/python/test_db_upgrade.py index dd9988480..9cb793559 100644 --- a/tests/unit_tests/python/test_db_upgrade.py +++ b/tests/unit_tests/python/test_db_upgrade.py @@ -6,51 +6,51 @@ bin_path = os.path.join(os.getcwd(), "bin") sys.path.insert(0, bin_path) -import database +import db_upgrade from api import config -CDV = database.CURRENT_DATABASE_VERSION +CDV = db_upgrade.CURRENT_DATABASE_VERSION def test_all_upgrade_scripts_exist(): for i in range(1, CDV): script_name = 'upgrade_to_{}'.format(i) - assert hasattr(database, script_name) + assert hasattr(db_upgrade, script_name) def test_CDV_was_bumped(): script_name = 'upgrade_to_{}'.format(CDV+1) - assert hasattr(database, script_name) is False + assert hasattr(db_upgrade, script_name) is False @patch('api.config.get_version', Mock(return_value={'database': 5})) def test_get_db_version_from_config(): - assert database.get_db_version() == 5 + assert db_upgrade.get_db_version() == 5 @pytest.fixture(scope='function') -def database_mock_setup(): +def db_upgrade_mock_setup(): setattr(config.db.singletons, 'update_one', Mock()) for i in range(1, CDV): script_name = 'upgrade_to_{}'.format(i) - setattr(database, script_name, Mock()) + setattr(db_upgrade, script_name, Mock()) -@patch('database.get_db_version', Mock(return_value=0)) -def test_all_upgrade_scripts_ran(database_mock_setup): +@patch('db_upgrade.get_db_version', Mock(return_value=0)) +def test_all_upgrade_scripts_ran(db_upgrade_mock_setup): with pytest.raises(SystemExit): - database.upgrade_schema() + db_upgrade.upgrade_schema() for i in range(1, CDV): script_name = 'upgrade_to_{}'.format(i) - assert getattr(database, script_name).called + assert getattr(db_upgrade, script_name).called -@patch('database.get_db_version', Mock(return_value=CDV-4)) -def test_necessary_upgrade_scripts_ran(database_mock_setup): +@patch('db_upgrade.get_db_version', Mock(return_value=CDV-4)) +def test_necessary_upgrade_scripts_ran(db_upgrade_mock_setup): with pytest.raises(SystemExit): - database.upgrade_schema() + db_upgrade.upgrade_schema() # Assert the necessary scripts were called for i in range(CDV-3, CDV): script_name = 'upgrade_to_{}'.format(i) - assert getattr(database, script_name).called + assert getattr(db_upgrade, script_name).called # But not the scripts before it for i in range(1, CDV-4): script_name = 'upgrade_to_{}'.format(i) - assert getattr(database, script_name).called is False + assert getattr(db_upgrade, script_name).called is False