How to use get_documentation_parts method in localstack

Best Python code snippet using localstack_python

test_features.py

Source:test_features.py Github

copy

Full Screen

...188def test_single_doc_mapped_in_api(smoke_test_app, apig_client):189 # We'll use the same API Gateway technique as in190 # test_path_params_mapped_in_api()191 rest_api_id = smoke_test_app.rest_api_id192 doc_parts = apig_client.get_documentation_parts(193 restApiId=rest_api_id,194 type='METHOD',195 path='/singledoc'196 )197 doc_props = json.loads(doc_parts['items'][0]['properties'])198 assert 'summary' in doc_props199 assert 'description' not in doc_props200 assert doc_props['summary'] == 'Single line docstring.'201def test_multi_doc_mapped_in_api(smoke_test_app, apig_client):202 # We'll use the same API Gateway technique as in203 # test_path_params_mapped_in_api()204 rest_api_id = smoke_test_app.rest_api_id205 doc_parts = apig_client.get_documentation_parts(206 restApiId=rest_api_id,207 type='METHOD',208 path='/multidoc'209 )210 doc_props = json.loads(doc_parts['items'][0]['properties'])211 assert 'summary' in doc_props212 assert 'description' in doc_props213 assert doc_props['summary'] == 'Multi-line docstring.'214 assert doc_props['description'] == 'And here is another line.'215@retry(max_attempts=18, delay=10)216def _get_resource_id(apig_client, rest_api_id, path):217 # This is the resource id for the '/path/{name}'218 # route. As far as I know this is the best way to get219 # this id....

Full Screen

Full Screen

test_apigateway.py

Source:test_apigateway.py Github

copy

Full Screen

