How to use tmp_http_server method in localstack

Best Python code snippet using localstack_python

test_cloudformation_apigateway.py

Source:test_cloudformation_apigateway.py Github

copy

Full Screen

1import os.path2import pytest3from localstack import constants4from localstack.utils.common import short_uid5def test_cfn_apigateway_aws_integration(6 apigateway_client, s3_client, iam_client, deploy_cfn_template7):8 api_name = f"rest-api-{short_uid()}"9 deploy_cfn_template(10 template_path=os.path.join(11 os.path.dirname(__file__), "../templates/apigw-awsintegration-request-parameters.yaml"12 ),13 template_mapping={"api_name": api_name},14 )15 # check resources creation16 apis = [api for api in apigateway_client.get_rest_apis()["items"] if api["name"] == api_name]17 assert len(apis) == 118 api_id = apis[0]["id"]19 # check resources creation20 resources = apigateway_client.get_resources(restApiId=api_id)["items"]21 assert (22 resources[0]["resourceMethods"]["GET"]["requestParameters"]["method.request.path.id"]23 is False24 )25 assert (26 resources[0]["resourceMethods"]["GET"]["methodIntegration"]["requestParameters"][27 "integration.request.path.object"28 ]29 == "method.request.path.id"30 )31 # check domains creation32 domain_names = [33 domain["domainName"] for domain in apigateway_client.get_domain_names()["items"]34 ]35 expected_domain = "cfn5632.localstack.cloud" # hardcoded value from template yaml file36 assert expected_domain in domain_names37 # check basepath mappings creation38 mappings = [39 mapping["basePath"]40 for mapping in apigateway_client.get_base_path_mappings(domainName=expected_domain)["items"]41 ]42 assert len(mappings) == 143 assert mappings[0] == "(none)"44@pytest.mark.only_localstack45def test_url_output(apigateway_client, tmp_http_server, deploy_cfn_template):46 test_port, invocations, proxy = tmp_http_server47 integration_uri = f"http://localhost:{test_port}/{{proxy}}"48 api_name = f"rest-api-{short_uid()}"49 stack = deploy_cfn_template(50 template_path=os.path.join(51 os.path.dirname(__file__), "../templates/apigateway-url-output.yaml"52 ),53 template_mapping={54 "api_name": api_name,55 "integration_uri": integration_uri,56 },57 )58 assert len(stack.outputs) == 259 api_id = stack.outputs["ApiV1IdOutput"]60 api_url = stack.outputs["ApiV1UrlOutput"]61 assert api_id62 assert api_url63 assert api_id in api_url...

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