Files
notifications-api/tests/app/test_cloudfoundry_config.py

85 lines
2.2 KiB
Python
Raw Normal View History

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
2022-10-31 15:37:12 -04:00
from app.cloudfoundry_config import CloudfoundryConfig
_bucket_credentials = {
2022-10-31 15:37:12 -04:00
'access_key_id': 'csv-access',
'bucket': 'csv-upload-bucket',
'region': 'us-gov-west-1',
'secret_access_key': 'csv-secret'
}
_postgres_url = 'postgres://postgres:password@localhost:5432/db_name'
2016-12-08 12:12:45 +00:00
@pytest.fixture
def vcap_services():
return {
'aws-rds': [{
2016-12-08 12:12:45 +00:00
'credentials': {
'uri': _postgres_url
2016-12-08 12:12:45 +00:00
}
}],
'aws-elasticache-redis': [{
'credentials': {
'uri': 'redis://xxx:6379'
}
}],
's3': [
{
'name': 'notifications-api-csv-upload-bucket-test',
'credentials': _bucket_credentials
},
{
'name': 'notifications-api-contact-list-bucket-test',
'credentials': {
'access_key_id': 'contact-access',
'bucket': 'contact-list-bucket',
'region': 'us-gov-west-1',
'secret_access_key': 'contact-secret'
}
}
],
'user-provided': []
2016-12-08 12:12:45 +00:00
}
def test_database_url(vcap_services):
os.environ['DATABASE_URL'] = _postgres_url
assert CloudfoundryConfig().database_url == 'postgresql://postgres:password@localhost:5432/db_name'
2022-10-31 15:37:12 -04:00
def test_redis_url(vcap_services):
os.environ['VCAP_SERVICES'] = json.dumps(vcap_services)
2016-12-08 12:12:45 +00:00
2022-10-31 15:37:12 -04:00
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
2022-10-31 15:37:12 -04:00
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