Best Python code snippet using localstack_python
models.py
Source:models.py
...361 api_id = create_id()362 rest_api = RestAPI(api_id, self.region_name, name, description)363 self.apis[api_id] = rest_api364 return rest_api365 def get_rest_api(self, function_id):366 rest_api = self.apis[function_id]367 return rest_api368 def list_apis(self):369 return self.apis.values()370 def delete_rest_api(self, function_id):371 rest_api = self.apis.pop(function_id)372 return rest_api373 def list_resources(self, function_id):374 api = self.get_rest_api(function_id)375 return api.resources.values()376 def get_resource(self, function_id, resource_id):377 api = self.get_rest_api(function_id)378 resource = api.resources[resource_id]379 return resource380 def create_resource(self, function_id, parent_resource_id, path_part):381 api = self.get_rest_api(function_id)382 child = api.add_child(383 path=path_part,384 parent_id=parent_resource_id,385 )386 return child387 def delete_resource(self, function_id, resource_id):388 api = self.get_rest_api(function_id)389 resource = api.resources.pop(resource_id)390 return resource391 def get_method(self, function_id, resource_id, method_type):392 resource = self.get_resource(function_id, resource_id)393 return resource.get_method(method_type)394 def create_method(self, function_id, resource_id, method_type, authorization_type):395 resource = self.get_resource(function_id, resource_id)396 method = resource.add_method(method_type, authorization_type)397 return method398 def get_stage(self, function_id, stage_name):399 api = self.get_rest_api(function_id)400 stage = api.stages.get(stage_name)401 if stage is None:402 raise StageNotFoundException()403 else:404 return stage405 def get_stages(self, function_id):406 api = self.get_rest_api(function_id)407 return api.get_stages()408 def create_stage(self, function_id, stage_name, deploymentId,409 variables=None, description='', cacheClusterEnabled=None, cacheClusterSize=None):410 if variables is None:411 variables = {}412 api = self.get_rest_api(function_id)413 api.create_stage(stage_name, deploymentId, variables=variables,414 description=description, cacheClusterEnabled=cacheClusterEnabled, cacheClusterSize=cacheClusterSize)415 return api.stages.get(stage_name)416 def update_stage(self, function_id, stage_name, patch_operations):417 stage = self.get_stage(function_id, stage_name)418 if not stage:419 api = self.get_rest_api(function_id)420 stage = api.stages[stage_name] = Stage()421 return stage.apply_operations(patch_operations)422 def get_method_response(self, function_id, resource_id, method_type, response_code):423 method = self.get_method(function_id, resource_id, method_type)424 method_response = method.get_response(response_code)425 return method_response426 def create_method_response(self, function_id, resource_id, method_type, response_code):427 method = self.get_method(function_id, resource_id, method_type)428 method_response = method.create_response(response_code)429 return method_response430 def delete_method_response(self, function_id, resource_id, method_type, response_code):431 method = self.get_method(function_id, resource_id, method_type)432 method_response = method.delete_response(response_code)433 return method_response434 def create_integration(self, function_id, resource_id, method_type, integration_type, uri,435 request_templates=None):436 resource = self.get_resource(function_id, resource_id)437 integration = resource.add_integration(method_type, integration_type, uri,438 request_templates=request_templates)439 return integration440 def get_integration(self, function_id, resource_id, method_type):441 resource = self.get_resource(function_id, resource_id)442 return resource.get_integration(method_type)443 def delete_integration(self, function_id, resource_id, method_type):444 resource = self.get_resource(function_id, resource_id)445 return resource.delete_integration(method_type)446 def create_integration_response(self, function_id, resource_id, method_type, status_code, selection_pattern):447 integration = self.get_integration(448 function_id, resource_id, method_type)449 integration_response = integration.create_integration_response(450 status_code, selection_pattern)451 return integration_response452 def get_integration_response(self, function_id, resource_id, method_type, status_code):453 integration = self.get_integration(454 function_id, resource_id, method_type)455 integration_response = integration.get_integration_response(456 status_code)457 return integration_response458 def delete_integration_response(self, function_id, resource_id, method_type, status_code):459 integration = self.get_integration(460 function_id, resource_id, method_type)461 integration_response = integration.delete_integration_response(462 status_code)463 return integration_response464 def create_deployment(self, function_id, name, description="", stage_variables=None):465 if stage_variables is None:466 stage_variables = {}467 api = self.get_rest_api(function_id)468 deployment = api.create_deployment(name, description, stage_variables)469 return deployment470 def get_deployment(self, function_id, deployment_id):471 api = self.get_rest_api(function_id)472 return api.get_deployment(deployment_id)473 def get_deployments(self, function_id):474 api = self.get_rest_api(function_id)475 return api.get_deployments()476 def delete_deployment(self, function_id, deployment_id):477 api = self.get_rest_api(function_id)478 return api.delete_deployment(deployment_id)479 def create_apikey(self, payload):480 key = ApiKey(**payload)481 self.keys[key['id']] = key482 return key483 def get_apikeys(self):484 return list(self.keys.values())485 def get_apikey(self, api_key_id):486 return self.keys[api_key_id]487 def delete_apikey(self, api_key_id):488 self.keys.pop(api_key_id)489 return {}490 def create_usage_plan(self, payload):491 plan = UsagePlan(**payload)...
apigateway_test.py
Source:apigateway_test.py
...7class ApiGatewayClientTestCase(TestCase):8 def setUp(self):9 self.client = ApiGatewayClient(region='us-east-1')10 self.client._api = Mock()11 def test_get_rest_api(self):12 self.client._api.get_rest_api = Mock(return_value={'foo': 'bar'})13 eq_(self.client.get_rest_api(None), None)14 eq_(self.client.get_rest_api('baz'), {'foo': 'bar'})15 self.client._api.get_rest_api = Mock(16 side_effect=botocore.exceptions.ClientError({'Error': {}}, 'bar'))17 eq_(self.client.get_rest_api('baz'), None)18 def test_get_export(self):19 m = Mock()20 m.read = Mock(return_value='{"foo": "bar"}')21 self.client._api.get_export = Mock(return_value={'body': m})22 eq_(self.client.get_export(None, 'baz'), {})23 eq_(self.client.get_export('baz', 'qux'), {'foo': 'bar'})24 self.client._api.get_export = Mock(25 side_effect=botocore.exceptions.ClientError({'Error': {}}, 'bar'))26 eq_(self.client.get_export('baz', 'qux'), {})27 def test_import_rest_api(self):28 self.client._api.import_rest_api = Mock(return_value={'foo': 'bar'})29 eq_(self.client.import_rest_api({'baz': 'qux'}), {'foo': 'bar'})30 def test_put_rest_api(self):31 self.client._api.put_rest_api = Mock(return_value={'foo': 'bar'})...
app.py
Source:app.py
...12 # init singletons13 get_flask_app()14 get_flask_app().config.from_object(config)15 get_database()16 get_rest_api()17 get_jwt()1819 cors = CORS(get_flask_app(), resources={r"/api/*": {"origins": "*"}})2021 init_admin()2223 #24 for url in urls:25 get_rest_api().add_resource(url[0], url[1])26
...
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!!