How to use test_invoke_method method in localstack

Best Python code snippet using localstack_python

test_aws_resources.py

Source:test_aws_resources.py Github

copy

Full Screen

...131 """132 '''133 invoke a test method for invalid input134 '''135 apigw_error_response = self.apigw_client.test_invoke_method(136 restApiId=self.restapi_id,137 resourceId=self.path_to_resource_id["/nights/{night}"],138 httpMethod="GET",139 pathWithQueryString="/nights/2008-09-27"140 )141 142 self.assertEqual(apigw_error_response["status"], 404)143 @unittest.skipIf(BUILD_ENVIRONMENT != "prod", "Skipping when there is no prod ratings data")144 def test_nights_endpoint_prod(self):145 """tests the nights endpoint where there is production data146 """147 apigw_path_list = []148 '''149 invoke a test method for valid input150 '''151 apigw_response = self.apigw_client.test_invoke_method(152 restApiId=self.restapi_id,153 resourceId=self.path_to_resource_id["/nights/{night}"],154 httpMethod="GET",155 pathWithQueryString="/nights/2014-01-04"156 )157 self.assertEqual(apigw_response["status"], 200)158 first_night_2014 = json.loads(apigw_response["body"])159 '''160 13 television ratings from 2014-01-04161 '''162 self.assertEqual(len(first_night_2014), 13)163 '''164 test structure of random ratings165 '''166 self.assertTrue(first_night_2014[0]["TOTAL_VIEWERS"].isnumeric())167 self.assertTrue(first_night_2014[0]["YEAR"].isnumeric())168 def test_search_endpoint(self):169 """Tests that the search integrations is setup170 """171 apigw_method = self.apigw_client.get_method(172 restApiId=self.restapi_id,173 resourceId=self.path_to_resource_id["/search"],174 httpMethod="GET"175 )176 '''177 Test api key is required for lambda proxy and that178 correct lambda arn is used as a backend179 '''180 self.assertTrue(apigw_method["apiKeyRequired"])181 self.assertTrue(apigw_method["methodIntegration"]["uri"].endswith(182 self.PROJECT_NAME + "-search-endpoint-" + BUILD_ENVIRONMENT + 183 "/invocations"184 ))185 def test_search_not_found(self):186 """Tests that 404 is returned if the startDate is greater than the187 endDate188 """189 '''190 invoke a test method for invalid input191 '''192 apigw_error_response = self.apigw_client.test_invoke_method(193 restApiId=self.restapi_id,194 resourceId=self.path_to_resource_id["/search"],195 httpMethod="GET",196 pathWithQueryString="/search?startDate=2015-9-24&endDate=2015-9-8"197 )198 199 self.assertEqual(apigw_error_response["status"], 404)200 @unittest.skipIf(BUILD_ENVIRONMENT != "prod", "Skipping when there is no prod ratings data")201 def test_search_endpoint_prod(self):202 """tests the seach endpoint where there is production data203 """204 apigw_path_list = []205 '''206 invoke a test method for valid input207 '''208 apigw_response = self.apigw_client.test_invoke_method(209 restApiId=self.restapi_id,210 resourceId=self.path_to_resource_id["/search"],211 httpMethod="GET",212 pathWithQueryString="/search?startDate=2012-05-26&endDate=2013-05-25"213 )214 self.assertEqual(apigw_response["status"], 200)215 ratings_response = json.loads(apigw_response["body"])216 '''217 should have 384 ratings for 2012218 '''219 self.assertEqual(len(ratings_response["ratings"]), 384)220 self.assertEqual(221 ratings_response["next"], 222 "/search?startDate=2013-01-01&endDate=2013-05-25"223 )224 '''225 test structure of random ratings226 '''227 self.assertTrue(ratings_response["ratings"][200]["TOTAL_VIEWERS"].isnumeric())228 self.assertTrue(ratings_response["ratings"][200]["YEAR"].isnumeric())229 @unittest.skipIf(BUILD_ENVIRONMENT != "prod", "Skipping when there is no prod ratings data")230 def test_search_matches_nights(self):231 """tests the seach endpoint matches nights when the startDate is232 equal to the endDate is equal to the night requested233 """234 '''235 invoke a test method for valid input236 '''237 apigw_search_response = self.apigw_client.test_invoke_method(238 restApiId=self.restapi_id,239 resourceId=self.path_to_resource_id["/search"],240 httpMethod="GET",241 pathWithQueryString="/search?startDate=2019-10-26&endDate=2019-10-26"242 )243 ratings_search_response = json.loads(apigw_search_response["body"])244 apigw_nights_response = self.apigw_client.test_invoke_method(245 restApiId=self.restapi_id,246 resourceId=self.path_to_resource_id["/nights/{night}"],247 httpMethod="GET",248 pathWithQueryString="/nights/2019-10-26"249 )250 nights_search_response = json.loads(apigw_nights_response["body"])251 252 253 self.assertIsNone(ratings_search_response["next"])254 self.assertEqual(255 len(ratings_search_response["ratings"]), 256 len(nights_search_response)257 )258 self.assertEqual(259 len(ratings_search_response["ratings"]), 260 11261 )262 263 def test_shows_endpoint(self):264 """Tests that the shows lambda proxy integrations is setup265 """266 apigw_method = self.apigw_client.get_method(267 restApiId=self.restapi_id,268 resourceId=self.path_to_resource_id["/shows/{show}"],269 httpMethod="GET"270 )271 '''272 Test api key is required for lambda proxy and that273 correct lambda arn is used as a backend274 '''275 self.assertTrue(apigw_method["apiKeyRequired"])276 self.assertTrue(apigw_method["methodIntegration"]["uri"].endswith(277 self.PROJECT_NAME + "-shows-endpoint-" + BUILD_ENVIRONMENT + 278 "/invocations"279 ))280 def test_shows_not_found(self):281 """Tests 404 is returned for shows not found282 """283 '''284 invoke a test method for invalid input285 '''286 apigw_error_response = self.apigw_client.test_invoke_method(287 restApiId=self.restapi_id,288 resourceId=self.path_to_resource_id["/shows/{show}"],289 httpMethod="GET",290 pathWithQueryString="/shows/Mock a show name"291 )292 293 self.assertEqual(apigw_error_response["status"], 404)294 @unittest.skipIf(BUILD_ENVIRONMENT != "prod", "Skipping when there is no prod ratings data")295 def test_shows_endpoint_prod(self):296 """tests the shows endpoint where there is production data297 """298 apigw_path_list = []299 '''300 invoke a test method for valid input301 '''302 apigw_response = self.apigw_client.test_invoke_method(303 restApiId=self.restapi_id,304 resourceId=self.path_to_resource_id["/shows/{show}"],305 httpMethod="GET",306 pathWithQueryString="/shows/Star Wars the Clone Wars"307 )308 self.assertEqual(apigw_response["status"], 200)309 star_wars_ratings = json.loads(apigw_response["body"])310 '''311 should have at least 50 airing of the show312 Star Wars the Clone Wars313 '''314 self.assertGreater(len(star_wars_ratings), 50)315 '''316 test structure of random ratings317 '''318 self.assertTrue(star_wars_ratings[10]["TOTAL_VIEWERS"].isnumeric())319 self.assertTrue(star_wars_ratings[10]["YEAR"].isnumeric())320 def test_years_endpoint(self):321 """Tests that the year lambda proxy integrations is setup322 """323 apigw_method = self.apigw_client.get_method(324 restApiId=self.restapi_id,325 resourceId=self.path_to_resource_id["/years/{year}"],326 httpMethod="GET"327 )328 '''329 Test api key is required for lambda proxy and that330 correct lambda arn is used as a backend331 '''332 self.assertTrue(apigw_method["apiKeyRequired"])333 self.assertTrue(apigw_method["methodIntegration"]["uri"].endswith(334 self.PROJECT_NAME + "-years-endpoint-" + BUILD_ENVIRONMENT + 335 "/invocations"336 ))337 def test_years_not_found(self):338 """Tests 404 is returned for years not found339 """340 '''341 invoke a test method for invalid input342 '''343 apigw_error_response = self.apigw_client.test_invoke_method(344 restApiId=self.restapi_id,345 resourceId=self.path_to_resource_id["/years/{year}"],346 httpMethod="GET",347 pathWithQueryString="/years/2009"348 )349 350 self.assertEqual(apigw_error_response["status"], 404)351 @unittest.skipIf(BUILD_ENVIRONMENT != "prod", "Skipping when there is no prod ratings data")352 def test_years_endpoint_prod(self):353 """tests the years endpoint where there is production data354 """355 apigw_path_list = []356 '''357 invoke a test method for valid input358 '''359 apigw_response = self.apigw_client.test_invoke_method(360 restApiId=self.restapi_id,361 resourceId=self.path_to_resource_id["/years/{year}"],362 httpMethod="GET",363 pathWithQueryString="/years/2014"364 )365 self.assertEqual(apigw_response["status"], 200)366 ratings_2014 = json.loads(apigw_response["body"])367 '''368 should have 674 television ratings from 2014369 '''370 self.assertGreater(len(ratings_2014), 500)371 '''372 test structure of random ratings373 '''...

Full Screen

Full Screen

api_gateway_helper.py

Source:api_gateway_helper.py Github

copy

Full Screen

...58 """59 try:60 api_id = self.get_api_id(name)61 resource_id = self.get_resource_id(path, api_id)62 response = self.api_client.test_invoke_method(restApiId=api_id, resourceId=resource_id, httpMethod='GET')63 return response['body']64 except Exception as e:65 print(e)66 def test_post_api(self, name, path, body):67 """68 Test API by POST request method.69 :param name: API name needs to be tested.70 :param path: Particular path of API which needs to be tested.71 :param body: Request body sent along with API.72 """73 try:74 api_id = self.get_api_id(name)75 resource_id = self.get_resource_id(path, api_id)76 result = json.dumps(body)77 response = self.api_client.test_invoke_method(restApiId=api_id, resourceId=resource_id, httpMethod='POST', body=result)78 return response['body']79 except Exception as e:...

