From eec45e8b710b97201db106a6460fe051f8917833 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 12 Oct 2010 23:37:47 +0000 Subject: 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 --- tests/modeltests/test_client/models.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 4a0c9d2ae0..59814a9bf1 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -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') -- cgit v1.3