How to use create_integration_test_api method in localstack

Best Python code snippet using localstack_python

test_apigateway_integrations.py

Source:test_apigateway_integrations.py Github

copy

Full Screen

...37# integration_action = "arn:aws:apigateway:us-west-2:dynamodb:action/PutItem"38# stage_name = "staging"39#40# create_table(dynamodb, table_name)41# api_id, _ = create_integration_test_api(client, integration_action)42#43# client.create_deployment(restApiId=api_id, stageName=stage_name)44#45# res = requests.put(46# f"https://{api_id}.execute-api.us-west-2.amazonaws.com/{stage_name}",47# json={"TableName": table_name, "Item": {"name": {"S": "the-key"}}},48# )49# res.status_code.should.equal(200)50# res.content.should.equal(b"{}")51#52#53# def test_aws_integration_dynamodb_multiple_stages(apigateway_client):54# if settings.TEST_SERVER_MODE:55# raise SkipTest("Cannot test mock of execute-api.apigateway in ServerMode")56#57# client = boto3.client("apigateway", region_name="us-west-2")58# dynamodb = boto3.client("dynamodb", region_name="us-west-2")59# table_name = "test_1"60# integration_action = "arn:aws:apigateway:us-west-2:dynamodb:action/PutItem"61#62# create_table(dynamodb, table_name)63# api_id, _ = create_integration_test_api(client, integration_action)64#65# client.create_deployment(restApiId=api_id, stageName="dev")66# client.create_deployment(restApiId=api_id, stageName="staging")67#68# res = requests.put(69# f"https://{api_id}.execute-api.us-west-2.amazonaws.com/dev",70# json={"TableName": table_name, "Item": {"name": {"S": "the-key"}}},71# )72# res.status_code.should.equal(200)73#74# res = requests.put(75# f"https://{api_id}.execute-api.us-west-2.amazonaws.com/staging",76# json={"TableName": table_name, "Item": {"name": {"S": "the-key"}}},77# )78# res.status_code.should.equal(200)79#80# # We haven't pushed to prod yet81# res = requests.put(82# f"https://{api_id}.execute-api.us-west-2.amazonaws.com/prod",83# json={"TableName": table_name, "Item": {"name": {"S": "the-key"}}},84# )85# res.status_code.should.equal(400)86#87#88# @mock_apigateway89# @mock_dynamodb90# def test_aws_integration_dynamodb_multiple_resources():91# if settings.TEST_SERVER_MODE:92# raise SkipTest("Cannot test mock of execute-api.apigateway in ServerMode")93#94# client = boto3.client("apigateway", region_name="us-west-2")95# dynamodb = boto3.client("dynamodb", region_name="us-west-2")96# table_name = "test_1"97# create_table(dynamodb, table_name)98#99# # Create API integration to PutItem100# integration_action = "arn:aws:apigateway:us-west-2:dynamodb:action/PutItem"101# api_id, root_id = create_integration_test_api(client, integration_action)102#103# # Create API integration to GetItem104# res = client.create_resource(restApiId=api_id, parentId=root_id, pathPart="item")105# parent_id = res["id"]106# integration_action = "arn:aws:apigateway:us-west-2:dynamodb:action/GetItem"107# api_id, root_id = create_integration_test_api(108# client,109# integration_action,110# api_id=api_id,111# parent_id=parent_id,112# http_method="GET",113# )114#115# client.create_deployment(restApiId=api_id, stageName="dev")116#117# # Put item at the root resource118# res = requests.put(119# f"https://{api_id}.execute-api.us-west-2.amazonaws.com/dev",120# json={121# "TableName": table_name,122# "Item": {"name": {"S": "the-key"}, "attr2": {"S": "sth"}},123# },124# )125# res.status_code.should.equal(200)126#127# # Get item from child resource128# res = requests.get(129# f"https://{api_id}.execute-api.us-west-2.amazonaws.com/dev/item",130# json={"TableName": table_name, "Key": {"name": {"S": "the-key"}}},131# )132# res.status_code.should.equal(200)133# json.loads(res.content).should.equal(134# {"Item": {"name": {"S": "the-key"}, "attr2": {"S": "sth"}}}135# )136#137#138# def create_table(dynamodb, table_name):139# # Create DynamoDB table140# dynamodb.create_table(141# TableName=table_name,142# KeySchema=[{"AttributeName": "name", "KeyType": "HASH"}],143# AttributeDefinitions=[{"AttributeName": "name", "AttributeType": "S"}],144# BillingMode="PAY_PER_REQUEST",145# )146#147#148# def create_integration_test_api(149# client, integration_action, api_id=None, parent_id=None, http_method="PUT"150# ):151# if not api_id:152# # We do not have a root yet - create the API first153# response = client.create_rest_api(name="my_api", description="this is my api")154# api_id = response["id"]155# if not parent_id:156# resources = client.get_resources(restApiId=api_id)157# parent_id = [158# resource for resource in resources["items"] if resource["path"] == "/"159# ][0]["id"]160#161# client.put_method(162# restApiId=api_id,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful