How to use test_http_integration method in localstack

Best Python code snippet using localstack_python

test_apigateway_integrations.py

Source:test_apigateway_integrations.py Github

copy

Full Screen

1import pytest2import requests3from localstack.services.apigateway.helpers import path_based_url4@pytest.mark.skip_offline5def test_http_integration(apigateway_client):6 response = apigateway_client.create_rest_api(name="my_api", description="this is my api")7 api_id = response["id"]8 resources = apigateway_client.get_resources(restApiId=api_id)9 root_id = [resource for resource in resources["items"] if resource["path"] == "/"][0]["id"]10 apigateway_client.put_method(11 restApiId=api_id, resourceId=root_id, httpMethod="GET", authorizationType="none"12 )13 apigateway_client.put_method_response(14 restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"15 )16 response = apigateway_client.put_integration(17 restApiId=api_id,18 resourceId=root_id,19 httpMethod="GET",...

Full Screen

Full Screen

Test_http_integration.py

Source:Test_http_integration.py Github

copy

Full Screen

1import pytest2import json3from app import create_app4# python -m pytest -v Test/Integration/Test_http_integration.py5# python -m pytest -v6def login(client):7 payload = {'username': 'stefan', 'password': 'parola'}8 client.post('/auth/login', data=payload, follow_redirects=True)9def in_stock(data, product_name, quantity):10 ok = False11 for product in data['data']:12 if product['product_name'] == product_name and product['quantity'] == quantity:13 ok = True14 return ok15@pytest.fixture16def client():17 """Configures the app for testing18 Sets app config variable ``TESTING`` to ``True``19 :return: App for testing20 """21 # app.config['TESTING'] = True22 local_app = create_app()23 client = local_app.test_client()24 yield client25def test_temperature(client):26 login(client)27 payload = {'value': 1}28 rv = client.post('/temperature/', data=payload, follow_redirects=True)29 res = json.loads(rv.data.decode())30 assert rv.status_code == 20031 assert res["status"] == 'Temperature successfully recorded/retrieved'32 request = client.get("/temperature/", follow_redirects=True)33 data = json.loads(request.data)34 assert request.status_code == 20035 assert data['data']['value'] == 136def test_rgb(client):37 login(client)38 payload = {'red': 100, 'green': 100, 'blue': 100}39 rv = client.post('/rgb/', data=payload, follow_redirects=True)40 res = json.loads(rv.data.decode())41 assert rv.status_code == 20042 assert res["status"] == "RGB successfully recorded/retrieved"43 request = client.get("/rgb/")44 assert request.status_code == 20045 data = json.loads(request.data)46 assert data['data']['red'] == 100 and data['data']['red'] == 100 and data['data']['red'] == 10047def test_holiday(client):48 login(client)49 payload = {'is_away': True, 'days': 10}50 rv = client.post('/holiday/', data=payload, follow_redirects=True)51 res = json.loads(rv.data.decode())52 assert rv.status_code == 20053 assert res["status"] == 'Holiday successfully recorded/retrieved'54 request = client.get("/holiday/")55 assert request.status_code == 20056 data = json.loads(request.data)57 assert data['data']['is_away'] == 'True' and data['data']['days'] == 1058def test_timer(client):59 login(client)60 payload = {'is_closed': True, 'time': 10}61 rv = client.post('/timer/', data=payload, follow_redirects=True)62 res = json.loads(rv.data.decode())63 assert rv.status_code == 20064 assert res["status"] == 'Timer successfully recorded/retrieved'65 request = client.get("/timer/")66 assert request.status_code == 20067 data = json.loads(request.data)68 assert data['data']['is_closed'] == 'True' and data['data']['time'] == 1069def test_stock(client):70 login(client)71 payload = {'product_name': 'aliment1', 'quantity': 1, 'product_expiration_date': "2022-01-31 13:37:24", 'shelf_number': 3}72 rv = client.post('/stock/', data=payload, follow_redirects=True)73 res = json.loads(rv.data.decode())74 assert res["status"] == 'Stock successfully recorded/retrieved'75 request = client.get("/stock/")76 assert request.status_code == 20077 data = json.loads(request.data)78 ok = False79 for product in data['data']:80 if product['product_name'] == 'aliment1' and product['quantity'] == 1:81 ok = True82 assert ok is True83def test_expired(client):84 login(client)85 payload = {'product_name': 'aliment11', 'quantity': 1, 'product_expiration_date': "2022-02-03 13:37:24", 'shelf_number': 3}86 rv = client.post('/stock/', data=payload, follow_redirects=True)87 res = json.loads(rv.data.decode())88 assert res["status"] == 'Stock successfully recorded/retrieved'89 request = client.get("/stock/")90 assert request.status_code == 20091 data = json.loads(request.data)92 assert in_stock(data, 'aliment11', 1) is True93 payload = {'product_name': 'aliment2', 'quantity': 2, 'product_expiration_date': "2022-03-31 13:37:24", 'shelf_number': 3}94 rv = client.post('/stock/', data=payload, follow_redirects=True)95 res = json.loads(rv.data.decode())96 assert res["status"] == 'Stock successfully recorded/retrieved'97 request = client.get("/stock/")98 assert request.status_code == 20099 data = json.loads(request.data)100 assert in_stock(data, 'aliment2', 2) is True101 request = client.get("/stock/expired")102 assert request.status_code == 200103 data = json.loads(request.data)104 # expira in urmatoarele 3 zile105 assert in_stock(data, 'aliment11', 1) is True106 # nu expira in urmatoarele 3 zile...

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