This commit is contained in:
Kenneth Kehl
2023-08-29 14:54:30 -07:00
parent 19dcd7a48b
commit 1ecb747c6d
588 changed files with 34100 additions and 23589 deletions

View File

@@ -6,79 +6,77 @@ import pytest
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'
"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'
_postgres_url = "postgres://postgres:password@localhost:5432/db_name"
@pytest.fixture
def vcap_services():
return {
'aws-rds': [{
'credentials': {
'uri': _postgres_url
}
}],
'aws-elasticache-redis': [{
'credentials': {
'uri': 'redis://xxx:6379'
}
}],
's3': [
"aws-rds": [{"credentials": {"uri": _postgres_url}}],
"aws-elasticache-redis": [{"credentials": {"uri": "redis://xxx:6379"}}],
"s3": [
{
'name': 'notify-api-csv-upload-bucket-test',
'credentials': _bucket_credentials
"name": "notify-api-csv-upload-bucket-test",
"credentials": _bucket_credentials,
},
{
'name': 'notify-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'
}
}
"name": "notify-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': []
"user-provided": [],
}
def test_database_url(vcap_services):
os.environ['DATABASE_URL'] = _postgres_url
os.environ["DATABASE_URL"] = _postgres_url
assert CloudfoundryConfig().database_url == 'postgresql://postgres:password@localhost:5432/db_name'
assert (
CloudfoundryConfig().database_url
== "postgresql://postgres:password@localhost:5432/db_name"
)
def test_redis_url(vcap_services):
os.environ['VCAP_SERVICES'] = json.dumps(vcap_services)
os.environ["VCAP_SERVICES"] = json.dumps(vcap_services)
assert CloudfoundryConfig().redis_url == 'rediss://xxx:6379'
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'] = ""
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)
os.environ["VCAP_SERVICES"] = json.dumps(vcap_services)
assert CloudfoundryConfig().s3_credentials('notify-api-csv-upload-bucket-test') == _bucket_credentials
assert (
CloudfoundryConfig().s3_credentials("notify-api-csv-upload-bucket-test")
== _bucket_credentials
)
def test_s3_bucket_credentials_falls_back_to_empty_creds():
os.environ['VCAP_SERVICES'] = ""
os.environ["VCAP_SERVICES"] = ""
expected = {
'bucket': '',
'access_key_id': '',
'secret_access_key': '',
'region': ''
"bucket": "",
"access_key_id": "",
"secret_access_key": "",
"region": "",
}
assert CloudfoundryConfig().s3_credentials('bucket') == expected
assert CloudfoundryConfig().s3_credentials("bucket") == expected