Best Python code snippet using localstack_python
apigateway_fixtures.py
Source:apigateway_fixtures.py  
...21        service, config=config, region_name=region_name, aws_access_key_id=aws_access_key_id22    )23def assert_response_status(response: Dict, status: int):24    assert response.get("ResponseMetadata").get("HTTPStatusCode") == status25def assert_response_is_200(response: Dict) -> bool:26    assert_response_status(response, 200)27    return True28def assert_response_is_201(response: Dict) -> bool:29    assert_response_status(response, 201)30    return True31def create_rest_api(apigateway_client, **kwargs):32    response = apigateway_client.create_rest_api(**kwargs)33    assert_response_is_201(response)34    resources = apigateway_client.get_resources(restApiId=response.get("id"))35    root_id = next(item for item in resources["items"] if item["path"] == "/")["id"]36    return response.get("id"), response.get("name"), root_id37def get_rest_apis(apigateway_client, **kwargs):38    response = apigateway_client.get_rest_apis(**kwargs)39    assert_response_is_200(response)40def delete_rest_api(apigateway_client, **kwargs):41    response = apigateway_client.delete_rest_api(**kwargs)42    assert_response_status(response, 202)43def create_rest_resource(apigateway_client, **kwargs):44    response = apigateway_client.create_resource(**kwargs)45    assert_response_is_200(response)46    return response.get("id"), response.get("parentId")47def delete_rest_resource(apigateway_client, **kwargs):48    response = apigateway_client.delete_resource(**kwargs)49    assert_response_is_200(response)50def create_rest_resource_method(apigateway_client, **kwargs):51    response = apigateway_client.put_method(**kwargs)52    assert_response_is_200(response)53    return response.get("httpMethod"), response.get("authorizerId")54def create_rest_authorizer(apigateway_client, **kwargs):55    response = apigateway_client.create_authorizer(**kwargs)56    assert_response_is_200(response)57    return response.get("id"), response.get("type")58def create_rest_api_integration(apigateway_client, **kwargs):59    response = apigateway_client.put_integration(**kwargs)60    assert_response_is_200(response)61    return response.get("uri"), response.get("type")62def delete_rest_api_integration(apigateway_client, **kwargs):63    response = apigateway_client.delete_integration(**kwargs)64    assert_response_is_200(response)65def get_rest_api_integration(apigateway_client, **kwargs):66    response = apigateway_client.get_integration(**kwargs)67    assert_response_is_200(response)68def create_rest_api_method_response(apigateway_client, **kwargs):69    response = apigateway_client.put_method_response(**kwargs)70    assert_response_is_200(response)71    return response.get("statusCode")72def create_rest_api_integration_response(apigateway_client, **kwargs):73    response = apigateway_client.put_integration_response(**kwargs)74    assert_response_is_200(response)75    return response.get("statusCode")76def create_domain_name(apigateway_client, **kwargs):77    response = apigateway_client.create_domain_name(**kwargs)78    assert_response_is_200(response)79def create_base_path_mapping(apigateway_client, **kwargs):80    response = apigateway_client.create_base_path_mapping(**kwargs)81    assert_response_is_200(response)82    return response.get("basePath"), response.get("stage")83def create_rest_api_deployment(apigateway_client, **kwargs):84    response = apigateway_client.create_deployment(**kwargs)85    assert_response_is_200(response)86def create_cognito_user_pool(cognito_idp, **kwargs):87    response = cognito_idp.create_user_pool(**kwargs)88    assert_response_is_200(response)89    return response.get("UserPool").get("Id"), response.get("UserPool").get("Arn")90def delete_cognito_user_pool(cognito_idp, **kwargs):91    response = cognito_idp.delete_user_pool(**kwargs)92    assert_response_is_200(response)93def create_cognito_user_pool_client(cognito_idp, **kwargs):94    response = cognito_idp.create_user_pool_client(**kwargs)95    assert_response_is_200(response)96    return (97        response.get("UserPoolClient").get("ClientId"),98        response.get("UserPoolClient").get("ClientName"),99    )100def create_cognito_user(cognito_idp, **kwargs):101    response = cognito_idp.sign_up(**kwargs)102    assert_response_is_200(response)103def create_cognito_sign_up_confirmation(cognito_idp, **kwargs):104    response = cognito_idp.admin_confirm_sign_up(**kwargs)105    assert_response_is_200(response)106def create_initiate_auth(cognito_idp, **kwargs):107    response = cognito_idp.initiate_auth(**kwargs)108    assert_response_is_200(response)109    return response.get("AuthenticationResult").get("IdToken")110def delete_cognito_user_pool_client(cognito_idp, **kwargs):111    response = cognito_idp.delete_user_pool_client(**kwargs)112    assert_response_is_200(response)113#114# Common utilities115#116class UrlType(Enum):117    HOST_BASED = 0118    PATH_BASED = 1119def api_invoke_url(120    api_id: str, stage: str = "", path: str = "/", url_type: UrlType = UrlType.HOST_BASED121):122    if is_aws_cloud():123        stage = f"/{stage}" if stage else ""124        return f"https://{api_id}.execute-api.{aws_stack.get_boto3_region()}.amazonaws.com{stage}{path}"125    if url_type == UrlType.HOST_BASED:126        return host_based_url(api_id, stage_name=stage, path=path)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
