mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
remove monkeypatch
it's interacting strangely with our os.environ stuff and not restoring nicely, probably due to fixture order which is hard to visualise and control.
This commit is contained in:
@@ -26,13 +26,12 @@ def cloudfoundry_config(postgres_config):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cloudfoundry_environ(monkeypatch, cloudfoundry_config):
|
||||
monkeypatch.setenv('VCAP_SERVICES', json.dumps(cloudfoundry_config))
|
||||
monkeypatch.setenv('VCAP_APPLICATION', '{"space_name": "🚀🌌"}')
|
||||
def cloudfoundry_environ(os_environ, cloudfoundry_config):
|
||||
os.environ['VCAP_SERVICES'] = json.dumps(cloudfoundry_config)
|
||||
os.environ['VCAP_APPLICATION'] = '{"space_name": "🚀🌌"}'
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
||||
def test_extract_cloudfoundry_config_populates_other_vars():
|
||||
def test_extract_cloudfoundry_config_populates_other_vars(cloudfoundry_environ):
|
||||
extract_cloudfoundry_config()
|
||||
|
||||
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgres uri'
|
||||
@@ -40,8 +39,7 @@ def test_extract_cloudfoundry_config_populates_other_vars():
|
||||
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
||||
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config):
|
||||
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config, cloudfoundry_environ):
|
||||
cloudfoundry_config['foo'] = {'credentials': {'foo': 'foo'}}
|
||||
cloudfoundry_config['user-provided'].append({
|
||||
'name': 'bar', 'credentials': {'bar': 'bar'}
|
||||
|
||||
@@ -21,16 +21,17 @@ def reload_config():
|
||||
|
||||
yield
|
||||
|
||||
os.environ.clear()
|
||||
for k, v in old_env.items():
|
||||
os.environ[k] = v
|
||||
|
||||
importlib.reload(config)
|
||||
|
||||
|
||||
def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
||||
def test_load_cloudfoundry_config_if_available(reload_config):
|
||||
os.environ['ADMIN_BASE_URL'] = 'env'
|
||||
monkeypatch.setenv('VCAP_SERVICES', 'some json blob')
|
||||
monkeypatch.setenv('VCAP_APPLICATION', 'some json blob')
|
||||
os.environ['VCAP_SERVICES'] = 'some json blob'
|
||||
os.environ['VCAP_APPLICATION'] = 'some json blob'
|
||||
|
||||
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config', side_effect=cf_conf) as cf_config:
|
||||
# reload config so that its module level code (ie: all of it) is re-instantiated
|
||||
@@ -42,10 +43,9 @@ def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
||||
assert config.Config.ADMIN_BASE_URL == 'cf'
|
||||
|
||||
|
||||
def test_load_config_if_cloudfoundry_not_available(monkeypatch, reload_config):
|
||||
def test_load_config_if_cloudfoundry_not_available(reload_config):
|
||||
os.environ['ADMIN_BASE_URL'] = 'env'
|
||||
|
||||
monkeypatch.delenv('VCAP_SERVICES', raising=False)
|
||||
os.environ.pop('VCAP_SERVICES', None)
|
||||
|
||||
with mock.patch('app.cloudfoundry_config.extract_cloudfoundry_config') as cf_config:
|
||||
# reload config so that its module level code (ie: all of it) is re-instantiated
|
||||
|
||||
@@ -130,14 +130,12 @@ def os_environ():
|
||||
"""
|
||||
# for use whenever you expect code to edit environment variables
|
||||
old_env = os.environ.copy()
|
||||
|
||||
class EnvironDict(dict):
|
||||
def __setitem__(self, key, value):
|
||||
assert type(value) == str
|
||||
super().__setitem__(key, value)
|
||||
|
||||
os.environ.clear()
|
||||
|
||||
yield
|
||||
|
||||
# clear afterwards in case anything extra was added to the environment during the test
|
||||
os.environ.clear()
|
||||
for k, v in old_env.items():
|
||||
os.environ[k] = v
|
||||
|
||||
|
||||
Reference in New Issue
Block a user