diff nosedjango/nosedjango.py @ 9:35178e70f1cd

urls support in testcase objects
author Victor Ng <victor@monkeybean.ca>
date Thu, 28 Aug 2008 13:33:58 -0400
parents a82369f2574e
children
line wrap: on
line diff
--- a/nosedjango/nosedjango.py	Thu Aug 28 12:42:31 2008 -0400
+++ b/nosedjango/nosedjango.py	Thu Aug 28 13:33:58 2008 -0400
@@ -114,6 +114,7 @@
 
         from django.core.management import call_command
         from django.core.urlresolvers import clear_url_caches
+        from django.conf import settings
         call_command('flush', verbosity=0, interactive=False)
 
         if isinstance(test, nose.case.Test) and \
@@ -122,6 +123,16 @@
                 # We have to use this slightly awkward syntax due to the fact
                 # that we're using *args and **kwargs together.
                 call_command('loaddata', *test.context.fixtures, **{'verbosity': 0}) 
+
+        if isinstance(test, nose.case.Test) and \
+            isinstance(test.test, nose.case.MethodTestCase) and \
+            hasattr(test.context, 'urls'):
+                # We have to use this slightly awkward syntax due to the fact
+                # that we're using *args and **kwargs together.
+                self.old_urlconf = settings.ROOT_URLCONF
+                settings.ROOT_URLCONF = self.urls
+                clear_url_caches()
+
         self.mail.outbox = []
 
     def finalize(self, result=None):
@@ -134,5 +145,11 @@
 
         from django.test.utils import teardown_test_environment
         from django.db import connection
+        from django.conf import settings
         connection.creation.destroy_test_db(self.old_db, verbosity=self.verbosity)   
         teardown_test_environment()
+
+        if hasattr(self, 'old_urlconf'):
+            settings.ROOT_URLCONF = self.old_urlconf
+            clear_url_caches()
+