import json import pytest from datetime import datetime from utils.alchemydb_handler import AlchemyDB from aws_testing_utils import lambda_handler, dynamodb_handler, s3_handler as \ s3, sqs_handler, cloudwatch_log_handler as cw, step_function_handler \ as sf_handler # Fixture for Lambda client @pytest.fixture def lambda_client(): return lambda_handler.LambdaHandler() # Fixture for DynamoDB client @pytest.fixture def dynamo_db(): return dynamodb_handler.DynamoDBHandler() @pytest.fixture def current_datetime(): return datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") @pytest.fixture() def alchemy_db(request): db_name = request.param alchemy_session = AlchemyDB(db_name) yield alchemy_session alchemy_session.close_connection() @pytest.fixture def s3_handler(): return s3.S3Handler() @pytest.fixture() def cloudwatch_log_handler(): return cw.CloudwatchLogHandler() @pytest.fixture() def step_function_handler(request): function_name = request.param return sf_handler.StepFunctionHandler(function_name) def shared_order_json(encoding_order, current_datetime): return { 'order_id': f'{encoding_order.encoding_order_id}', 'created_at': f'{current_datetime}', 'priority': encoding_order.priority, 'encoder_id': encoding_order.encoder_id, 'meta_update': encoding_order.meta_update, 'user_id': encoding_order.orchadmin_user_id, } def add_order_json_file_to_s3(s3_handler, encoding_order, current_datetime, product_id, store_id, s3_bucket): base_json = shared_order_json(encoding_order, current_datetime) s3_data = { 'products': [product_id], 'stores': [store_id], 'validated': {f'{product_id}': [store_id]} } s3_data.update(base_json) json_data = json.dumps(s3_data) sub_dir = 'vector3/vector-orders/' file_path = f'{sub_dir}{encoding_order.encoding_order_id}.json' s3_handler.put(s3_bucket, file_path, f'{json_data}') @pytest.fixture def sqs_client(): return sqs_handler.SQSHandler()