How to use connect_api_gateway_to_s3 method in localstack

Best Python code snippet using localstack_python

test_api_gateway.py

Source:test_api_gateway.py Github

copy

Full Screen

...1109 Key=object_name,1110 Body=object_content,1111 ContentType=object_content_type,1112 )1113 self.connect_api_gateway_to_s3(bucket_name, object_name, api_id, "GET")1114 apigw_client.create_deployment(restApiId=api_id, stageName="test")1115 url = gateway_request_url(api_id, "test", "/")1116 result = requests.get(url)1117 self.assertEqual(200, result.status_code)1118 self.assertEqual(object_content, result.text)1119 self.assertEqual(object_content_type, result.headers["content-type"])1120 # clean up1121 apigw_client.delete_rest_api(restApiId=api_id)1122 s3_client.delete_object(Bucket=bucket_name, Key=object_name)1123 s3_client.delete_bucket(Bucket=bucket_name)1124 def test_api_mock_integration_response_params(self):1125 # apigw_client = aws_stack.connect_to_service('apigateway')1126 resps = [1127 {1128 "statusCode": "204",1129 "httpMethod": "OPTIONS",1130 "responseParameters": {1131 "method.response.header.Access-Control-Allow-Methods": "'POST,OPTIONS'",1132 "method.response.header.Vary": "'Origin'",1133 },1134 }1135 ]1136 api_id = self.create_api_gateway_and_deploy(1137 integration_type="MOCK", integration_responses=resps1138 )1139 url = gateway_request_url(api_id=api_id, stage_name=self.TEST_STAGE_NAME, path="/")1140 result = requests.options(url)1141 self.assertLess(result.status_code, 400)1142 self.assertEqual("Origin", result.headers.get("vary"))1143 self.assertEqual("POST,OPTIONS", result.headers.get("Access-Control-Allow-Methods"))1144 # =====================================================================1145 # Helper methods1146 # =====================================================================1147 def connect_api_gateway_to_s3(self, bucket_name, file_name, api_id, method):1148 """Connects the root resource of an api gateway to the given object of an s3 bucket."""1149 apigw_client = aws_stack.connect_to_service("apigateway")1150 s3_uri = "arn:aws:apigateway:{}:s3:path/{}/{}".format(1151 aws_stack.get_region(), bucket_name, file_name1152 )1153 test_role = "test-s3-role"1154 role_arn = aws_stack.role_arn(role_name=test_role)1155 resources = apigw_client.get_resources(restApiId=api_id)1156 # using the root resource '/' directly for this test1157 root_resource_id = resources["items"][0]["id"]1158 apigw_client.put_method(1159 restApiId=api_id,1160 resourceId=root_resource_id,1161 httpMethod=method,...

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