Best Python code snippet using localstack_python
test_unit_ServiceApiResourceHandler.py
Source:test_unit_ServiceApiResourceHandler.py  
...450            "restApiId": REST_API_ID451        }452        ServiceApiResourceHandler.api_gateway.put_rest_api.assert_called_once_with(**kwargs)453    @mock.patch.object(ServiceApiResourceHandler, 'api_gateway')454    def test_create_rest_api_deployment(self, *args):455        # Execute456        ServiceApiResourceHandler.create_rest_api_deployment(457            REST_API_ID, 458            SWAGGER_DIGEST)459        # Verify460        kwargs = {461            'restApiId': REST_API_ID,462            'description': SWAGGER_DIGEST,463            'stageName': ServiceApiResourceHandler.STAGE_NAME464        }465        ServiceApiResourceHandler.api_gateway.create_deployment.assert_called_once_with(**kwargs)466    @mock.patch.object(ServiceApiResourceHandler, 'api_gateway')467    @mock.patch.object(ServiceApiResourceHandler, 'get_rest_api_stage_update_patch_operations', return_value = MOCK_PATCH_OPERATIONS)468    def test_update_rest_api_stage_with_patch_operations(self, *args):469        # Setup470        mock_stage = { 'MockStage': '' }...ServiceApiResourceHandler.py
Source:ServiceApiResourceHandler.py  
...136def create_api_gateway(props, swagger_content):137    rest_api_id = import_rest_api(swagger_content)138    try:139        swagger_digest = compute_swagger_digest(swagger_content)140        create_rest_api_deployment(rest_api_id, swagger_digest)141        update_rest_api_stage(rest_api_id, props)142    except:143        delete_rest_api(rest_api_id)144        raise145    return rest_api_id146def update_api_gateway(rest_api_id, props, swagger_content):147    rest_api_deployment_id = get_rest_api_deployment_id(rest_api_id)148    new_swagger_digest = detect_swagger_changes(rest_api_id, rest_api_deployment_id, swagger_content)149    if new_swagger_digest:150        put_rest_api(rest_api_id, swagger_content)151        create_rest_api_deployment(rest_api_id, new_swagger_digest)152    update_rest_api_stage(rest_api_id, props)153def delete_api_gateway(rest_api_id):154    delete_rest_api(rest_api_id)155def delete_rest_api(rest_api_id):156    res = api_gateway.delete_rest_api(restApiId = rest_api_id)157def detect_swagger_changes(rest_api_id, rest_api_deployment_id, swagger_content):158    new_digest = compute_swagger_digest(swagger_content)159    old_digest = get_rest_api_deployment_swagger_digest(rest_api_id, rest_api_deployment_id)160    if new_digest == old_digest:161        return None162    else:163        return new_digest164def compute_swagger_digest(swagger_content):165    return hashlib.sha224(swagger_content).hexdigest()166def get_rest_api_deployment_swagger_digest(rest_api_id, rest_api_deployment_id):167    168    kwargs = {169        'restApiId': rest_api_id, 170        'deploymentId': rest_api_deployment_id171    }172    res = api_gateway.get_deployment(**kwargs)173    return res.get('description', '')174        175def import_rest_api(swagger_content):176    kwargs = {177        'failOnWarnings': True,178        'body': swagger_content179    }180    res = api_gateway.import_rest_api(**kwargs)181    return res['id']182def put_rest_api(rest_api_id, swagger_content):183    kwargs = {184        'failOnWarnings': True,185        'restApiId': rest_api_id,186        'mode': 'overwrite',187        'body': swagger_content188    }189    res = api_gateway.put_rest_api(**kwargs)190def create_rest_api_deployment(rest_api_id, swagger_digest):191    kwargs = {192        'restApiId': rest_api_id,193        'stageName': STAGE_NAME,194        'description': swagger_digest195    }196    res = api_gateway.create_deployment(**kwargs)197def update_rest_api_stage(rest_api_id, props):198    kwargs = {199        'restApiId': rest_api_id,200        'stageName': STAGE_NAME,201    }202    current_stage = api_gateway.get_stage(**kwargs)203    patch_operations = get_rest_api_stage_update_patch_operations(current_stage, props)204    ...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!!
