Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Last active August 29, 2015 14:01
Show Gist options
  • Save cansadadeserfeliz/dca59e325c9f7554d176 to your computer and use it in GitHub Desktop.
Save cansadadeserfeliz/dca59e325c9f7554d176 to your computer and use it in GitHub Desktop.
Django: ajax json view in tests
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