How to use list_stacks method in localstack

Best Python code snippet using localstack_python

app.py

Source:app.py Github

copy

Full Screen

1from flask import Flask, request, make_response, jsonify2from flask_cors import CORS3import re4app = Flask(__name__)5CORS(app)6BASE_URL = r'/rpn/'7list_stacks = {}8def isValidNumber(value):9 """10 Check validity of the number format11 return: True or False12 """13 if type(value) == str:14 regex = re.compile(r'^[0-9]*[.]?[0-9]+$')15 if regex.match(value):16 return True17 else:18 return False19 20 elif type(value) in [int, float]:21 return True22def isOperator(value):23 """24 check if it is a valid operand25 return: True or False26 """27 return (True if (re.match(r'^[+\-*/]$', value) != None) else False)28 29def getAvailableIdStack():30 """31 Get the first id available (not part of list_stack keys)32 output: int id_stack33 """34 id_stack = 035 while id_stack in list_stacks.keys():36 id_stack += 137 return id_stack38 39@app.route(BASE_URL + 'stack', methods=['POST'])40def createNewStack():41 """42 Create a new Stack and add it to the list of stacks43 return: newly created stack44 """45 id = getAvailableIdStack() 46 list_stacks[id] = []47 print(list_stacks)48 return make_response(jsonify({"_id":id,"stack":list_stacks[id]}), 201)49@app.route(BASE_URL + 'stack', methods=['GET'])50def getListStack():51 """52 Retrieve the entire list of stacks53 output: the list of stacks54 """55 result = []56 if len(list_stacks) > 0:57 for key, value in list_stacks.items():58 result.append({"_id":key, "stack":value})59 return make_response (jsonify(result),200)60 61@app.route(BASE_URL + 'stack/<id>', methods=['GET'])62def getStack(id):63 """64 Retrieve and send back the desired stack 65 input : Id of the Stack66 output: the desired stack67 """68 id = int(id)69 if id in list_stacks.keys():70 return make_response(jsonify({"_id": id, "stack": list_stacks[id]}), 200)71 else:72 return make_response('Stack id not defined', 400)73 74@app.route(BASE_URL + '/stack/<id>', methods=['DELETE'])75def deleteStack(id):76 id = int(id)77 if id in list_stacks.keys():78 list_stacks.pop(id)79 print(list_stacks)80 result = []81 if len(list_stacks) > 0:82 for key, value in list_stacks.items():83 result.append({"_id":key, "stack":value})84 return make_response (jsonify(result),200)85 else:86 return make_response("stack {} does not exist".format(id), 400)87@app.route(BASE_URL + 'stack/<id>', methods=['POST'])88def addValue(id):89 id = int(id)90 value = request.json['value']91 if id in list_stacks.keys():92 if isValidNumber(value):93 list_stacks[id].append(float(value))94 print(list_stacks[id])95 return make_response(jsonify({"_id": id, "stack": list_stacks[id]}), 200)96 else:97 return make_response('Error : Input not a number'.format(id), 400)98 else:99 return make_response('Stack {} does not exist'.format(id), 400)100@app.route(BASE_URL + '/op/stack/<id>', methods=['POST'])101def calculate(id):102 id = int(id)103 operator = request.json['operator']104 try: 105 if isOperator(operator):106 if id in list_stacks.keys():107 if len(list_stacks[id]) > 1:108 secondOperand = list_stacks[id].pop()109 firstOperand = list_stacks[id].pop()110 result = eval("{}{}{}".format(str(firstOperand), operator, str(secondOperand)))111 print("{}{}{}".format(str(firstOperand), operator, str(secondOperand)))112 print(result)113 list_stacks[id].append(result)114 print(list_stacks[id])115 return make_response(jsonify({"_id": id, "stack": list_stacks[id]}), 200)116 else:117 return make_response("stack {} does not exist".format(id), 400)118 else:119 return make_response("Operator not valid", 400)120 except ZeroDivisionError:121 return make_response('Error: Division by zero not valid', 400)122if __name__ == "__main__":...

Full Screen

Full Screen

commands.py

Source:commands.py Github

copy

Full Screen

1__author__ = "Sivadon Chaisiri"2__copyright__ = "Copyright (c) 2020 Sivadon Chaisiri"3__license__ = "MIT License"4# internal packages5import sys6# 3rd-party packages7import click8import botocore9# custom packages10from . import _session11from . import list_stacks12from . import list_resources13from . import describe_stack14from . import describe_events15from . import describe_resource16from . import create_stack17from . import update_stack18from . import delete_stack19from . import protect_stack20from . import cost_template21from . import upload_object22from . import hanga_util as util23from . import hanga_constants as const24def _print_version(ctx, param, value):25 if not value or ctx.resilient_parsing:26 return27 click.echo('hanga 0.01')28 ctx.exit()29def _init_profile(ctx, param, value):30 click.echo(value)31 ctx.exit()32@click.group()33@click.option(34 '--version',35 is_flag=True,36 callback=_print_version,37 expose_value=False,38 is_eager=True,39 help='Show hanga version'40)41@click.option(42 '--profile', '-p',43 required=True,44 default=const.DEFAULT_PROFILE,45 help='AWS CLI profile'46)47@click.option(48 '--region', '-r',49 help='Working region'50)51def cli(profile, region):52 try:53 _session._init_session(profile, region) 54 except:55 click.secho(const.ERM_PROFILE_NOTFOUND, bg=const.BG_ERROR, fg=const.FG_ERROR)56 sys.exit(const.ERC_PROFILE_NOTFOUND)57cli.add_command(describe_stack.describe_stack)58cli.add_command(describe_events.describe_events)59cli.add_command(describe_resource.describe_resource)60cli.add_command(list_stacks.list_stacks)61cli.add_command(list_resources.list_resources)62cli.add_command(create_stack.create_stack)63cli.add_command(update_stack.update_stack)64cli.add_command(delete_stack.delete_stack)65cli.add_command(protect_stack.protect_stack)66cli.add_command(cost_template.cost_template)...

Full Screen

Full Screen

test_heat.py

Source:test_heat.py Github

copy

Full Screen

1# Licensed under the Apache License, Version 2.0 (the "License"); you may2# not use this file except in compliance with the License. You may obtain3# a copy of the License at4#5# http://www.apache.org/licenses/LICENSE-2.06#7# Unless required by applicable law or agreed to in writing, software8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the10# License for the specific language governing permissions and limitations11# under the License.12import unittest13import openstack.connection14from ospurge.resources import heat15from ospurge.tests import mock16class TestStacks(unittest.TestCase):17 def setUp(self):18 self.cloud = mock.Mock(spec_set=openstack.connection.Connection)19 self.creds_manager = mock.Mock(cloud=self.cloud)20 def test_list_without_service(self):21 self.cloud.has_service.return_value = False22 self.assertEqual(heat.Stacks(self.creds_manager).list(), [])23 self.cloud.list_stacks.assert_not_called()24 def test_list_with_service(self):25 self.cloud.has_service.return_value = True26 self.assertIs(self.cloud.list_stacks.return_value,27 heat.Stacks(self.creds_manager).list())28 self.cloud.list_stacks.assert_called_once_with()29 def test_delete(self):30 stack = mock.MagicMock()31 self.assertIsNone(heat.Stacks(self.creds_manager).delete(stack))32 self.cloud.delete_stack.assert_called_once_with(stack['id'], wait=True)33 def test_disable(self):34 stack = mock.MagicMock()35 with self.assertLogs(level='WARNING'):36 heat.Stacks(self.creds_manager).disable(stack)37 def test_to_string(self):38 stack = mock.MagicMock()39 self.assertIn("Heat Stack",...

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