def test_ec2_iam_policy(): """Check template for proper format.""" ec2_json = get_template(EC2_TEMPLATE_NAME) ec2_dict = json.loads(ec2_json) assert all(key in ec2_dict for key in ('Version', 'Statement')) assert len(ec2_dict['Statement']) == 1 only_statement = ec2_dict['Statement'][0] assert only_statement['Action'] == 'sts:AssumeRole' assert only_statement['Effect'] == 'Allow' assert only_statement['Principal']['Service'] == 'ec2.amazonaws.com'
def test_lambda_iam_policy(): """Check Lambda Trust Relationship template format.""" lambda_json = get_template(LAMBDA_TEMPLATE_NAME) lambda_dict = json.loads(lambda_json) assert all(key in lambda_dict for key in ('Version', 'Statement')) assert len(lambda_dict['Statement']) == 1 only_statement = lambda_dict['Statement'][0] assert only_statement['Action'] == 'sts:AssumeRole' assert only_statement['Effect'] == 'Allow' assert only_statement['Principal']['Service'] == 'lambda.amazonaws.com'
def valid_json(template, data): parsed_template = get_template(template_file=template, data=data) assert type(json.loads(parsed_template)) == dict
def test_get_template(): with pytest.raises(ForemastTemplateNotFound): template = get_template(template_file='doesnotexist.json.j2')