diff --git a/requests/models.py b/requests/models.py index 9ec7975b..99260453 100644 --- a/requests/models.py +++ b/requests/models.py @@ -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): diff --git a/test_requests.py b/test_requests.py index 9f2503db..c974e980 100644 --- a/test_requests.py +++ b/test_requests.py @@ -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()