2016-12-08 12:12:45 +00:00
|
|
|
import json
|
2021-03-10 13:55:06 +00:00
|
|
|
import os
|
2016-12-08 12:12:45 +00:00
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2021-03-10 13:55:06 +00:00
|
|
|
from app.cloudfoundry_config import (
|
|
|
|
|
extract_cloudfoundry_config,
|
|
|
|
|
set_config_env_vars,
|
|
|
|
|
)
|
2016-12-08 12:12:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def postgres_config():
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
'credentials': {
|
|
|
|
|
'uri': 'postgres uri'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2017-03-03 11:07:29 +00:00
|
|
|
@pytest.fixture
|
2018-01-04 16:55:49 +00:00
|
|
|
def cloudfoundry_config(postgres_config):
|
2016-12-08 12:12:45 +00:00
|
|
|
return {
|
|
|
|
|
'postgres': postgres_config,
|
2018-01-04 16:55:49 +00:00
|
|
|
'user-provided': []
|
2016-12-08 12:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2020-01-06 17:07:06 +00:00
|
|
|
def cloudfoundry_environ(os_environ, cloudfoundry_config):
|
|
|
|
|
os.environ['VCAP_SERVICES'] = json.dumps(cloudfoundry_config)
|
|
|
|
|
os.environ['VCAP_APPLICATION'] = '{"space_name": "🚀🌌"}'
|
2016-12-08 12:12:45 +00:00
|
|
|
|
|
|
|
|
|
2020-01-06 17:07:06 +00:00
|
|
|
def test_extract_cloudfoundry_config_populates_other_vars(cloudfoundry_environ):
|
2016-12-08 12:12:45 +00:00
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
2021-04-29 13:49:37 +01:00
|
|
|
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgresql uri'
|
2016-12-08 12:12:45 +00:00
|
|
|
assert os.environ['NOTIFY_ENVIRONMENT'] == '🚀🌌'
|
2017-07-31 13:28:34 +01:00
|
|
|
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
2016-12-08 12:12:45 +00:00
|
|
|
|
|
|
|
|
|
2020-01-06 17:07:06 +00:00
|
|
|
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config, cloudfoundry_environ):
|
2016-12-08 12:12:45 +00:00
|
|
|
cloudfoundry_config['foo'] = {'credentials': {'foo': 'foo'}}
|
|
|
|
|
cloudfoundry_config['user-provided'].append({
|
|
|
|
|
'name': 'bar', 'credentials': {'bar': 'bar'}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
set_config_env_vars(cloudfoundry_config)
|
|
|
|
|
|
|
|
|
|
assert 'foo' not in os.environ
|
|
|
|
|
assert 'bar' not in os.environ
|