Best Python code snippet using localstack_python
apigateway.py
Source:apigateway.py  
...106            "name": self._get_swagger_header_name(),107            "in": "header",108            "x-amazon-apigateway-authtype": self._get_swagger_authtype(),109            "x-amazon-apigateway-authorizer": {110                "type": self._get_swagger_authorizer_type()111            }112        }113        if authorizer_type == 'COGNITO_USER_POOLS':114            swagger[APIGATEWAY_AUTHORIZER_KEY]['providerARNs'] = self._get_user_pool_arn_array()115        elif authorizer_type == 'LAMBDA':116            partition = ArnGenerator.get_partition_name()117            resource = 'lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations'118            authorizer_uri = fnSub(ArnGenerator.generate_arn(partition=partition, service='apigateway',119                                   resource=resource, include_account_id=False),120                                   {'__FunctionArn__': self.function_arn})121            swagger[APIGATEWAY_AUTHORIZER_KEY]['authorizerUri'] = authorizer_uri122            reauthorize_every = self._get_reauthorize_every()123            function_invoke_role = self._get_function_invoke_role()124            if reauthorize_every is not None:125                swagger[APIGATEWAY_AUTHORIZER_KEY]['authorizerResultTtlInSeconds'] = reauthorize_every126            if function_invoke_role:127                swagger[APIGATEWAY_AUTHORIZER_KEY]['authorizerCredentials'] = function_invoke_role128            if self._get_function_payload_type() == 'REQUEST':129                swagger[APIGATEWAY_AUTHORIZER_KEY]['identitySource'] = self._get_identity_source()130        # Authorizer Validation Expression is only allowed on COGNITO_USER_POOLS and LAMBDA_TOKEN131        is_lambda_token_authorizer = authorizer_type == 'LAMBDA' and self._get_function_payload_type() == 'TOKEN'132        if authorizer_type == 'COGNITO_USER_POOLS' or is_lambda_token_authorizer:133            identity_validation_expression = self._get_identity_validation_expression()134            if identity_validation_expression:135                swagger[APIGATEWAY_AUTHORIZER_KEY]['identityValidationExpression'] = identity_validation_expression136        return swagger137    def _get_identity_validation_expression(self):138        return self.identity and self.identity.get('ValidationExpression')139    def _get_identity_source(self):140        identity_source_headers = []141        identity_source_query_strings = []142        identity_source_stage_variables = []143        identity_source_context = []144        if self.identity.get('Headers'):145            identity_source_headers = list(map(lambda h: 'method.request.header.' + h, self.identity.get('Headers')))146        if self.identity.get('QueryStrings'):147            identity_source_query_strings = list(map(lambda qs: 'method.request.querystring.' + qs, self.identity.get('QueryStrings')))148        if self.identity.get('StageVariables'):149            identity_source_stage_variables = list(map(lambda sv: 'stageVariables.' + sv, self.identity.get('StageVariables')))150        if self.identity.get('Context'):151            identity_source_context = list(map(lambda c: 'context.' + c, self.identity.get('Context')))152        identity_source_array = identity_source_headers + identity_source_query_strings + identity_source_stage_variables + identity_source_context153        identity_source = ', '.join(identity_source_array)154        return identity_source155    def _get_user_pool_arn_array(self):156        return self.user_pool_arn if isinstance(self.user_pool_arn, list) else [self.user_pool_arn]157    def _get_swagger_header_name(self):158        authorizer_type = self._get_type()159        payload_type = self._get_function_payload_type()160        if authorizer_type == 'LAMBDA' and payload_type == 'REQUEST':161            return 'Unused'162        return self._get_identity_header()163    def _get_type(self):164        if self.user_pool_arn:165            return 'COGNITO_USER_POOLS'166        return 'LAMBDA'167    def _get_identity_header(self):168        if not self.identity or not self.identity.get('Header'):169            return 'Authorization'170        return self.identity.get('Header')171    def _get_reauthorize_every(self):172        if not self.identity:173            return None174        return self.identity.get('ReauthorizeEvery')175    def _get_function_invoke_role(self):176        if not self.function_invoke_role or self.function_invoke_role == 'NONE':177            return None178        return self.function_invoke_role179    def _get_swagger_authtype(self):180        authorizer_type = self._get_type()181        return 'cognito_user_pools' if authorizer_type == 'COGNITO_USER_POOLS' else 'custom'182    def _get_function_payload_type(self):183        return 'TOKEN' if not self.function_payload_type else self.function_payload_type184    def _get_swagger_authorizer_type(self):185        authorizer_type = self._get_type()186        if authorizer_type == 'COGNITO_USER_POOLS':187            return 'cognito_user_pools'188        payload_type = self._get_function_payload_type()189        if payload_type == 'REQUEST':190            return 'request'191        if payload_type == 'TOKEN':...payment.py
Source:payment.py  
1from pos.authorization import authorize_google, authorize_robot, authorize_sms2from pos.data import PaymentStatus3from pos.order import Order4class PaymentProcessor:5    def __init__(self, authorizer_type: str):6        if authorizer_type == "google":7            self.authorize = authorize_google8        elif authorizer_type == "sms":9            self.authorize = authorize_sms10        else:11            self.authorize = authorize_robot12    def pay_debit(self, order: Order) -> None:13        if not self.authorize():14            raise Exception("Not authorized")15        print(f"Processing debit payment for amount: ${(order.total_price / 100):.2f}.")16        order.status = PaymentStatus.PAID17    def pay_credit(self, order: Order, security_code: str) -> None:18        if not self.authorize():19            raise Exception("Not authorized")20        print(21            f"Processing credit payment for amount: ${(order.total_price / 100):.2f}."22        )23        print(f"Verifying security code: {security_code}")24        order.status = PaymentStatus.PAID25    def pay_paypal(self, order: Order, email_address: str) -> None:26        if not self.authorize():27            raise Exception("Not authorized")28        print(29            f"Processing PayPal payment for amount: ${(order.total_price / 100):.2f}."30        )31        print(f"Using email address: {email_address}")...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!!