1"""2awslimitchecker/tests/services/test_apigateway.py3The latest version of this package is available at:4<https://github.com/jantman/awslimitchecker>5################################################################################6Copyright 2015-2018 Jason Antman <jason@jasonantman.com>7 This file is part of awslimitchecker, also known as awslimitchecker.8 awslimitchecker is free software: you can redistribute it and/or modify9 it under the terms of the GNU Affero General Public License as published by10 the Free Software Foundation, either version 3 of the License, or11 (at your option) any later version.12 awslimitchecker is distributed in the hope that it will be useful,13 but WITHOUT ANY WARRANTY; without even the implied warranty of14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 GNU Affero General Public License for more details.16 You should have received a copy of the GNU Affero General Public License17 along with awslimitchecker. If not, see <http://www.gnu.org/licenses/>.18The Copyright and Authors attributions contained herein may not be removed or19otherwise altered, except to add the Author attribution of a contributor to20this work. (Additional Terms pursuant to Section 7b of the AGPL v3)21################################################################################22While not legally required, I sincerely request that anyone who finds23bugs please submit them at <https://github.com/jantman/awslimitchecker> or24to me via email, and that you send any contributions or improvements25either as a pull request on GitHub, or to me via email.26################################################################################27AUTHORS:28Jason Antman <jason@jasonantman.com> <http://www.jasonantman.com>29################################################################################30"""31import sys32from copy import deepcopy33from awslimitchecker.tests.services import result_fixtures34from awslimitchecker.services.apigateway import _ApigatewayService35# https://code.google.com/p/mock/issues/detail?id=24936# py>=3.4 should use unittest.mock not the mock package on pypi37if (38 sys.version_info[0] < 3 or39 sys.version_info[0] == 3 and sys.version_info[1] < 440):41 from mock import patch, call, Mock, DEFAULT42else:43 from unittest.mock import patch, call, Mock, DEFAULT44pbm = 'awslimitchecker.services.apigateway' # module patch base45pb = '%s._ApigatewayService' % pbm # class patch pase46class Test_ApigatewayService(object):47 def test_init(self):48 """test __init__()"""49 cls = _ApigatewayService(21, 43)50 assert cls.service_name == 'ApiGateway'51 assert cls.api_name == 'apigateway'52 assert cls.conn is None53 assert cls.warning_threshold == 2154 assert cls.critical_threshold == 4355 def test_get_limits(self):56 cls = _ApigatewayService(21, 43)57 cls.limits = {}58 res = cls.get_limits()59 assert sorted(res.keys()) == sorted([60 'API keys per account',61 'APIs per account',62 'Client certificates per account',63 'Custom authorizers per API',64 'Documentation parts per API',65 'Resources per API',66 'Stages per API',67 'Usage plans per account'68 ])69 for name, limit in res.items():70 assert limit.service == cls71 assert limit.def_warning_threshold == 2172 assert limit.def_critical_threshold == 4373 def test_get_limits_again(self):74 """test that existing limits dict is returned on subsequent calls"""75 mock_limits = Mock()76 cls = _ApigatewayService(21, 43)77 cls.limits = mock_limits78 res = cls.get_limits()79 assert res == mock_limits80 def test_find_usage(self):81 mock_conn = Mock()82 with patch('%s.connect' % pb) as mock_connect:83 with patch.multiple(84 pb,85 autospec=True,86 _find_usage_apis=DEFAULT,87 _find_usage_api_keys=DEFAULT,88 _find_usage_certs=DEFAULT,89 _find_usage_plans=DEFAULT90 ) as mocks:91 cls = _ApigatewayService(21, 43)92 cls.conn = mock_conn93 assert cls._have_usage is False94 cls.find_usage()95 assert mock_connect.mock_calls == [call()]96 assert cls._have_usage is True97 assert mock_conn.mock_calls == []98 assert mocks['_find_usage_apis'].mock_calls == [call(cls)]99 assert mocks['_find_usage_api_keys'].mock_calls == [call(cls)]100 assert mocks['_find_usage_certs'].mock_calls == [call(cls)]101 assert mocks['_find_usage_plans'].mock_calls == [call(cls)]102 def test_find_usage_apis(self):103 mock_conn = Mock()104 res = result_fixtures.ApiGateway.get_rest_apis105 mock_paginator = Mock()106 mock_paginator.paginate.return_value = res107 def se_res_paginate(restApiId=None):108 return result_fixtures.ApiGateway.get_resources[restApiId]109 mock_res_paginator = Mock()110 mock_res_paginator.paginate.side_effect = se_res_paginate111 def se_get_paginator(api_name):112 if api_name == 'get_rest_apis':113 return mock_paginator114 elif api_name == 'get_resources':115 return mock_res_paginator116 def se_paginate_dict(*args, **kwargs):117 if args[0] == mock_conn.get_documentation_parts:118 return result_fixtures.ApiGateway.doc_parts[kwargs['restApiId']]119 if args[0] == mock_conn.get_authorizers:120 return result_fixtures.ApiGateway.authorizers[121 kwargs['restApiId']122 ]123 def se_get_stages(restApiId=None):124 return result_fixtures.ApiGateway.stages[restApiId]125 mock_conn.get_paginator.side_effect = se_get_paginator126 mock_conn.get_stages.side_effect = se_get_stages127 cls = _ApigatewayService(21, 43)128 cls.conn = mock_conn129 with patch('%s.paginate_dict' % pbm, autospec=True) as mock_pd:130 with patch('%s.logger' % pbm) as mock_logger:131 mock_pd.side_effect = se_paginate_dict132 cls._find_usage_apis()133 # APIs usage134 usage = cls.limits['APIs per account'].get_current_usage()135 assert len(usage) == 1136 assert usage[0].get_value() == 3137 # Resources usage138 usage = cls.limits['Resources per API'].get_current_usage()139 assert len(usage) == 3140 assert usage[0].resource_id == 'api3'141 assert usage[0].get_value() == 0142 assert usage[1].resource_id == 'api2'143 assert usage[1].get_value() == 2144 assert usage[2].resource_id == 'api1'145 assert usage[2].get_value() == 3146 usage = cls.limits['Documentation parts per API'].get_current_usage()147 assert len(usage) == 3148 assert usage[0].resource_id == 'api3'149 assert usage[0].get_value() == 2150 assert usage[1].resource_id == 'api2'151 assert usage[1].get_value() == 1152 assert usage[2].resource_id == 'api1'153 assert usage[2].get_value() == 4154 usage = cls.limits['Stages per API'].get_current_usage()155 assert len(usage) == 3156 assert usage[0].resource_id == 'api3'157 assert usage[0].get_value() == 2158 assert usage[1].resource_id == 'api2'159 assert usage[1].get_value() == 1160 assert usage[2].resource_id == 'api1'161 assert usage[2].get_value() == 3162 usage = cls.limits['Custom authorizers per API'].get_current_usage()163 assert len(usage) == 3164 assert usage[0].resource_id == 'api3'165 assert usage[0].get_value() == 0166 assert usage[1].resource_id == 'api2'167 assert usage[1].get_value() == 2168 assert usage[2].resource_id == 'api1'169 assert usage[2].get_value() == 1170 assert mock_conn.mock_calls == [171 call.get_paginator('get_rest_apis'),172 call.get_paginator('get_resources'),173 call.get_stages(restApiId='api3'),174 call.get_paginator('get_resources'),175 call.get_stages(restApiId='api2'),176 call.get_paginator('get_resources'),177 call.get_stages(restApiId='api1')178 ]179 assert mock_paginator.mock_calls == [call.paginate()]180 assert mock_res_paginator.mock_calls == [181 call.paginate(restApiId='api3'),182 call.paginate(restApiId='api2'),183 call.paginate(restApiId='api1')184 ]185 assert mock_pd.mock_calls == [186 call(187 mock_conn.get_documentation_parts,188 restApiId='api3',189 alc_marker_path=['position'],190 alc_data_path=['items'],191 alc_marker_param='position'192 ),193 call(194 mock_conn.get_authorizers,195 restApiId='api3',196 alc_marker_path=['position'],197 alc_data_path=['items'],198 alc_marker_param='position'199 ),200 call(201 mock_conn.get_documentation_parts,202 restApiId='api2',203 alc_marker_path=['position'],204 alc_data_path=['items'],205 alc_marker_param='position'206 ),207 call(208 mock_conn.get_authorizers,209 restApiId='api2',210 alc_marker_path=['position'],211 alc_data_path=['items'],212 alc_marker_param='position'213 ),214 call(215 mock_conn.get_documentation_parts,216 restApiId='api1',217 alc_marker_path=['position'],218 alc_data_path=['items'],219 alc_marker_param='position'220 ),221 call(222 mock_conn.get_authorizers,223 restApiId='api1',224 alc_marker_path=['position'],225 alc_data_path=['items'],226 alc_marker_param='position'227 ),228 ]229 assert mock_logger.mock_calls == [230 call.debug('Finding usage for APIs'),231 call.debug('Found %d APIs', 3),232 call.debug('Finding usage for per-API limits')233 ]234 def test_find_usage_apis_stages_now_paginated(self):235 mock_conn = Mock()236 res = result_fixtures.ApiGateway.get_rest_apis237 mock_paginator = Mock()238 mock_paginator.paginate.return_value = res239 def se_res_paginate(restApiId=None):240 return result_fixtures.ApiGateway.get_resources[restApiId]241 mock_res_paginator = Mock()242 mock_res_paginator.paginate.side_effect = se_res_paginate243 def se_get_paginator(api_name):244 if api_name == 'get_rest_apis':245 return mock_paginator246 elif api_name == 'get_resources':247 return mock_res_paginator248 def se_paginate_dict(*args, **kwargs):249 if args[0] == mock_conn.get_documentation_parts:250 return result_fixtures.ApiGateway.doc_parts[kwargs['restApiId']]251 if args[0] == mock_conn.get_authorizers:252 return result_fixtures.ApiGateway.authorizers[253 kwargs['restApiId']254 ]255 def se_get_stages(restApiId=None):256 r = deepcopy(result_fixtures.ApiGateway.stages[restApiId])257 r['position'] = 'foo'258 return r259 mock_conn.get_paginator.side_effect = se_get_paginator260 mock_conn.get_stages.side_effect = se_get_stages261 cls = _ApigatewayService(21, 43)262 cls.conn = mock_conn263 with patch('%s.paginate_dict' % pbm, autospec=True) as mock_pd:264 with patch('%s.logger' % pbm) as mock_logger:265 mock_pd.side_effect = se_paginate_dict266 cls._find_usage_apis()267 assert mock_logger.mock_calls == [268 call.debug('Finding usage for APIs'),269 call.debug('Found %d APIs', 3),270 call.debug('Finding usage for per-API limits'),271 call.warning(272 'APIGateway get_stages returned more keys than present in '273 'boto3 docs: %s', ['item', 'position']274 )275 ]276 def test_find_usage_plans(self):277 mock_conn = Mock()278 res = result_fixtures.ApiGateway.plans279 mock_paginator = Mock()280 mock_paginator.paginate.return_value = res281 mock_conn.get_paginator.return_value = mock_paginator282 cls = _ApigatewayService(21, 43)283 cls.conn = mock_conn284 with patch('%s.logger' % pbm) as mock_logger:285 cls._find_usage_plans()286 # APIs usage287 usage = cls.limits['Usage plans per account'].get_current_usage()288 assert len(usage) == 1289 assert usage[0].get_value() == 4290 assert mock_conn.mock_calls == [291 call.get_paginator('get_usage_plans'),292 call.get_paginator().paginate()293 ]294 assert mock_paginator.mock_calls == [call.paginate()]295 assert mock_logger.mock_calls == [296 call.debug('Finding usage for Usage Plans')297 ]298 def test_find_usage_certs(self):299 mock_conn = Mock()300 res = result_fixtures.ApiGateway.certs301 mock_paginator = Mock()302 mock_paginator.paginate.return_value = res303 mock_conn.get_paginator.return_value = mock_paginator304 cls = _ApigatewayService(21, 43)305 cls.conn = mock_conn306 with patch('%s.logger' % pbm) as mock_logger:307 cls._find_usage_certs()308 # APIs usage309 usage = cls.limits[310 'Client certificates per account'].get_current_usage()311 assert len(usage) == 1312 assert usage[0].get_value() == 2313 assert mock_conn.mock_calls == [314 call.get_paginator('get_client_certificates'),315 call.get_paginator().paginate()316 ]317 assert mock_paginator.mock_calls == [call.paginate()]318 assert mock_logger.mock_calls == [319 call.debug('Finding usage for Client Certificates')320 ]321 def test_find_usage_api_keys(self):322 mock_conn = Mock()323 res = result_fixtures.ApiGateway.api_keys324 mock_paginator = Mock()325 mock_paginator.paginate.return_value = res326 mock_conn.get_paginator.return_value = mock_paginator327 cls = _ApigatewayService(21, 43)328 cls.conn = mock_conn329 with patch('%s.logger' % pbm) as mock_logger:330 cls._find_usage_api_keys()331 # API Keys usage332 usage = cls.limits[333 'API keys per account'].get_current_usage()334 assert len(usage) == 1335 assert usage[0].get_value() == 4336 assert mock_conn.mock_calls == [337 call.get_paginator('get_api_keys'),338 call.get_paginator().paginate()339 ]340 assert mock_paginator.mock_calls == [call.paginate()]341 assert mock_logger.mock_calls == [342 call.debug('Finding usage for API Keys')343 ]344 def test_required_iam_permissions(self):345 cls = _ApigatewayService(21, 43)346 assert cls.required_iam_permissions() == [347 "apigateway:GET",348 "apigateway:HEAD",349 "apigateway:OPTIONS"...

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