Skip to content

Instantly share code, notes, and snippets.

@flavianmissi
Created November 8, 2011 15:39
Show Gist options
  • Save flavianmissi/1348085 to your computer and use it in GitHub Desktop.
Save flavianmissi/1348085 to your computer and use it in GitHub Desktop.
Testing with Django's RequestFactory
from django.test.client import RequestFactory
from django.utils.unittest import TestCase
from myapp.views import my_view
class MyViewTestCase(TestCase):
def test_my_view_should_return_200_status_code(self):
request = RequestFactory().get('url_for_the_view')
request.custom_attr = ':)'
response = my_view(request)
self.assertEqual(200, response.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment