def get_response(self, method, url): if (method, url) in self._entries: rbody, rcode, rheaders = self._entries.pop((method, url)) if not isinstance(rbody, six.string_types): rbody = json.dumps(rbody) stripe_response = StripeResponse(rbody, rcode, rheaders) return stripe_response return None
def interpret_response(self, rbody, rcode, rheaders): try: if hasattr(rbody, 'decode'): rbody = rbody.decode('utf-8') resp = StripeResponse(rbody, rcode, rheaders) except Exception: raise error.APIError( "Invalid response body from API: %s " "(HTTP response code was %d)" % (rbody, rcode), rbody, rcode, rheaders) if not (200 <= rcode < 300): self.handle_error_response(rbody, rcode, resp.data, rheaders) return resp
def interpret_response(self, rbody, rcode, rheaders): try: if hasattr(rbody, "decode"): rbody = rbody.decode("utf-8") resp = StripeResponse(rbody, rcode, rheaders) except Exception: raise error.APIError( "Invalid response body from API: %s " "(HTTP response code was %d)" % (rbody, rcode), rbody, rcode, rheaders, ) if self._should_handle_code_as_error(rcode): self.handle_error_response(rbody, rcode, resp.data, rheaders) return resp
def get_response(self, method, url, expect_stream=False): if (method, url) in self._entries: rbody, rcode, rheaders, is_streaming = self._entries.pop( (method, url)) if expect_stream != is_streaming: return None if not isinstance(rbody, six.string_types): rbody = json.dumps(rbody) if is_streaming: stripe_response = StripeStreamResponse( util.io.BytesIO(str.encode(rbody)), rcode, rheaders) else: stripe_response = StripeResponse(rbody, rcode, rheaders) return stripe_response return None
def mock_stripe_response(): code = 200 headers = TestStripeResponse.mock_headers() body = TestStripeResponse.mock_body() response = StripeResponse(body, code, headers) return response, headers, body, code
def mock_response(self, mock_headers, mock_body): code = 200 response = StripeResponse(mock_body, code, mock_headers) return response