def test_s3_backend_update(s3_bucket_name): from swag_client.backend import SWAGManager from swag_client.util import parse_swag_config_options swag_opts = { 'swag.type': 's3', 'swag.bucket_name': s3_bucket_name, 'swag.cache_expires': 0 } swag = SWAGManager(**parse_swag_config_options(swag_opts)) account = { 'aliases': ['test'], 'contacts': ['*****@*****.**'], 'description': 'LOL, Test account', 'email': '*****@*****.**', 'environment': 'test', 'id': '012345678910', 'name': 'testaccount', 'owner': 'netflix', 'provider': 'aws', 'sensitive': False } swag.create(account) account['aliases'] = ['test', 'prod'] swag.update(account) item = swag.get("[?id=='{id}']".format(id=account['id'])) assert item['aliases'] == ['test', 'prod']
def test_dynamodb_backend_update(dynamodb_table): from swag_client.backend import SWAGManager from swag_client.util import parse_swag_config_options swag_opts = { 'swag.type': 'dynamodb', 'swag.namespace': 'accounts', 'swag.key_type': 'HASH', 'swag.key_attribute': 'id', 'swag.cache_expires': 0 } swag = SWAGManager(**parse_swag_config_options(swag_opts)) account = { 'aliases': ['test'], 'contacts': ['*****@*****.**'], 'description': 'LOL, Test account', 'email': '*****@*****.**', 'environment': 'test', 'id': '012345678910', 'name': 'testaccount', 'owner': 'netflix', 'provider': 'aws', 'sensitive': False } swag.create(account) account['aliases'] = ['test', 'prod'] swag.update(account) assert swag.get("[?id=='{id}']".format(id=account['id']))
def test_get_only_test_accounts(swag_accounts): """Tests that the SWAG logic will only return 'test' accounts if specified.""" from historical.common.accounts import get_historical_accounts # Setup: bucket_name = 'SWAG' data_file = 'accounts.json' region = 'us-east-1' owner = 'third-party' os.environ['SWAG_BUCKET'] = bucket_name os.environ['SWAG_DATA_FILE'] = data_file os.environ['SWAG_REGION'] = region os.environ['SWAG_OWNER'] = owner swag_opts = { 'swag.type': 's3', 'swag.bucket_name': bucket_name, 'swag.data_file': data_file, 'swag.region': region, 'swag.cache_expires': 0 } swag = SWAGManager(**parse_swag_config_options(swag_opts)) # Production account: account = { 'aliases': ['prod'], 'contacts': ['*****@*****.**'], 'description': 'LOL, PROD account', 'email': '*****@*****.**', 'environment': 'prod', 'id': '999999999999', 'name': 'prodaccount', 'owner': 'third-party', 'provider': 'aws', 'sensitive': False, 'account_status': 'ready', 'services': [{ 'name': 'historical', 'status': [{ 'region': 'all', 'enabled': True }] }] } swag.create(account) # Get all the swag accounts: result = get_historical_accounts() assert len(result) == 2 assert result[1]['environment'] == 'prod' assert result[1]['id'] == '999999999999' # Only test accounts: os.environ['TEST_ACCOUNTS_ONLY'] = 'True' result = get_historical_accounts() assert len(result) == 1 assert result[0]['environment'] == 'test' assert result[0]['id'] != '999999999999' # Test the boolean logic: os.environ['TEST_ACCOUNTS_ONLY'] = '' result = get_historical_accounts() assert len(result) == 2 os.environ['TEST_ACCOUNTS_ONLY'] = 'false' result = get_historical_accounts() assert len(result) == 2 # Make sure that disabled/deleted accounts are not in the results: account['account_status'] = 'deleted' swag.update(account) result = get_historical_accounts() assert len(result) == 1