Skip to content

Instantly share code, notes, and snippets.

@erdimeola
Created January 6, 2014 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdimeola/8280457 to your computer and use it in GitHub Desktop.
Save erdimeola/8280457 to your computer and use it in GitHub Desktop.
Django Unit Test Request Object Instance
from django.utils import unittest
from django.test.client import RequestFactory
class SimpleTest(unittest.TestCase):
def setUp(self):
# Every test needs access to the request factory.
self.factory = RequestFactory()
def test_details(self):
# Create an instance of a GET request.
request = self.factory.get('/customer/details')
# Test my_view() as if it were deployed at /customer/details
response = my_view(request)
self.assertEqual(response.status_code, 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment