def product(get_product, products_table_name): """ Product """ table = boto3.resource("dynamodb").Table(products_table_name) # pylint: disable=no-member product = get_product() table.put_item(Item=product) yield product table.delete_item(Key={"productId": product["productId"]})
def products(product_table_name, get_product): """ Create fake products """ table = boto3.resource("dynamodb").Table(product_table_name) # pylint: disable=no-member products = [get_product() for _ in range(3)] for product in products: table.put_item(Item=product) yield products for product in products: table.delete_item(Key={"productId": product["productId"]})
def test_create_order_fail_products(function_arn, table_name, order_request, get_product): """ Test the CreateOrder function """ order_request = copy.deepcopy(order_request) order_request["order"]["products"] = [get_product()] lambda_ = boto3.client("lambda") # Trigger the function response = lambda_.invoke(FunctionName=function_arn, InvocationType="RequestResponse", Payload=json.dumps(order_request).encode()) response = json.load(response["Payload"]) print(response) # Check the output of the Function assert response["success"] == False assert len(response.get("errors", [])) > 0
def _get_product(): product = get_product() product["quantity"] = random.randint(1, 10) return product