How to use _test_error_checker method in tempest

Best Python code snippet using tempest_python

test_rest_client.py

Source:test_rest_client.py Github

copy

Full Screen

...247 self.rest_client = rest_client.RestClient(248 fake_auth_provider.FakeAuthProvider(), None, None)249 def test_response_less_than_400(self):250 self.rest_client._error_checker(**self.set_data("399"))251 def _test_error_checker(self, exception_type, data):252 e = self.assertRaises(exception_type,253 self.rest_client._error_checker,254 **data)255 self.assertEqual(e.resp, data['resp'])256 self.assertTrue(hasattr(e, 'resp_body'))257 return e258 def test_response_400(self):259 self._test_error_checker(exceptions.BadRequest, self.set_data("400"))260 def test_response_401(self):261 self._test_error_checker(exceptions.Unauthorized, self.set_data("401"))262 def test_response_403(self):263 self._test_error_checker(exceptions.Forbidden, self.set_data("403"))264 def test_response_404(self):265 self._test_error_checker(exceptions.NotFound, self.set_data("404"))266 def test_response_409(self):267 self._test_error_checker(exceptions.Conflict, self.set_data("409"))268 def test_response_410(self):269 self._test_error_checker(exceptions.Gone, self.set_data("410"))270 def test_response_412(self):271 self._test_error_checker(exceptions.PreconditionFailed,272 self.set_data("412"))273 def test_response_413(self):274 self._test_error_checker(exceptions.OverLimit, self.set_data("413"))275 def test_response_413_without_absolute_limit(self):276 self._test_error_checker(exceptions.RateLimitExceeded,277 self.set_data("413", absolute_limit=False))278 def test_response_415(self):279 self._test_error_checker(exceptions.InvalidContentType,280 self.set_data("415"))281 def test_response_422(self):282 self._test_error_checker(exceptions.UnprocessableEntity,283 self.set_data("422"))284 def test_response_500_with_text(self):285 # _parse_resp is expected to return 'str'286 self._test_error_checker(exceptions.ServerFault, self.set_data("500"))287 def test_response_501_with_text(self):288 self._test_error_checker(exceptions.NotImplemented,289 self.set_data("501"))290 def test_response_400_with_dict(self):291 r_body = '{"resp_body": {"err": "fake_resp_body"}}'292 e = self._test_error_checker(exceptions.BadRequest,293 self.set_data("400", r_body=r_body))294 if self.c_type == 'application/json':295 expected = {"err": "fake_resp_body"}296 else:297 expected = r_body298 self.assertEqual(expected, e.resp_body)299 def test_response_401_with_dict(self):300 r_body = '{"resp_body": {"err": "fake_resp_body"}}'301 e = self._test_error_checker(exceptions.Unauthorized,302 self.set_data("401", r_body=r_body))303 if self.c_type == 'application/json':304 expected = {"err": "fake_resp_body"}305 else:306 expected = r_body307 self.assertEqual(expected, e.resp_body)308 def test_response_403_with_dict(self):309 r_body = '{"resp_body": {"err": "fake_resp_body"}}'310 e = self._test_error_checker(exceptions.Forbidden,311 self.set_data("403", r_body=r_body))312 if self.c_type == 'application/json':313 expected = {"err": "fake_resp_body"}314 else:315 expected = r_body316 self.assertEqual(expected, e.resp_body)317 def test_response_404_with_dict(self):318 r_body = '{"resp_body": {"err": "fake_resp_body"}}'319 e = self._test_error_checker(exceptions.NotFound,320 self.set_data("404", r_body=r_body))321 if self.c_type == 'application/json':322 expected = {"err": "fake_resp_body"}323 else:324 expected = r_body325 self.assertEqual(expected, e.resp_body)326 def test_response_404_with_invalid_dict(self):327 r_body = '{"foo": "bar"]'328 e = self._test_error_checker(exceptions.NotFound,329 self.set_data("404", r_body=r_body))330 expected = r_body331 self.assertEqual(expected, e.resp_body)332 def test_response_410_with_dict(self):333 r_body = '{"resp_body": {"err": "fake_resp_body"}}'334 e = self._test_error_checker(exceptions.Gone,335 self.set_data("410", r_body=r_body))336 if self.c_type == 'application/json':337 expected = {"err": "fake_resp_body"}338 else:339 expected = r_body340 self.assertEqual(expected, e.resp_body)341 def test_response_410_with_invalid_dict(self):342 r_body = '{"foo": "bar"]'343 e = self._test_error_checker(exceptions.Gone,344 self.set_data("410", r_body=r_body))345 expected = r_body346 self.assertEqual(expected, e.resp_body)347 def test_response_409_with_dict(self):348 r_body = '{"resp_body": {"err": "fake_resp_body"}}'349 e = self._test_error_checker(exceptions.Conflict,350 self.set_data("409", r_body=r_body))351 if self.c_type == 'application/json':352 expected = {"err": "fake_resp_body"}353 else:354 expected = r_body355 self.assertEqual(expected, e.resp_body)356 def test_response_500_with_dict(self):357 r_body = '{"resp_body": {"err": "fake_resp_body"}}'358 e = self._test_error_checker(exceptions.ServerFault,359 self.set_data("500", r_body=r_body))360 if self.c_type == 'application/json':361 expected = {"err": "fake_resp_body"}362 else:363 expected = r_body364 self.assertEqual(expected, e.resp_body)365 def test_response_501_with_dict(self):366 r_body = '{"resp_body": {"err": "fake_resp_body"}}'367 self._test_error_checker(exceptions.NotImplemented,368 self.set_data("501", r_body=r_body))369 def test_response_bigger_than_400(self):370 # Any response code, that bigger than 400, and not in371 # (401, 403, 404, 409, 412, 413, 422, 500, 501)372 self._test_error_checker(exceptions.UnexpectedResponseCode,373 self.set_data("402"))374class TestRestClientErrorCheckerTEXT(TestRestClientErrorCheckerJSON):375 c_type = "text/plain"376 def test_fake_content_type(self):377 # This test is required only in one exemplar378 # Any response code, that bigger than 400, and not in379 # (401, 403, 404, 409, 413, 422, 500, 501)380 self._test_error_checker(exceptions.UnexpectedContentType,381 self.set_data("405", enc="fake_enc"))382 def test_response_413_without_absolute_limit(self):383 # Skip this test because rest_client cannot get overLimit message384 # from text body.385 pass386class TestRestClientUtils(BaseRestClientTestClass):387 def _is_resource_deleted(self, resource_id):388 if not isinstance(self.retry_pass, int):389 return False390 if self.retry_count >= self.retry_pass:391 return True392 self.retry_count = self.retry_count + 1393 return False394 def setUp(self):...

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 tempest 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