Full Screen

Full Screen

apigateway_invoker.py

Source:apigateway_invoker.py Github

copy

Full Screen

...15 authenticator = Authenticator.for_account_and_service(account, self.AWS_SERVICE_NAME)16 self._client = authenticator.client17 self.logger = logging.getLogger(__name__)1819 def test_invoke_method(self, rest_api_id, resource_id, http_method, body, headers={}, path_with_query_string=""):2021 """22 Este método invoca a la api privada de aws que especifiquemos2324 :param rest_api_id: Id del servicio al que se le quiere peticionar (lo sacamos de aws)25 :param resource_id: Id del endpoint al que se le quiere peticionar (lo sacamos de aws)26 :param http_method: Método HTTP a utilizar (GET, POST, PUT, DELETE, UPDATE, PATCH)27 :param body: cuerpo del request en formato dic, json28 :param headers: (opcional)29 :param path_with_query_string: (opcional) Envía información en el path (un ID en un get by ID)30 :return type: Response3132 Ejemplo de uso::3334 payload = {35 "balance": 891428583106,36 "cb_transaction_id": "2639",37 "status": "authorized"38 }3940 response = self.apigw_invoker.test_invoke_method(41 rest_api_id=self.__apigateway_id,42 resource_id=self.__resource_id,43 http_method="POST",44 body=json.dumps(payload)45 )46 """4748 api_response = self._client.test_invoke_method(49 restApiId=rest_api_id,50 resourceId=resource_id,51 httpMethod=http_method,52 body=body,53 headers=headers,54 pathWithQueryString=path_with_query_string55 ) ...

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