Last active
August 29, 2015 14:06
-
-
Save igniteflow/a1b438d5aba485cc2709 to your computer and use it in GitHub Desktop.
Add content_as_python attribute to the APIClient.get() returned response object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from rest_framework.test import APIClient | |
| def get(self, *args, **kwargs): | |
| response = super(APIClient, self).get(*args, **kwargs) | |
| try: | |
| response.content_as_python = json.loads(response.content) | |
| except ValueError as e: | |
| response.content_as_python = e | |
| return response | |
| APIClient.get = get | |
| api_client = APIClient() | |
| response = api_client.get('/api/spam/) | |
| print(response.content_as_python) # JSON object has been loaded to python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment