1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #8138 -- Changed django.test.TestCase to rollback tests (when the database supports it) instead of flushing and reloading the database. This can substantially reduce the time it takes to run large test suites.

This change may be slightly backwards incompatible, if existing tests need to test transactional behavior, or if they rely on invalid assumptions or a specific test case ordering.  For the first case, django.test.TransactionTestCase should be used.  TransactionTestCase is also a quick fix to get around test case errors revealed by the new rollback approach, but a better long-term fix is to correct the test case.  See the testing doc for full details.

Many thanks to:
* Marc Remolt for the initial proposal and implementation.
* Luke Plant for initial testing and improving the implementation.
* Ramiro Morales for feedback and help with tracking down a mysterious PostgreSQL issue.
* Eric Holscher for feedback regarding the effect of the change on the Ellington testsuite.
* Russell Keith-Magee for guidance and feedback from beginning to end.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9756 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Karen Tracey
2009-01-16 02:30:22 +00:00
parent f9f9d703cf
commit 344f16e220
11 changed files with 251 additions and 51 deletions

View File

@@ -21,8 +21,10 @@ class GenericAdminViewTest(TestCase):
# relies on content type IDs, which will vary depending on what
# other tests have been run), thus we do it here.
e = Episode.objects.create(name='This Week in Django')
self.episode_pk = e.pk
m = Media(content_object=e, url='http://example.com/podcast.mp3')
m.save()
self.media_pk = m.pk
def tearDown(self):
self.client.logout()
@@ -39,7 +41,7 @@ class GenericAdminViewTest(TestCase):
"""
A smoke test to ensure GET on the change_view works.
"""
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episode/1/')
response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episode/%d/' % self.episode_pk)
self.failUnlessEqual(response.status_code, 200)
def testBasicAddPost(self):
@@ -64,10 +66,11 @@ class GenericAdminViewTest(TestCase):
# inline data
"generic_inline_admin-media-content_type-object_id-TOTAL_FORMS": u"2",
"generic_inline_admin-media-content_type-object_id-INITIAL_FORMS": u"1",
"generic_inline_admin-media-content_type-object_id-0-id": u"1",
"generic_inline_admin-media-content_type-object_id-0-id": u"%d" % self.media_pk,
"generic_inline_admin-media-content_type-object_id-0-url": u"http://example.com/podcast.mp3",
"generic_inline_admin-media-content_type-object_id-1-id": u"",
"generic_inline_admin-media-content_type-object_id-1-url": u"",
}
response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/episode/1/', post_data)
url = '/generic_inline_admin/admin/generic_inline_admin/episode/%d/' % self.episode_pk
response = self.client.post(url, post_data)
self.failUnlessEqual(response.status_code, 302) # redirect somewhere