Last active
August 29, 2015 14:01
-
-
Save cansadadeserfeliz/dca59e325c9f7554d176 to your computer and use it in GitHub Desktop.
Django: ajax json view in tests
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 django.test import TestCase | |
class JSONViewTestCase(TestCase): | |
def test_json_view(self): | |
response = self.client.post( | |
reverse('my_json_view'), | |
json.dumps({ | |
# your JSON | |
}), | |
'json', | |
HTTP_X_REQUESTED_WITH='XMLHttpRequest', | |
) | |
json_string = response.content | |
response_data = json.loads(json_string) | |
# do smth. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment