def _transform(self): endpoint = self._get_url() self.logger.info("Calling transform", request_url=endpoint) response = remote_call(endpoint, json=self.survey) if response_ok(response) and response.content is not None: self.logger.info("Successfully transformed") return response.content else: raise QuarantinableError("Response missing content")
def _transform(self): """ call the transform endpoint and raise quarantinable error if bad response""" endpoint = self._get_url() self.logger.info("Calling transform", request_url=endpoint) response = remote_call(endpoint, json=self.survey) if response_ok(response) and response.content is not None: self.logger.info("{}:Successfully transformed".format(self.__class__.__name__)) return response.content raise QuarantinableError("Response missing content")
def _transform(self): """ call the transform endpoint and raise quarantinable error if bad response""" endpoint = self._get_url() self.logger.info("Calling transform", request_url=endpoint) response = remote_call(endpoint, json=self.survey) if response_ok(response) and response.content is not None: self.logger.info( f"{self.__class__.__name__}:Successfully transformed") return response.content raise QuarantinableError("Response missing content")
def test_response_none(self): response = None result = request_helper.response_ok(response) self.assertEqual(result, False)
def test_response_ok_200_return_true(self): response = Response() response.status_code = 200 result = request_helper.response_ok(response) self.assertEqual(result, True)
def test_response_ok_500_return_false(self): response = Response() response.status_code = 500 result = request_helper.response_ok(response) self.assertEqual(result, False)
def test_response_ok_500_raise_retryable_error(self): response = Response() response.status_code = 500 with self.assertRaises(RetryableError): request_helper.response_ok(response)
def test_response_ok_404_raises_not_found_error(self): response = Response() response.status_code = 404 with self.assertRaises(QuarantinableError): request_helper.response_ok(response)
def test_response_ok_400_raise_bad_request_error(self): response = Response() response.status_code = 400 with self.assertRaises(QuarantinableError): request_helper.response_ok(response)