2016-12-08 16:50:37 +00:00
|
|
|
import os
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from app.cloudfoundry_config import extract_cloudfoundry_config, set_config_env_vars
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def notify_config():
|
|
|
|
|
return {
|
|
|
|
|
'name': 'notify-config',
|
|
|
|
|
'credentials': {
|
|
|
|
|
'api_host_name': 'api host name',
|
2017-03-27 17:59:06 +01:00
|
|
|
'admin_base_url': 'admin base url',
|
2016-12-08 16:50:37 +00:00
|
|
|
'admin_client_secret': 'admin client secret',
|
|
|
|
|
'secret_key': 'secret key',
|
|
|
|
|
'dangerous_salt': 'dangerous salt',
|
2017-11-16 16:33:50 +00:00
|
|
|
'route_secret_key_1': 'key 1',
|
|
|
|
|
'route_secret_key_2': 'key 2',
|
2016-12-08 16:50:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def aws_config():
|
|
|
|
|
return {
|
|
|
|
|
'name': 'notify-aws',
|
|
|
|
|
'credentials': {
|
|
|
|
|
'aws_access_key_id': 'aws access key id',
|
|
|
|
|
'aws_secret_access_key': 'aws secret access key',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def hosted_graphite_config():
|
|
|
|
|
return {
|
|
|
|
|
'name': 'hosted-graphite',
|
|
|
|
|
'credentials': {
|
|
|
|
|
'statsd_prefix': 'statsd prefix'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def deskpro_config():
|
|
|
|
|
return {
|
|
|
|
|
'name': 'deskpro',
|
|
|
|
|
'credentials': {
|
|
|
|
|
'api_host': 'deskpro api host',
|
|
|
|
|
'api_key': 'deskpro api key'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-04-10 18:12:00 +01:00
|
|
|
@pytest.fixture
|
|
|
|
|
def template_preview_config():
|
|
|
|
|
return {
|
|
|
|
|
'name': 'notify-template-preview',
|
|
|
|
|
'credentials': {
|
|
|
|
|
'api_host': 'template-preview api host',
|
|
|
|
|
'api_key': 'template-preview api key'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-08 16:50:37 +00:00
|
|
|
@pytest.fixture
|
|
|
|
|
def cloudfoundry_config(
|
|
|
|
|
notify_config,
|
|
|
|
|
aws_config,
|
|
|
|
|
hosted_graphite_config,
|
|
|
|
|
deskpro_config,
|
2017-04-10 18:12:00 +01:00
|
|
|
template_preview_config,
|
2016-12-08 16:50:37 +00:00
|
|
|
):
|
|
|
|
|
return {
|
|
|
|
|
'user-provided': [
|
|
|
|
|
notify_config,
|
|
|
|
|
aws_config,
|
|
|
|
|
hosted_graphite_config,
|
|
|
|
|
deskpro_config,
|
2017-04-10 18:12:00 +01:00
|
|
|
template_preview_config,
|
2016-12-08 16:50:37 +00:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def cloudfoundry_environ(monkeypatch, cloudfoundry_config):
|
|
|
|
|
monkeypatch.setenv('VCAP_SERVICES', json.dumps(cloudfoundry_config))
|
2017-01-09 19:14:04 +00:00
|
|
|
monkeypatch.setenv('VCAP_APPLICATION', '{"space_name":"🚀🌌"}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
|
|
|
|
def test_extract_cloudfoundry_config_populates_other_vars():
|
|
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
|
|
|
|
assert os.environ['NOTIFY_ENVIRONMENT'] == '🚀🌌'
|
2017-08-09 15:30:24 +01:00
|
|
|
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
2016-12-08 16:50:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
|
|
|
|
def test_set_config_env_vars_ignores_unknown_configs(cloudfoundry_config):
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
|
|
|
|
def test_notify_config():
|
|
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
|
|
|
|
assert os.environ['API_HOST_NAME'] == 'api host name'
|
2017-03-27 17:59:06 +01:00
|
|
|
assert os.environ['ADMIN_BASE_URL'] == 'admin base url'
|
2016-12-08 16:50:37 +00:00
|
|
|
assert os.environ['ADMIN_CLIENT_SECRET'] == 'admin client secret'
|
|
|
|
|
assert os.environ['SECRET_KEY'] == 'secret key'
|
|
|
|
|
assert os.environ['DANGEROUS_SALT'] == 'dangerous salt'
|
2017-11-16 16:33:50 +00:00
|
|
|
assert os.environ['ROUTE_SECRET_KEY_1'] == 'key 1'
|
|
|
|
|
assert os.environ['ROUTE_SECRET_KEY_2'] == 'key 2'
|
2016-12-08 16:50:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
|
|
|
|
def test_aws_config():
|
|
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
|
|
|
|
assert os.environ['AWS_ACCESS_KEY_ID'] == 'aws access key id'
|
|
|
|
|
assert os.environ['AWS_SECRET_ACCESS_KEY'] == 'aws secret access key'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
|
|
|
|
def test_hosted_graphite_config():
|
|
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
|
|
|
|
assert os.environ['STATSD_PREFIX'] == 'statsd prefix'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
|
|
|
|
def test_deskpro_config():
|
|
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
|
|
|
|
assert os.environ['DESKPRO_API_HOST'] == 'deskpro api host'
|
|
|
|
|
assert os.environ['DESKPRO_API_KEY'] == 'deskpro api key'
|
2017-04-10 18:12:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
2017-04-11 17:15:31 +01:00
|
|
|
def test_template_preview_config():
|
2017-04-10 18:12:00 +01:00
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
|
|
|
|
assert os.environ['TEMPLATE_PREVIEW_API_HOST'] == 'template-preview api host'
|
|
|
|
|
assert os.environ['TEMPLATE_PREVIEW_API_KEY'] == 'template-preview api key'
|