Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_response_init(c, res):
Response(c, res)
def test_response_status_code(c, res):
res.status_code = 404
assert Response(c, res).status_code == 404
def test_response_url(c, res):
res.url = c.base_url + '/users/me'
assert Response(c, res).url == c.base_url + '/users/me'
def get(self, id):
# NOTE: this is actually performing a search with ID and mangling
# the response data to conform to a single object format.
# There is no method to retrieve a preapproval by ID at the moment.
res = self.search(id=id)
if not res.data['results']:
raise errors.NotFoundError('could not find preapproval with ID = %s' % id)
res = Response(self._client.client, res._response) # pylint: disable=protected-access
res.data = res.data['results'][0]
return res
def _request(self, method, url, **kwargs):
try:
res = self._session.request(method, url, **kwargs)
res.raise_for_status()
except (requests.ConnectionError, requests.HTTPError) as error:
self._handle_request_error(error)
try:
data = res.json()
if 'paging' in data:
return response.PaginatedResponse(self, res)
except ValueError:
pass
return response.Response(self, res)