Skip to content

Commit

Permalink
[1.2.X] Fixed #14919 - test isolation issue with model_inheritance.Mo…
Browse files Browse the repository at this point in the history
…delInheritanceTests.test_multiple_table and views.DefaultsTests.test_csrf_token_in_404

test_csrf_token_in_404 was assuming DEBUG = False, and test_multiple_table
was leaving DEBUG = True.  Both issues have been fixed.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14930 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
spookylukey committed Dec 18, 2010
1 parent 6c357cc commit 5a33ce2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
18 changes: 11 additions & 7 deletions tests/modeltests/model_inheritance/tests.py
Expand Up @@ -266,12 +266,16 @@ def test_multiple_table(self):
# select_related works with fields from the parent object as if they # select_related works with fields from the parent object as if they
# were a normal part of the model. # were a normal part of the model.
old_DEBUG = settings.DEBUG old_DEBUG = settings.DEBUG
starting_queries = len(connection.queries) try:
settings.DEBUG = True settings.DEBUG = True
starting_queries = len(connection.queries)
ItalianRestaurant.objects.all()[0].chef
self.assertEqual(len(connection.queries) - starting_queries, 2)

starting_queries = len(connection.queries)
ItalianRestaurant.objects.select_related("chef")[0].chef
self.assertEqual(len(connection.queries) - starting_queries, 1)
finally:
settings.DEBUG = old_DEBUG


ItalianRestaurant.objects.all()[0].chef
self.assertEqual(len(connection.queries) - starting_queries, 2)


starting_queries = len(connection.queries)
ItalianRestaurant.objects.select_related("chef")[0].chef
self.assertEqual(len(connection.queries) - starting_queries, 1)
15 changes: 10 additions & 5 deletions tests/regressiontests/views/tests/defaults.py
Expand Up @@ -60,11 +60,16 @@ def test_csrf_token_in_404(self):
The 404 page should have the csrf_token available in the context The 404 page should have the csrf_token available in the context
""" """
# See ticket #14565 # See ticket #14565
for url in self.non_existing_urls: old_DEBUG = settings.DEBUG
response = self.client.get(url) try:
csrf_token = response.context['csrf_token'] settings.DEBUG = False # so we get real 404, not technical
self.assertNotEqual(str(csrf_token), 'NOTPROVIDED') for url in self.non_existing_urls:
self.assertNotEqual(str(csrf_token), '') response = self.client.get(url)
csrf_token = response.context['csrf_token']
self.assertNotEqual(str(csrf_token), 'NOTPROVIDED')
self.assertNotEqual(str(csrf_token), '')
finally:
settings.DEBUG = old_DEBUG


def test_server_error(self): def test_server_error(self):
"The server_error view raises a 500 status" "The server_error view raises a 500 status"
Expand Down

0 comments on commit 5a33ce2

Please sign in to comment.