2022-04-12 16:48:38 +01:00
|
|
|
import json
|
2016-12-08 16:50:37 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2022-10-20 08:03:32 -04:00
|
|
|
from app.cloudfoundry_config import CloudfoundryConfig
|
|
|
|
|
|
|
|
|
|
bucket_credentials = {
|
|
|
|
|
'access_key_id': 'contact-list-access',
|
|
|
|
|
'bucket': 'contact-list-bucket',
|
|
|
|
|
'region': 'us-gov-west-1',
|
|
|
|
|
'secret_access_key': 'contact-list-secret'
|
|
|
|
|
}
|
2016-12-08 16:50:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-04-13 14:45:29 +01:00
|
|
|
def vcap_services():
|
2022-04-12 16:48:38 +01:00
|
|
|
return {
|
2022-08-05 00:25:03 -07:00
|
|
|
'aws-elasticache-redis': [{
|
2022-04-12 16:48:38 +01:00
|
|
|
'credentials': {
|
2022-09-09 17:02:48 -07:00
|
|
|
'uri': 'redis://xxx:6379'
|
2022-04-12 16:48:38 +01:00
|
|
|
}
|
|
|
|
|
}],
|
2022-09-19 11:19:38 -04:00
|
|
|
's3': [
|
|
|
|
|
{
|
2022-11-07 12:15:54 -05:00
|
|
|
'name': 'notify-api-csv-upload-bucket-test',
|
2022-09-19 11:19:38 -04:00
|
|
|
'credentials': {
|
2022-09-22 12:33:55 -04:00
|
|
|
'access_key_id': 'csv-access',
|
|
|
|
|
'bucket': 'csv-upload-bucket',
|
2022-09-26 10:25:03 -04:00
|
|
|
'region': 'us-gov-west-1',
|
2022-09-22 12:33:55 -04:00
|
|
|
'secret_access_key': 'csv-secret'
|
2022-09-19 11:19:38 -04:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-11-07 12:15:54 -05:00
|
|
|
'name': 'notify-api-contact-list-bucket-test',
|
2022-10-20 08:03:32 -04:00
|
|
|
'credentials': bucket_credentials
|
2022-09-19 11:19:38 -04:00
|
|
|
}
|
|
|
|
|
],
|
2022-04-12 16:48:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-10-20 08:03:32 -04:00
|
|
|
def test_redis_url(vcap_services):
|
2022-04-13 14:45:29 +01:00
|
|
|
os.environ['VCAP_SERVICES'] = json.dumps(vcap_services)
|
2017-01-09 19:14:04 +00:00
|
|
|
|
2022-10-20 08:03:32 -04:00
|
|
|
assert CloudfoundryConfig().redis_url == 'rediss://xxx:6379'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_redis_url_falls_back_to_REDIS_URL():
|
|
|
|
|
expected = 'rediss://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)
|
|
|
|
|
|
2022-11-07 12:15:54 -05:00
|
|
|
assert CloudfoundryConfig().s3_credentials('notify-api-contact-list-bucket-test') == bucket_credentials
|
2022-10-20 08:03:32 -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
|