mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge branch 'master' of git://github.com/kennethreitz/requests
Conflicts: test_requests.py
This commit is contained in:
+7
-4
@@ -603,8 +603,11 @@ class Response(object):
|
||||
|
||||
return content
|
||||
|
||||
def json(self):
|
||||
"""Returns the json-encoded content of a response, if any."""
|
||||
def json(self, **kwargs):
|
||||
"""Returns the json-encoded content of a response, if any.
|
||||
|
||||
:param \*\*kwargs: Optional arguments that ``json.loads`` takes.
|
||||
"""
|
||||
|
||||
if not self.encoding and len(self.content) > 3:
|
||||
# No encoding set. JSON RFC 4627 section 3 states we should expect
|
||||
@@ -613,8 +616,8 @@ class Response(object):
|
||||
# a best guess).
|
||||
encoding = guess_json_utf(self.content)
|
||||
if encoding is not None:
|
||||
return json.loads(self.content.decode(encoding))
|
||||
return json.loads(self.text or self.content)
|
||||
return json.loads(self.content.decode(encoding), **kwargs)
|
||||
return json.loads(self.text or self.content, **kwargs)
|
||||
|
||||
@property
|
||||
def links(self):
|
||||
|
||||
+5
-7
@@ -34,9 +34,6 @@ class RequestsTestCase(unittest.TestCase):
|
||||
"""Teardown."""
|
||||
pass
|
||||
|
||||
def test_assertion(self):
|
||||
assert 1
|
||||
|
||||
def test_entry_points(self):
|
||||
|
||||
requests.session
|
||||
@@ -76,10 +73,6 @@ class RequestsTestCase(unittest.TestCase):
|
||||
self.assertEqual(request.url,
|
||||
"http://example.com/path?key=value&a=b#fragment")
|
||||
|
||||
def test_HTTP_200_OK_GET(self):
|
||||
r = requests.get(httpbin('get'))
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_HTTP_200_OK_GET_ALTERNATIVE(self):
|
||||
r = requests.Request('GET', httpbin('get'))
|
||||
s = requests.Session()
|
||||
@@ -281,6 +274,11 @@ class RequestsTestCase(unittest.TestCase):
|
||||
|
||||
self.assertTrue(hasattr(resp, 'hook_working'))
|
||||
|
||||
def test_links(self):
|
||||
url = 'https://api.github.com/users/kennethreitz/repos?page=1&per_page=10'
|
||||
r = requests.head(url=url)
|
||||
self.assertEqual(r.links['next']['rel'], 'next')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user