From 0c5bbeff866f5917736a743767421c3f8b2c4820 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: May 11 2018 14:54:05 +0000 Subject: Always use default configuration when running tests Sets TEST=true implicitly when executing tests in which case default/example configuration file is always used. --- diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..8e09845 --- /dev/null +++ b/conftest.py @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0+ + +import pytest + + +@pytest.fixture(autouse=True) +def set_environment_variable(monkeypatch): + monkeypatch.setenv('TEST', 'true') diff --git a/docs/dev-guide.rst b/docs/dev-guide.rst index 8b6a4d8..d3ea10f 100644 --- a/docs/dev-guide.rst +++ b/docs/dev-guide.rst @@ -39,7 +39,7 @@ the following command: .. code-block:: console - $ TEST=true py.test greenwave/tests/ + $ py.test greenwave/tests/ There are also functional tests in the :file:`functional-tests` directory. The functional tests will start their own copy of the `ResultsDB`_, `WaiverDB`_, @@ -48,7 +48,7 @@ functional tests like this: .. code-block:: console - $ TEST=true PYTHONPATH=. py.test functional-tests/ + $ PYTHONPATH=. py.test functional-tests/ The functional tests assume you have ResultsDB and WaiverDB git checkouts in :file:`../resultsdb` and :file:`../waiverdb` respectively. You can tell it to diff --git a/functional-tests/conftest.py b/functional-tests/conftest.py index 427a378..5d5c499 100644 --- a/functional-tests/conftest.py +++ b/functional-tests/conftest.py @@ -66,7 +66,6 @@ def resultsdb_server(tmpdir_factory): """ % dbname)) env = dict(os.environ, PYTHONPATH=resultsdb_source, - TEST='true', RESULTSDB_CONFIG=settings_file.strpath) # Create and populate the database drop_and_create_database(dbname) @@ -104,7 +103,6 @@ def waiverdb_server(tmpdir_factory): """ % dbname)) env = dict(os.environ, PYTHONPATH=waiverdb_source, - TEST='true', WAIVERDB_CONFIG=settings_file.strpath) # Create and populate the database drop_and_create_database(dbname) @@ -167,7 +165,6 @@ def greenwave_server(tmpdir_factory, resultsdb_server, waiverdb_server, greenwav """ % greenwave_cache_config)) env = dict(os.environ, PYTHONPATH='.', - TEST='true', GREENWAVE_CONFIG=settings_file.strpath) p = subprocess.Popen(['gunicorn', '--bind=127.0.0.1:5005', diff --git a/functional-tests/consumers/test_resultsdb.py b/functional-tests/consumers/test_resultsdb.py index 742d8cf..d8b4ab3 100644 --- a/functional-tests/consumers/test_resultsdb.py +++ b/functional-tests/consumers/test_resultsdb.py @@ -11,8 +11,7 @@ from greenwave.consumers import resultsdb @mock.patch('greenwave.consumers.resultsdb.fedmsg.publish') def test_consume_new_result( mock_fedmsg, load_config, requests_session, greenwave_server, - testdatabuilder, monkeypatch): - monkeypatch.setenv('TEST', 'true') + testdatabuilder): load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} nvr = testdatabuilder.unique_nvr() result = testdatabuilder.create_result(item=nvr, @@ -128,8 +127,7 @@ def test_consume_new_result( @mock.patch('greenwave.consumers.resultsdb.fedmsg.publish') def test_no_message_for_unchanged_decision( mock_fedmsg, load_config, requests_session, greenwave_server, - testdatabuilder, monkeypatch): - monkeypatch.setenv('TEST', 'true') + testdatabuilder): load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} nvr = testdatabuilder.unique_nvr() # One result gets the decision in a certain state. @@ -175,9 +173,8 @@ def test_no_message_for_unchanged_decision( @mock.patch('greenwave.consumers.resultsdb.fedmsg.publish') def test_invalidate_new_result_with_mocked_cache( mock_fedmsg, load_config, requests_session, greenwave_server, - testdatabuilder, monkeypatch): + testdatabuilder): """ Consume a result, and ensure that `delete` is called. """ - monkeypatch.setenv('TEST', 'true') load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} nvr = testdatabuilder.unique_nvr() result = testdatabuilder.create_result( @@ -221,8 +218,7 @@ def test_invalidate_new_result_with_mocked_cache( @mock.patch('greenwave.consumers.resultsdb.fedmsg.publish') def test_invalidate_new_result_with_real_cache( mock_fedmsg, load_config, requests_session, greenwave_server, - testdatabuilder, monkeypatch, greenwave_cache_config): - monkeypatch.setenv('TEST', 'true') + testdatabuilder, greenwave_cache_config): load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} nvr = testdatabuilder.unique_nvr() for testcase_name in ['dist.rpmdeplint', 'dist.upgradepath', 'dist.abicheck']: @@ -302,9 +298,8 @@ def test_invalidate_new_result_with_real_cache( @mock.patch('greenwave.consumers.resultsdb.fedmsg.publish') def test_invalidate_new_result_with_no_preexisting_cache( mock_fedmsg, load_config, requests_session, greenwave_server, - testdatabuilder, monkeypatch): + testdatabuilder): """ Ensure that invalidating an unknown value is sane. """ - monkeypatch.setenv('TEST', 'true') load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} nvr = testdatabuilder.unique_nvr() result = testdatabuilder.create_result( @@ -346,8 +341,7 @@ def test_invalidate_new_result_with_no_preexisting_cache( @mock.patch('greenwave.consumers.resultsdb.fedmsg.publish') def test_consume_compose_id_result( mock_fedmsg, load_config, requests_session, greenwave_server, - testdatabuilder, monkeypatch): - monkeypatch.setenv('TEST', 'true') + testdatabuilder): load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} compose_id = testdatabuilder.unique_compose_id() result = testdatabuilder.create_compose_result( @@ -415,14 +409,13 @@ def test_consume_compose_id_result( @mock.patch('greenwave.consumers.resultsdb.fedmsg.publish') def test_consume_legacy_result( mock_fedmsg, load_config, requests_session, greenwave_server, - testdatabuilder, monkeypatch): + testdatabuilder): """ Test that we can still handle the old legacy "taskotron" format. We should be using resultsdb.result.new everywhere now, but we also need to be able to handle this taskotron format for the transition. """ - monkeypatch.setenv('TEST', 'true') load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} nvr = testdatabuilder.unique_nvr() result = testdatabuilder.create_result(item=nvr, diff --git a/functional-tests/consumers/test_waiverdb.py b/functional-tests/consumers/test_waiverdb.py index b49761a..18feaff 100644 --- a/functional-tests/consumers/test_waiverdb.py +++ b/functional-tests/consumers/test_waiverdb.py @@ -16,8 +16,7 @@ TASKTRON_RELEASE_CRITICAL_TASKS = [ @mock.patch('greenwave.consumers.resultsdb.fedmsg.config.load_config') @mock.patch('greenwave.consumers.waiverdb.fedmsg.publish') def test_consume_new_waiver( - mock_fedmsg, load_config, requests_session, greenwave_server, testdatabuilder, monkeypatch): - monkeypatch.setenv('TEST', 'true') + mock_fedmsg, load_config, requests_session, greenwave_server, testdatabuilder): load_config.return_value = {'greenwave_api_url': greenwave_server + 'api/v1.0'} nvr = testdatabuilder.unique_nvr() result = testdatabuilder.create_result(item=nvr, diff --git a/greenwave.spec b/greenwave.spec index f235c4b..aa8cc41 100644 --- a/greenwave.spec +++ b/greenwave.spec @@ -73,7 +73,7 @@ DEV=true GREENWAVE_CONFIG=$(pwd)/conf/settings.py.example make -C docs SPHINXOPT %check export PYTHONPATH=%{buildroot}/%{python2_sitelib} -TEST=true GREENWAVE_CONFIG=$(pwd)/conf/settings.py.example py.test greenwave/tests/ +GREENWAVE_CONFIG=$(pwd)/conf/settings.py.example py.test greenwave/tests/ %files %license COPYING diff --git a/greenwave/utils.py b/greenwave/utils.py index efb001e..424d96a 100644 --- a/greenwave/utils.py +++ b/greenwave/utils.py @@ -65,14 +65,16 @@ def load_config(config_obj=None): # Load default config, then override that with a config file config = Config(__name__) if config_obj is None: - if os.getenv('DEV') == 'true': - config_obj = 'greenwave.config.DevelopmentConfig' - elif os.getenv('TEST') == 'true': + if os.getenv('TEST') == 'true': config_obj = 'greenwave.config.TestingConfig' + elif os.getenv('DEV') == 'true': + config_obj = 'greenwave.config.DevelopmentConfig' else: config_obj = 'greenwave.config.ProductionConfig' - if os.getenv('DEV') == 'true' or os.getenv('TEST') == 'true': + if os.getenv('TEST') == 'true': + default_config_file = os.getcwd() + '/conf/settings.py.example' + elif os.getenv('DEV') == 'true': default_config_file = os.getcwd() + '/conf/settings.py' else: default_config_file = '/etc/greenwave/settings.py' diff --git a/tox.ini b/tox.ini index eacb53d..c61a8f5 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,6 @@ deps = whitelist_externals = rm setenv = - TEST=true GREENWAVE_CONFIG={toxinidir}/conf/settings.py.example commands = rm -rf htmlcov coverage.xml