Merge pull request #3508 from alphagov/redis-ssl-181796569

Prepare to switch to Redis on PaaS
This commit is contained in:
Ben Thorner
2022-04-12 15:47:46 +01:00
committed by GitHub
3 changed files with 44 additions and 15 deletions

View File

@@ -10,39 +10,38 @@ from app.cloudfoundry_config import (
@pytest.fixture
def postgres_config():
return [
{
def cloudfoundry_config():
return {
'postgres': [{
'credentials': {
'uri': 'postgres uri'
}
}
]
@pytest.fixture
def cloudfoundry_config(postgres_config):
return {
'postgres': postgres_config,
}],
'redis': [{
'credentials': {
'uri': 'redis uri'
}
}],
'user-provided': []
}
@pytest.fixture
def cloudfoundry_environ(os_environ, cloudfoundry_config):
os.environ['VCAP_SERVICES'] = json.dumps(cloudfoundry_config)
def vcap_application(os_environ):
os.environ['VCAP_APPLICATION'] = '{"space_name": "🚀🌌"}'
def test_extract_cloudfoundry_config_populates_other_vars(cloudfoundry_environ):
def test_extract_cloudfoundry_config_populates_other_vars(cloudfoundry_config, vcap_application):
os.environ['VCAP_SERVICES'] = json.dumps(cloudfoundry_config)
extract_cloudfoundry_config()
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgresql uri'
assert os.environ['REDIS_URL'] == 'redis uri'
assert os.environ['NOTIFY_ENVIRONMENT'] == '🚀🌌'
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config, cloudfoundry_environ):
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config, vcap_application):
cloudfoundry_config['foo'] = {'credentials': {'foo': 'foo'}}
cloudfoundry_config['user-provided'].append({
'name': 'bar', 'credentials': {'bar': 'bar'}
@@ -52,3 +51,9 @@ def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config, cloudf
assert 'foo' not in os.environ
assert 'bar' not in os.environ
def test_set_config_env_vars_copes_if_redis_not_set(cloudfoundry_config, vcap_application):
del cloudfoundry_config['redis']
set_config_env_vars(cloudfoundry_config)
assert 'REDIS_URL' not in os.environ