From 415bd694f9de8252e8d47bdf3df73cc62ca97728 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 30 Jun 2008 12:34:29 +0000 Subject: Fixed #7521 -- Added the ability to customize ROOT_URLCONF for the duration of a TestCase. Thanks to Mark Fargas (telenieko) for his work on this patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7805 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/testing.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'docs') diff --git a/docs/testing.txt b/docs/testing.txt index befa6979af..0b18545efb 100644 --- a/docs/testing.txt +++ b/docs/testing.txt @@ -797,6 +797,37 @@ another test, or by the order of test execution. .. _dumpdata documentation: ../django-admin/#dumpdata-appname-appname .. _loaddata documentation: ../django-admin/#loaddata-fixture-fixture +URLconf configuration +~~~~~~~~~~~~~~~~~~~~~ + +**New in Django development version** + +If your application provides views, you may want to include tests that +use the test client to exercise those views. However, an end user is free +to deploy the views in your application at any URL of their choosing. +This means that your tests can't rely upon the fact that your views will +be available at a particular URL. + +In order to provide a reliable URL space for your test, +``django.test.TestCase`` provides the ability to customize the URLconf +configuration for the duration of the execution of a test suite. +If your ``TestCase`` instance defines an ``urls`` attribute, the +``TestCase`` will use the value of that attribute as the ``ROOT_URLCONF`` +for the duration of that test. + +For example:: + + from django.test import TestCase + + class TestMyViews(TestCase): + urls = 'myapp.test_urls' + + def testIndexPageView(self): + # Here you'd test your view using ``Client``. + +This test case will use the contents of ``myapp.test_urls`` as the +URLconf for the duration of the test case. + Emptying the test outbox ~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.3