2022-04-12 16:48:38 +01:00
|
|
|
import json
|
2016-12-08 16:50:37 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2018-01-09 14:18:32 +00:00
|
|
|
from app.cloudfoundry_config import extract_cloudfoundry_config
|
2016-12-08 16:50:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-04-12 16:48:38 +01:00
|
|
|
def cloudfoundry_config():
|
|
|
|
|
return {
|
|
|
|
|
'redis': [{
|
|
|
|
|
'credentials': {
|
|
|
|
|
'uri': 'redis uri'
|
|
|
|
|
}
|
|
|
|
|
}],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def vcap_application(os_environ):
|
2020-01-07 11:54:10 +00:00
|
|
|
os.environ['VCAP_APPLICATION'] = '{"space_name":"🚀🌌"}'
|
2017-01-09 19:14:04 +00:00
|
|
|
|
|
|
|
|
|
2022-04-12 16:48:38 +01:00
|
|
|
def test_extract_cloudfoundry_config_populates_other_vars(vcap_application, cloudfoundry_config):
|
|
|
|
|
os.environ['VCAP_SERVICES'] = json.dumps(cloudfoundry_config)
|
2017-01-09 19:14:04 +00:00
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
|
2022-04-12 16:48:38 +01:00
|
|
|
assert os.environ['REDIS_URL'] == 'redis uri'
|
2017-01-09 19:14:04 +00:00
|
|
|
assert os.environ['NOTIFY_ENVIRONMENT'] == '🚀🌌'
|
2017-08-09 15:30:24 +01:00
|
|
|
assert os.environ['NOTIFY_LOG_PATH'] == '/home/vcap/logs/app.log'
|
2022-04-12 16:48:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_config_env_vars_copes_if_redis_not_set(vcap_application, cloudfoundry_config):
|
|
|
|
|
del cloudfoundry_config['redis']
|
|
|
|
|
os.environ['VCAP_SERVICES'] = json.dumps(cloudfoundry_config)
|
|
|
|
|
|
|
|
|
|
extract_cloudfoundry_config()
|
|
|
|
|
assert 'REDIS_URL' not in os.environ
|