mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 16:31:15 -05:00
previously in run_app_paas.sh, we captured stdout from the app and piped that into the log file. However, this came up with a bunch of problems, mainly: * exceptions with stack traces often weren't formatted properly, and kibana could not parse them * celery logs were duplicated - we'd collect both the json logs and the human readable stdout logs. instead, with the updated utils library, we can use that to log json straight to the appropriate directory directly.
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
import os
|
|
import importlib
|
|
from unittest import mock
|
|
|
|
import pytest
|
|
|
|
from app import config
|
|
|
|
|
|
def cf_conf():
|
|
os.environ['ADMIN_BASE_URL'] = 'cf'
|
|
|
|
|
|
@pytest.fixture
|
|
def reload_config():
|
|
"""
|
|
Reset config, by simply re-running config.py from a fresh environment
|
|
"""
|
|
old_env = os.environ.copy()
|
|
|
|
yield
|
|
|
|
os.environ = old_env
|
|
importlib.reload(config)
|
|
|
|
|
|
def test_load_cloudfoundry_config_if_available(monkeypatch, reload_config):
|
|
os.environ['ADMIN_BASE_URL'] = 'env'
|
|
monkeypatch.setenv('VCAP_SERVICES', 'some json blob')
|
|
monkeypatch.setenv('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
|
|
importlib.reload(config)
|
|
|
|
assert cf_config.called
|
|
|
|
assert os.environ['ADMIN_BASE_URL'] == 'cf'
|
|
assert config.Config.ADMIN_BASE_URL == 'cf'
|
|
|
|
|
|
def test_load_config_if_cloudfoundry_not_available(monkeypatch, reload_config):
|
|
os.environ['ADMIN_BASE_URL'] = 'env'
|
|
|
|
monkeypatch.delenv('VCAP_SERVICES', raising=False)
|
|
|
|
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
|
|
importlib.reload(config)
|
|
|
|
assert not cf_config.called
|
|
|
|
assert os.environ['ADMIN_BASE_URL'] == 'env'
|
|
assert config.Config.ADMIN_BASE_URL == 'env'
|
|
|
|
|
|
def test_cloudfoundry_config_has_different_defaults():
|
|
# these should always be set on Sandbox
|
|
assert config.Sandbox.REDIS_ENABLED is False
|