Skip to content

Instantly share code, notes, and snippets.

@RussellLuo
Last active August 29, 2015 14:01
Show Gist options
  • Save RussellLuo/6d18228c4e513636700a to your computer and use it in GitHub Desktop.
Save RussellLuo/6d18228c4e513636700a to your computer and use it in GitHub Desktop.
An example showing how to use the dummy request in Django unit testing.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.test.client import RequestFactory
class RequestTest(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.url = reverse('the-url-name', kwargs={})
def test_request(self):
data = {'name': 'core_class', 'value': 'RequestFactory'}
request = self.factory.post(self.url, data)
name = request.POST.get('name')
self.assertEqual(name, 'core_class')
value = request.POST.get('value')
self.assertEqual(value, 'RequestFactory')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment