1+ '''Test CreateJpgFromRaw'''
2+
3+ import json
4+ import os
5+
6+ import boto3
7+
8+ import pytest
9+ from aws_lambda_powertools .utilities .data_classes import S3Event
10+ from mypy_boto3_cloudformation import CloudFormationClient
11+ from mypy_boto3_lambda import LambdaClient
12+ from mypy_boto3_events import EventsClient
13+
14+ STACK_NAME = os .environ .get ('STACK_NAME' )
15+ FUNCTION_LOGICAL_ID = 'CreateJpegFromRaw'
16+ EVENT_BUS_LOGICAL_ID = 'EventBus'
17+ IMAGE_BUCKET_PATH = os .environ .get ('TEST_PHOTO_IMAGE_BUCKET_PATH' , 'DUMMY_BUCKET' ).strip ('/' ).split ('/' , 1 )
18+ BUCKET_NAME = IMAGE_BUCKET_PATH [0 ]
19+ BUCKET_PATH = IMAGE_BUCKET_PATH [1 ].strip ('/' ) if len (IMAGE_BUCKET_PATH ) > 1 else ''
20+
21+ DATA_DIR = './data'
22+ EVENT_DIR = os .path .join (DATA_DIR , 'events' )
23+
24+ ## AWS
25+ @pytest .fixture ()
26+ def session ():
27+ '''Return a boto3 session'''
28+ return boto3 .Session ()
29+
30+ @pytest .fixture ()
31+ def cfn_client (session ) -> CloudFormationClient :
32+ '''Return a CFN client'''
33+ return session .client ('cloudformation' )
34+
35+ @pytest .fixture ()
36+ def lambda_client (session ) -> LambdaClient :
37+ '''Return a Lambda client'''
38+ return session .client ('lambda' )
39+
40+ @pytest .fixture ()
41+ def lambda_function_name (cfn_client ) -> str :
42+ '''Return the Lambda function name'''
43+ function_info = cfn_client .describe_stack_resource (
44+ StackName = STACK_NAME ,
45+ LogicalResourceId = FUNCTION_LOGICAL_ID
46+ )
47+ return function_info ['StackResourceDetail' ]['PhysicalResourceId' ]
48+
49+ @pytest .fixture ()
50+ def events_client (session ) -> EventsClient :
51+ '''Return an SNS client'''
52+ return session .client ('sns' )
53+
54+ @pytest .fixture ()
55+ def eventbus_name (cfn_client ) -> str :
56+ '''Return the EventBus name'''
57+ eventbus_name = cfn_client .describe_stack_resource (
58+ StackName = STACK_NAME ,
59+ LogicalResourceId = EVENT_BUS_LOGICAL_ID
60+ )
61+ return eventbus_name ['StackResourceDetail' ]['PhysicalResourceId' ]
62+
63+
64+ ### Events
0 commit comments