mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge branch 'main' into stvnrlly-create-user-command
This commit is contained in:
@@ -92,9 +92,9 @@ def test_update_letter_notifications_statuses_calls_with_correct_bucket_location
|
||||
s3_mock.assert_called_with('{}-ftp'.format(
|
||||
current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
'NOTIFY-20170823160812-RSP.TXT',
|
||||
os.environ['AWS_ACCESS_KEY_ID'],
|
||||
os.environ['AWS_SECRET_ACCESS_KEY'],
|
||||
os.environ['AWS_REGION'],
|
||||
os.environ.get('AWS_ACCESS_KEY_ID'),
|
||||
os.environ.get('AWS_SECRET_ACCESS_KEY'),
|
||||
os.environ.get('AWS_REGION'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,14 @@ import os
|
||||
|
||||
import pytest
|
||||
|
||||
from app.cloudfoundry_config import extract_cloudfoundry_config
|
||||
from app.cloudfoundry_config import CloudfoundryConfig
|
||||
|
||||
bucket_credentials = {
|
||||
'access_key_id': 'csv-access',
|
||||
'bucket': 'csv-upload-bucket',
|
||||
'region': 'us-gov-west-1',
|
||||
'secret_access_key': 'csv-secret'
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -22,12 +29,7 @@ def vcap_services():
|
||||
's3': [
|
||||
{
|
||||
'name': 'notifications-api-csv-upload-bucket-test',
|
||||
'credentials': {
|
||||
'access_key_id': 'csv-access',
|
||||
'bucket': 'csv-upload-bucket',
|
||||
'region': 'us-gov-west-1',
|
||||
'secret_access_key': 'csv-secret'
|
||||
}
|
||||
'credentials': bucket_credentials
|
||||
},
|
||||
{
|
||||
'name': 'notifications-api-contact-list-bucket-test',
|
||||
@@ -43,12 +45,33 @@ def vcap_services():
|
||||
}
|
||||
|
||||
|
||||
def test_extract_cloudfoundry_config_populates_other_vars(os_environ, vcap_services):
|
||||
os.environ['DEPLOY_ENV'] = 'test'
|
||||
def test_redis_url(vcap_services):
|
||||
os.environ['VCAP_SERVICES'] = json.dumps(vcap_services)
|
||||
extract_cloudfoundry_config()
|
||||
|
||||
assert os.environ['SQLALCHEMY_DATABASE_URI'] == 'postgresql uri'
|
||||
assert os.environ['REDIS_URL'] == 'rediss://xxx:6379'
|
||||
assert os.environ['CSV_UPLOAD_BUCKET_NAME'] == 'csv-upload-bucket'
|
||||
assert os.environ['CONTACT_LIST_BUCKET_NAME'] == 'contact-list-bucket'
|
||||
assert CloudfoundryConfig().redis_url == 'rediss://xxx:6379'
|
||||
|
||||
|
||||
def test_redis_url_falls_back_to_REDIS_URL():
|
||||
expected = 'redis://yyy:6379'
|
||||
os.environ['REDIS_URL'] = expected
|
||||
os.environ['VCAP_SERVICES'] = ""
|
||||
|
||||
assert CloudfoundryConfig().redis_url == expected
|
||||
|
||||
|
||||
def test_s3_bucket_credentials(vcap_services):
|
||||
os.environ['VCAP_SERVICES'] = json.dumps(vcap_services)
|
||||
|
||||
assert CloudfoundryConfig().s3_credentials('notifications-api-csv-upload-bucket-test') == bucket_credentials
|
||||
|
||||
|
||||
def test_s3_bucket_credentials_falls_back_to_empty_creds():
|
||||
os.environ['VCAP_SERVICES'] = ""
|
||||
expected = {
|
||||
'bucket': '',
|
||||
'access_key_id': '',
|
||||
'secret_access_key': '',
|
||||
'region': ''
|
||||
}
|
||||
|
||||
assert CloudfoundryConfig().s3_credentials('bucket') == expected
|
||||
|
||||
@@ -1,62 +1,6 @@
|
||||
import importlib
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from app import config
|
||||
from app.config import QueueNames
|
||||
|
||||
|
||||
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
|
||||
|
||||
os.environ.clear()
|
||||
for k, v in old_env.items():
|
||||
os.environ[k] = v
|
||||
|
||||
importlib.reload(config)
|
||||
|
||||
|
||||
def test_load_cloudfoundry_config_if_available(reload_config):
|
||||
os.environ['ADMIN_BASE_URL'] = 'env'
|
||||
os.environ['VCAP_SERVICES'] = 'some json blob'
|
||||
os.environ['VCAP_APPLICATION'] = 'some json blob'
|
||||
|
||||
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'
|
||||
|
||||
|
||||
def test_load_config_if_cloudfoundry_not_available(reload_config):
|
||||
os.environ['ADMIN_BASE_URL'] = 'env'
|
||||
os.environ.pop('VCAP_SERVICES', None)
|
||||
|
||||
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'
|
||||
|
||||
|
||||
def test_queue_names_all_queues_correct():
|
||||
# Need to ensure that all_queues() only returns queue names used in API
|
||||
queues = QueueNames.all_queues()
|
||||
|
||||
Reference in New Issue
Block a user