diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-10-12 23:37:47 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-10-12 23:37:47 +0000 |
| commit | eec45e8b710b97201db106a6460fe051f8917833 (patch) | |
| tree | d2b3d43a5ead4b70d3b9efda390ca0d6624b287f /tests/modeltests/test_client/models.py | |
| parent | 120aae2209a50641f51e1f6bc4fe383fb42757fb (diff) | |
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
Diffstat (limited to 'tests/modeltests/test_client/models.py')
| -rw-r--r-- | tests/modeltests/test_client/models.py | 14 |
1 files changed, 13 insertions, 1 deletions
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') |
