@@ -102,11 +102,6 @@ def firehose_client(boto3_session: Session, localstack: URL) -> BaseClient:
102102 return boto3_session .client ("firehose" , endpoint_url = str (localstack ))
103103
104104
105- @pytest .fixture (autouse = True )
106- def firehose_delivery_stream (firehose_client : BaseClient ) -> dict [str , Any ]:
107- return firehose_client .create_delivery_stream (DeliveryStreamName = "eligibility-signposting-audit-stream" )
108-
109-
110105@pytest .fixture (scope = "session" )
111106def iam_role (iam_client : BaseClient ) -> Generator [str ]:
112107 role_name = "LambdaExecutionRole"
@@ -391,13 +386,38 @@ def rules_bucket(s3_client: BaseClient) -> Generator[BucketName]:
391386
392387
393388@pytest .fixture (scope = "session" )
394- def audit_bucket (s3_client : BaseClient ) -> Generator [BucketName ]:
389+ def audit_bucket (s3_client : BaseClient ) -> Generator [BucketName , None , None ]:
395390 bucket_name = BucketName (os .getenv ("AUDIT_BUCKET_NAME" , "test-audit-bucket" ))
396- s3_client .create_bucket (Bucket = bucket_name , CreateBucketConfiguration = {"LocationConstraint" : AWS_REGION })
391+ s3_client .create_bucket (
392+ Bucket = bucket_name ,
393+ CreateBucketConfiguration = {"LocationConstraint" : AWS_REGION }
394+ )
397395 yield bucket_name
396+
397+ # Delete all objects in the bucket before deletion
398+ objects = s3_client .list_objects_v2 (Bucket = bucket_name ).get ("Contents" , [])
399+ for obj in objects :
400+ s3_client .delete_object (Bucket = bucket_name , Key = obj ["Key" ])
398401 s3_client .delete_bucket (Bucket = bucket_name )
399402
400403
404+ @pytest .fixture (autouse = True )
405+ def firehose_delivery_stream (firehose_client : BaseClient , audit_bucket : BucketName ) -> dict [str , Any ]:
406+ return firehose_client .create_delivery_stream (
407+ DeliveryStreamName = "eligibility-signposting-audit-stream" ,
408+ DeliveryStreamType = "DirectPut" ,
409+ ExtendedS3DestinationConfiguration = {
410+ "BucketARN" : f"arn:aws:s3:::{ audit_bucket } " ,
411+ "RoleARN" : "arn:aws:iam::000000000000:role/firehose_delivery_role" ,
412+ "Prefix" : "audit-logs/" ,
413+ "BufferingHints" : {
414+ "SizeInMBs" : 1 ,
415+ "IntervalInSeconds" : 60
416+ },
417+ "CompressionFormat" : "UNCOMPRESSED" ,
418+ }
419+ )
420+
401421@pytest .fixture (scope = "class" )
402422def campaign_config (s3_client : BaseClient , rules_bucket : BucketName ) -> Generator [rules .CampaignConfig ]:
403423 campaign : rules .CampaignConfig = rule .CampaignConfigFactory .build (
0 commit comments