How to use import_rest_api method in localstack

Best Python code snippet using localstack_python

api_test.py

Source:api_test.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from unittest import TestCase3from nose.tools import eq_4from mock import Mock5from lamvery.actions.api import (6 ApiAction,7 DEFAULT_MAPPING_TEMPLATE8)9def default_args():10 args = Mock()11 args.conf_file = '.lamvery.yml'12 args.dry_run = False13 args.no_integrate = False14 args.remove = False15 args.write_id = True16 args.stage = None17 return args18class ApiActionTestCase(TestCase):19 def test_get_stage_name(self):20 args = default_args()21 api = ApiAction(args)22 eq_(api.get_stage_name(), 'dev')23 args = default_args()24 args.stage = 'prod'25 api = ApiAction(args)26 eq_(api.get_stage_name(), 'prod')27 def test_get_cors(self):28 args = default_args()29 api = ApiAction(args)30 eq_(api.get_cors().get('origin'), "'*'")31 def test_action(self):32 args = default_args()33 api = ApiAction(args)34 api._config.save_api_id = Mock()35 api._get_client = Mock()36 api._apply_api = Mock(37 return_value={'id': 'foo', 'name': 'bar', 'description': 'baz'})38 api._deploy = Mock(39 return_value={'id': 'foo', 'apiSummary': 'bar', 'description': 'baz'})40 api._get_remote_configuration = Mock(return_value={})41 api.action()42 def test_add_permissions(self):43 args = default_args()44 api = ApiAction(args)45 api._get_client = Mock()46 api._add_permissions('foo', {'paths': {'/': {'get': {'bar': 'baz'}}}})47 def test_get_remote_configuration(self):48 args = default_args()49 api = ApiAction(args)50 m = Mock()51 m.get_export = Mock(return_value={'foo': 'bar'})52 eq_(api._get_remote_configuration(m, 'baz', 'qux'), {'foo': 'bar'})53 def test_integrate_aws(self):54 args = default_args()55 api = ApiAction(args)56 api._get_client = Mock()57 ret = api._integrate_aws(58 {'paths': {'/': {'get': {'responses': {'get': {'foo': 'bar'}}}}}, 'info': {}},59 'baz',60 {'methods': "'GET,OPTION'", 'headers': 'foo,bar', 'origin': "'*'"})61 eq_(62 ret['paths']['/']['get']['x-amazon-apigateway-integration']['requestTemplates'],63 {'application/json': DEFAULT_MAPPING_TEMPLATE})64 eq_(ret['basePath'], '/baz')65 def test_generate_method_cors(self):66 args = default_args()67 api = ApiAction(args)68 eq_(69 api._generate_method_cors({'origin': "'*'"}),70 {71 'method.response.header.Access-Control-Allow-Origin': "'*'"72 })73 def test_generate_option_cors(self):74 args = default_args()75 api = ApiAction(args)76 ret = api._generate_option_cors(77 {'methods': "'GET,OPTION'", 'headers': "'foo,bar'", 'origin': "'*'"})78 eq_(79 ret['x-amazon-apigateway-integration']['responses']['default']['responseParameters'],80 {81 'method.response.header.Access-Control-Allow-Methods': "'GET,OPTION'",82 'method.response.header.Access-Control-Allow-Headers': "'foo,bar'",83 'method.response.header.Access-Control-Allow-Origin': "'*'"84 })85 def test_apply_api(self):86 args = default_args()87 api = ApiAction(args)88 c = Mock()89 c.import_rest_api = Mock(return_value='import_rest_api')90 c.put_rest_api = Mock(return_value='put_rest_api')91 c.get_rest_api = Mock(return_value=None)92 eq_(api._apply_api(c, 'baz', {'foo': 'bar'}), 'import_rest_api')93 c.get_rest_api = Mock(return_value='baz')94 eq_(api._apply_api(c, 'baz', {'foo': 'bar'}), 'put_rest_api')95 args = default_args()96 args.remove = True97 api = ApiAction(args)98 c.get_rest_api = Mock(return_value=None)99 eq_(api._apply_api(c, 'baz', {'foo': 'bar'}), None)100 c.get_rest_api = Mock(return_value='baz')101 eq_(api._apply_api(c, 'baz', {'foo': 'bar'}), None)102 def test_print_apply_result(self):103 args = default_args()104 api = ApiAction(args)105 api._print_apply_result({106 'id': 'foo',107 'name': 'bar',108 'description': 'baz',109 'warnings': ['qux']})110 def test_deploy(self):111 args = default_args()112 api = ApiAction(args)113 c = Mock()114 c.create_deployment = Mock(return_value='foo')115 eq_(api._deploy(c, 'bar', 'baz'), 'foo')116 def test_print_deploy_result(self):117 args = default_args()118 api = ApiAction(args)119 api._print_deploy_result({120 'id': 'foo',121 'apiSummary': 'bar',122 'description': 'baz'})123 def test_print_conf_diff(self):124 args = default_args()125 api = ApiAction(args)...

Full Screen

Full Screen

imports.py

Source:imports.py Github

copy

Full Screen

1from django.contrib.auth import get_user_model2import os3import json4import requests5from iamport import Iamport6from rest_framework.response import Response7from rest_framework import status8Order = get_user_model()9class Import(object):10 def get_permissin(self):11 imp_key = os.environ.get("IMPORT_REST_API")12 imp_secret = os.environ.get("IMPORT_REST_API_SECRET")13 # print(imp_key, imp_secret)14 api_url = "https://api.iamport.kr/users/getToken"15 headers = {16 "Content-Type": "application/json",17 }18 body = {"imp_key": imp_key, "imp_secret": imp_secret}19 body = json.dumps(body)20 getToken = requests.post(api_url, headers=headers, data=body)21 getToken_json = getToken.json()22 if getToken_json["code"] == 0:23 return getToken_json["response"]24 else:25 return False26 def get_payment(merchant_uid):27 merchant_uid = merchant_uid28 imp_key = os.environ.get("IMPORT_REST_API")29 imp_secret = os.environ.get("IMPORT_REST_API_SECRET")30 iamport = Iamport(imp_key=imp_key, imp_secret=imp_secret)31 response = iamport.find(merchant_uid=merchant_uid)32 print(response)33 return response34 # api_url = "https://api.iamport.kr/payment/" + imp_uid35 # headers = {36 # "Content-Type": "application/json; charset=UTF-8",37 # "Authorization": "timestamp",38 # }39 # sms_requests = requests.post(api_url, headers=headers)40 # sms_json = sms_requests.json()41 # print(sms_json)42 # if sms_json["statusCode"] == "202":...

Full Screen

Full Screen

apigateway.py

Source:apigateway.py Github

copy

Full Screen

...24 parameters={'extensions': 'integrations'})25 return json.loads(ret['body'].read())26 except botocore.exceptions.ClientError:27 return {}28 def import_rest_api(self, api_conf):29 return self._api.import_rest_api(body=json.dumps(api_conf))30 def put_rest_api(self, api_id, api_conf):31 return self._api.put_rest_api(32 restApiId=api_id,33 mode='overwrite',34 body=json.dumps(api_conf))35 def delete_rest_api(self, api_id):36 self._api.delete_rest_api(api_id)37 def create_deployment(self, api_id, stage):38 return self._api.create_deployment(39 restApiId=api_id,...

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