comparison 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
comparison
equal deleted inserted replaced
8:a82369f2574e 9:35178e70f1cd
112 # test case. This is more in the spirit of unittesting where there is 112 # test case. This is more in the spirit of unittesting where there is
113 # no state information passed between individual tests. 113 # no state information passed between individual tests.
114 114
115 from django.core.management import call_command 115 from django.core.management import call_command
116 from django.core.urlresolvers import clear_url_caches 116 from django.core.urlresolvers import clear_url_caches
117 from django.conf import settings
117 call_command('flush', verbosity=0, interactive=False) 118 call_command('flush', verbosity=0, interactive=False)
118 119
119 if isinstance(test, nose.case.Test) and \ 120 if isinstance(test, nose.case.Test) and \
120 isinstance(test.test, nose.case.MethodTestCase) and \ 121 isinstance(test.test, nose.case.MethodTestCase) and \
121 hasattr(test.context, 'fixtures'): 122 hasattr(test.context, 'fixtures'):
122 # We have to use this slightly awkward syntax due to the fact 123 # We have to use this slightly awkward syntax due to the fact
123 # that we're using *args and **kwargs together. 124 # that we're using *args and **kwargs together.
124 call_command('loaddata', *test.context.fixtures, **{'verbosity': 0}) 125 call_command('loaddata', *test.context.fixtures, **{'verbosity': 0})
126
127 if isinstance(test, nose.case.Test) and \
128 isinstance(test.test, nose.case.MethodTestCase) and \
129 hasattr(test.context, 'urls'):
130 # We have to use this slightly awkward syntax due to the fact
131 # that we're using *args and **kwargs together.
132 self.old_urlconf = settings.ROOT_URLCONF
133 settings.ROOT_URLCONF = self.urls
134 clear_url_caches()
135
125 self.mail.outbox = [] 136 self.mail.outbox = []
126 137
127 def finalize(self, result=None): 138 def finalize(self, result=None):
128 """ 139 """
129 Clean up any created database and schema. 140 Clean up any created database and schema.
132 # short circuit if no settings file can be found 143 # short circuit if no settings file can be found
133 return 144 return
134 145
135 from django.test.utils import teardown_test_environment 146 from django.test.utils import teardown_test_environment
136 from django.db import connection 147 from django.db import connection
148 from django.conf import settings
137 connection.creation.destroy_test_db(self.old_db, verbosity=self.verbosity) 149 connection.creation.destroy_test_db(self.old_db, verbosity=self.verbosity)
138 teardown_test_environment() 150 teardown_test_environment()
151
152 if hasattr(self, 'old_urlconf'):
153 settings.ROOT_URLCONF = self.old_urlconf
154 clear_url_caches()
155