Last active
August 29, 2015 14:01
-
-
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.
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
#!/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