2016-12-08 12:12:45 +00:00
|
|
|
import os
|
|
|
|
|
import importlib
|
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from app import config
|
2017-08-22 15:49:56 +01:00
|
|
|
from app.config import QueueNames
|
2016-12-08 12:12:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2020-01-06 17:07:06 +00:00
|
|
|
os.environ.clear()
|
2020-01-06 16:08:33 +00:00
|
|
|
for k, v in old_env.items():
|
|
|
|
|
os.environ[k] = v
|
|
|
|
|
|
2016-12-08 12:12:45 +00:00
|
|
|
importlib.reload(config)
|
|
|
|
|
|
|
|
|
|
|
2020-01-06 17:07:06 +00:00
|
|
|
def test_load_cloudfoundry_config_if_available(reload_config):
|
2016-12-08 12:12:45 +00:00
|
|
|
os.environ['ADMIN_BASE_URL'] = 'env'
|
2020-01-06 17:07:06 +00:00
|
|
|
os.environ['VCAP_SERVICES'] = 'some json blob'
|
|
|
|
|
os.environ['VCAP_APPLICATION'] = 'some json blob'
|
2016-12-08 12:12:45 +00:00
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
|
|
|
2020-01-06 17:07:06 +00:00
|
|
|
def test_load_config_if_cloudfoundry_not_available(reload_config):
|
2016-12-08 12:12:45 +00:00
|
|
|
os.environ['ADMIN_BASE_URL'] = 'env'
|
2020-01-06 17:07:06 +00:00
|
|
|
os.environ.pop('VCAP_SERVICES', None)
|
2016-12-08 12:12:45 +00:00
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
|
|
|
2017-08-22 15:49:56 +01:00
|
|
|
def test_queue_names_all_queues_correct():
|
|
|
|
|
# Need to ensure that all_queues() only returns queue names used in API
|
|
|
|
|
queues = QueueNames.all_queues()
|
2020-10-27 16:18:57 +00:00
|
|
|
assert len(queues) == 15
|
2017-08-22 16:26:07 +01:00
|
|
|
assert set([
|
|
|
|
|
QueueNames.PRIORITY,
|
|
|
|
|
QueueNames.PERIODIC,
|
|
|
|
|
QueueNames.DATABASE,
|
|
|
|
|
QueueNames.SEND_SMS,
|
|
|
|
|
QueueNames.SEND_EMAIL,
|
|
|
|
|
QueueNames.RESEARCH_MODE,
|
2019-08-15 15:21:00 +01:00
|
|
|
QueueNames.REPORTING,
|
2017-08-22 16:26:07 +01:00
|
|
|
QueueNames.JOBS,
|
|
|
|
|
QueueNames.RETRY,
|
2017-12-08 17:33:13 +00:00
|
|
|
QueueNames.NOTIFY,
|
2017-12-13 11:55:08 +00:00
|
|
|
QueueNames.CREATE_LETTERS_PDF,
|
2017-12-18 16:22:22 +00:00
|
|
|
QueueNames.CALLBACKS,
|
|
|
|
|
QueueNames.LETTERS,
|
2020-03-16 16:13:30 +00:00
|
|
|
QueueNames.SMS_CALLBACKS,
|
2020-10-27 16:18:57 +00:00
|
|
|
QueueNames.SAVE_API_EMAIL
|
2017-08-22 16:26:07 +01:00
|
|
|
]) == set(queues)
|