""" Select fine-grained assertion tests on key elements of the CloudFormation template generated by ckd synth """
import json
import pytest

import aws_cdk 
from aws_cdk.assertions import Template, Match

from dicom_ahl.study_stack import StudyProcessorStack

@pytest.fixture
def synthesize_template():
    
    app = aws_cdk.core.App()

    # Create instance of StudyProcessorStack
    study_stack = StudyProcessorStack(app, "StudyStack")

    template = Template.from_stack(study_stack)
    
    return template

def test_encrypted_ingestion_bucket(synthesize_template):
    """ Assert that s3 buckets are encrypted """
    synthesize_template.has_resource_properties("AWS::S3::Bucket", 
        {"BucketEncryption": Match.object_equals(
                {"ServerSideEncryptionConfiguration": [
                    {"ServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}
                    ]})
        }
    )

def test_no_unencrypted(synthesize_template):
    """ Assert that no S3 bucket in template lacks encryption properties """
    synthesize_template.has_resource_properties("AWS::S3::Bucket", 
        {"BucketEncryption": Match.not_(Match.absent())
        }
    )