mirror of
https://github.com/django/django.git
synced 2025-11-01 12:25:37 +00:00
Fixed #9002 -- Added a RequestFactory. This allows you to create request instances so you can unit test views as standalone functions. Thanks to Simon Willison for the suggestion and snippet on which this patch was originally based.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14191 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
120aae2209
commit
eec45e8b71
4 changed files with 244 additions and 132 deletions
|
|
@ -20,9 +20,12 @@ testing against the contexts and templates produced by a view,
|
|||
rather than the HTML rendered to the end-user.
|
||||
|
||||
"""
|
||||
from django.test import Client, TestCase
|
||||
from django.conf import settings
|
||||
from django.core import mail
|
||||
from django.test import Client, TestCase, RequestFactory
|
||||
|
||||
from views import get_view
|
||||
|
||||
|
||||
class ClientTest(TestCase):
|
||||
fixtures = ['testdata.json']
|
||||
|
|
@ -469,3 +472,12 @@ class CustomTestClientTest(TestCase):
|
|||
"""A test case can specify a custom class for self.client."""
|
||||
self.assertEqual(hasattr(self.client, "i_am_customized"), True)
|
||||
|
||||
|
||||
class RequestFactoryTest(TestCase):
|
||||
def test_request_factory(self):
|
||||
factory = RequestFactory()
|
||||
request = factory.get('/somewhere/')
|
||||
response = get_view(request)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, 'This is a test')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue