Permalink
Browse files

[1.2.X] Removed all usages of deprecated TestCase methods (self.fail*…

…). This removed most of the Warnings emitted (with -Wall) during the test suite. Backport of [14803].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14805 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 5a792ec commit cc48f66f733c9b2fdbc817d473c82300e807f779 @alex alex committed Dec 4, 2010
Showing with 402 additions and 387 deletions.
  1. +5 −5 django/test/testcases.py
  2. +5 −5 tests/modeltests/model_formsets/tests.py
  3. +2 −2 tests/modeltests/signals/tests.py
  4. +8 −8 tests/modeltests/test_client/models.py
  5. +10 −9 tests/modeltests/update/tests.py
  6. +11 −11 tests/regressiontests/admin_changelist/tests.py
  7. +6 −8 tests/regressiontests/admin_inlines/tests.py
  8. +2 −1 tests/regressiontests/admin_scripts/tests.py
  9. +214 −209 tests/regressiontests/admin_views/tests.py
  10. +1 −1 tests/regressiontests/admin_widgets/tests.py
  11. +5 −5 tests/regressiontests/app_loading/tests.py
  12. +2 −2 tests/regressiontests/bug8245/tests.py
  13. +1 −1 tests/regressiontests/builtin_server/tests.py
  14. +10 −7 tests/regressiontests/comment_tests/tests/comment_form_tests.py
  15. +5 −5 tests/regressiontests/comment_tests/tests/comment_view_tests.py
  16. +3 −2 tests/regressiontests/comment_tests/tests/model_tests.py
  17. +15 −13 tests/regressiontests/comment_tests/tests/moderation_view_tests.py
  18. +16 −16 tests/regressiontests/file_storage/tests.py
  19. +2 −1 tests/regressiontests/file_uploads/tests.py
  20. +10 −8 tests/regressiontests/generic_inline_admin/tests.py
  21. +32 −31 tests/regressiontests/httpwrappers/tests.py
  22. +3 −2 tests/regressiontests/inline_formsets/tests.py
  23. +8 −7 tests/regressiontests/middleware/tests.py
  24. +5 −7 tests/regressiontests/model_forms_regress/tests.py
  25. +13 −12 tests/regressiontests/test_client_regress/models.py
  26. +7 −8 tests/regressiontests/views/tests/debug.py
  27. +1 −1 tests/regressiontests/views/tests/generic/create_update.py
@@ -313,7 +313,7 @@ def assertRedirects(self, response, expected_url, status_code=302,
if hasattr(response, 'redirect_chain'):
# The request was a followed redirect
- self.failUnless(len(response.redirect_chain) > 0,
+ self.assertTrue(len(response.redirect_chain) > 0,
msg_prefix + "Response didn't redirect as expected: Response"
" code was %d (expected %d)" %
(response.status_code, status_code))
@@ -427,7 +427,7 @@ def assertFormError(self, response, form, field, errors, msg_prefix=''):
if field:
if field in context[form].errors:
field_errors = context[form].errors[field]
- self.failUnless(err in field_errors,
+ self.assertTrue(err in field_errors,
msg_prefix + "The field '%s' on form '%s' in"
" context %d does not contain the error '%s'"
" (actual errors: %s)" %
@@ -442,7 +442,7 @@ def assertFormError(self, response, form, field, errors, msg_prefix=''):
(form, i, field))
else:
non_field_errors = context[form].non_field_errors()
- self.failUnless(err in non_field_errors,
+ self.assertTrue(err in non_field_errors,
msg_prefix + "The form '%s' in context %d does not"
" contain the non-field error '%s'"
" (actual errors: %s)" %
@@ -462,7 +462,7 @@ def assertTemplateUsed(self, response, template_name, msg_prefix=''):
template_names = [t.name for t in to_list(response.template)]
if not template_names:
self.fail(msg_prefix + "No templates used to render the response")
- self.failUnless(template_name in template_names,
+ self.assertTrue(template_name in template_names,
msg_prefix + "Template '%s' was not a template used to render"
" the response. Actual template(s) used: %s" %
(template_name, u', '.join(template_names)))
@@ -476,7 +476,7 @@ def assertTemplateNotUsed(self, response, template_name, msg_prefix=''):
msg_prefix += ": "
template_names = [t.name for t in to_list(response.template)]
- self.failIf(template_name in template_names,
+ self.assertFalse(template_name in template_names,
msg_prefix + "Template '%s' was used unexpectedly in rendering"
" the response" % template_name)
@@ -2,13 +2,13 @@
import re
from datetime import date
from decimal import Decimal
+
from django import forms
from django.db import models
-from django.forms.models import _get_foreign_key
-from django.forms.models import inlineformset_factory
-from django.forms.models import modelformset_factory
-from django.forms.models import modelformset_factory
+from django.forms.models import (_get_foreign_key, inlineformset_factory,
+ modelformset_factory, modelformset_factory)
from django.test import TestCase
+
from modeltests.model_formsets.models import (
Author, BetterAuthor, Book, BookWithCustomPK, Editor,
BookWithOptionalAltEditor, AlternateBook, AuthorMeeting, CustomPrimaryKey,
@@ -30,7 +30,7 @@ def test_deletion(self):
}
formset = PoetFormSet(data, queryset=Poet.objects.all())
formset.save()
- self.failUnless(formset.is_valid())
+ self.assertTrue(formset.is_valid())
self.assertEqual(Poet.objects.count(), 0)
def test_add_form_deletion_when_invalid(self):
@@ -143,6 +143,6 @@ def test_disconnect_in_dispatch(self):
signals.post_save.connect(sender=Person, receiver=b)
p = Person.objects.create(first_name='John', last_name='Smith')
- self.failUnless(a._run)
- self.failUnless(b._run)
+ self.assertTrue(a._run)
+ self.assertTrue(b._run)
self.assertEqual(signals.post_save.receivers, [])
@@ -70,7 +70,7 @@ def test_post(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['data'], '37')
self.assertEqual(response.template.name, 'POST Template')
- self.failUnless('Data received' in response.content)
+ self.assertTrue('Data received' in response.content)
def test_response_headers(self):
"Check the value of HTTP headers returned in a response"
@@ -275,7 +275,7 @@ def test_view_with_login(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Request a page that requires a login
response = self.client.get('/test_client/login_protected_view/')
@@ -291,7 +291,7 @@ def test_view_with_method_login(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Request a page that requires a login
response = self.client.get('/test_client/login_protected_method_view/')
@@ -307,7 +307,7 @@ def test_view_with_login_and_custom_redirect(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Request a page that requires a login
response = self.client.get('/test_client/login_protected_view_custom_redirect/')
@@ -318,13 +318,13 @@ def test_view_with_bad_login(self):
"Request a page that is protected with @login, but use bad credentials"
login = self.client.login(username='otheruser', password='nopassword')
- self.failIf(login)
+ self.assertFalse(login)
def test_view_with_inactive_login(self):
"Request a page that is protected with @login, but use an inactive login"
login = self.client.login(username='inactive', password='password')
- self.failIf(login)
+ self.assertFalse(login)
def test_logout(self):
"Request a logout after logging in"
@@ -352,7 +352,7 @@ def test_view_with_permissions(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Log in with wrong permissions. Should result in 302.
response = self.client.get('/test_client/permission_protected_view/')
@@ -369,7 +369,7 @@ def test_view_with_method_permissions(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Log in with wrong permissions. Should result in 302.
response = self.client.get('/test_client/permission_protected_method_view/')
@@ -2,6 +2,7 @@
from models import A, B, C, D, DataPoint, RelatedPoint
+
class SimpleTest(TestCase):
def setUp(self):
self.a1 = A.objects.create()
@@ -15,38 +16,38 @@ def test_nonempty_update(self):
Test that update changes the right number of rows for a nonempty queryset
"""
num_updated = self.a1.b_set.update(y=100)
- self.failUnlessEqual(num_updated, 20)
+ self.assertEqual(num_updated, 20)
cnt = B.objects.filter(y=100).count()
- self.failUnlessEqual(cnt, 20)
+ self.assertEqual(cnt, 20)
def test_empty_update(self):
"""
Test that update changes the right number of rows for an empty queryset
"""
num_updated = self.a2.b_set.update(y=100)
- self.failUnlessEqual(num_updated, 0)
+ self.assertEqual(num_updated, 0)
cnt = B.objects.filter(y=100).count()
- self.failUnlessEqual(cnt, 0)
+ self.assertEqual(cnt, 0)
def test_nonempty_update_with_inheritance(self):
"""
Test that update changes the right number of rows for an empty queryset
when the update affects only a base table
"""
num_updated = self.a1.d_set.update(y=100)
- self.failUnlessEqual(num_updated, 20)
+ self.assertEqual(num_updated, 20)
cnt = D.objects.filter(y=100).count()
- self.failUnlessEqual(cnt, 20)
+ self.assertEqual(cnt, 20)
def test_empty_update_with_inheritance(self):
"""
Test that update changes the right number of rows for an empty queryset
when the update affects only a base table
"""
num_updated = self.a2.d_set.update(y=100)
- self.failUnlessEqual(num_updated, 0)
+ self.assertEqual(num_updated, 0)
cnt = D.objects.filter(y=100).count()
- self.failUnlessEqual(cnt, 0)
+ self.assertEqual(cnt, 0)
class AdvancedTests(TestCase):
@@ -112,4 +113,4 @@ def test_update_slice_fail(self):
"""
method = DataPoint.objects.all()[:2].update
self.assertRaises(AssertionError, method,
- another_value='another thing')
+ another_value='another thing')
@@ -11,8 +11,8 @@ def test_select_related_preserved(self):
overwrite a custom select_related provided by ModelAdmin.queryset().
"""
m = ChildAdmin(Child, admin.site)
- cl = ChangeList(MockRequest(), Child, m.list_display, m.list_display_links,
- m.list_filter, m.date_hierarchy, m.search_fields,
+ cl = ChangeList(MockRequest(), Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_editable, m)
self.assertEqual(cl.query_set.query.select_related, {'parent': {'name': {}}})
@@ -25,24 +25,24 @@ def test_result_list_html(self):
new_child = Child.objects.create(name='name', parent=new_parent)
request = MockRequest()
m = ChildAdmin(Child, admin.site)
- cl = ChangeList(request, Child, m.list_display, m.list_display_links,
- m.list_filter, m.date_hierarchy, m.search_fields,
+ cl = ChangeList(request, Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_editable, m)
cl.formset = None
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
context = Context({'cl': cl})
table_output = template.render(context)
row_html = '<tbody><tr class="row1"><td><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td>Parent object</td></tr></tbody>'
- self.failIf(table_output.find(row_html) == -1,
+ self.assertFalse(table_output.find(row_html) == -1,
'Failed to find expected row element: %s' % table_output)
def test_result_list_editable_html(self):
"""
- Regression tests for #11791: Inclusion tag result_list generates a
+ Regression tests for #11791: Inclusion tag result_list generates a
table and this checks that the items are nested within the table
element tags.
Also a regression test for #13599, verifies that hidden fields
- when list_editable is enabled are rendered in a div outside the
+ when list_editable is enabled are rendered in a div outside the
table.
"""
new_parent = Parent.objects.create(name='parent')
@@ -54,8 +54,8 @@ def test_result_list_editable_html(self):
m.list_display = ['id', 'name', 'parent']
m.list_display_links = ['id']
m.list_editable = ['name']
- cl = ChangeList(request, Child, m.list_display, m.list_display_links,
- m.list_filter, m.date_hierarchy, m.search_fields,
+ cl = ChangeList(request, Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_editable, m)
FormSet = m.get_changelist_formset(request)
cl.formset = FormSet(queryset=cl.result_list)
@@ -64,11 +64,11 @@ def test_result_list_editable_html(self):
table_output = template.render(context)
# make sure that hidden fields are in the correct place
hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></div>'
- self.failIf(table_output.find(hiddenfields_div) == -1,
+ self.assertFalse(table_output.find(hiddenfields_div) == -1,
'Failed to find hidden fields in: %s' % table_output)
# make sure that list editable fields are rendered in divs correctly
editable_name_field = '<input name="form-0-name" value="name" class="vTextField" maxlength="30" type="text" id="id_form-0-name" />'
- self.failIf('<td>%s</td>' % editable_name_field == -1,
+ self.assertFalse('<td>%s</td>' % editable_name_field == -1,
'Failed to find "name" list_editable field in: %s' % table_output)
class ChildAdmin(admin.ModelAdmin):
@@ -1,12 +1,10 @@
-from django.test import TestCase
-
from django.contrib.admin.helpers import InlineAdminForm
from django.contrib.contenttypes.models import ContentType
+from django.test import TestCase
+
# local test models
-from models import Holder, Inner, InnerInline
-from models import Holder2, Inner2, Holder3, Inner3
-from models import Person, OutfitItem, Fashionista
-from models import Teacher, Parent, Child
+from models import (Holder, Inner, InnerInline, Holder2, Inner2, Holder3,
+ Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child)
class TestInline(TestCase):
@@ -19,7 +17,7 @@ def setUp(self):
self.change_url = '/test_admin/admin/admin_inlines/holder/%i/' % holder.id
result = self.client.login(username='super', password='secret')
- self.failUnlessEqual(result, True)
+ self.assertEqual(result, True)
def tearDown(self):
self.client.logout()
@@ -75,7 +73,7 @@ class TestInlineMedia(TestCase):
def setUp(self):
result = self.client.login(username='super', password='secret')
- self.failUnlessEqual(result, True)
+ self.assertEqual(result, True)
def tearDown(self):
self.client.logout()
@@ -12,6 +12,7 @@
from django import conf, bin, get_version
from django.conf import settings
+
class AdminScriptTestCase(unittest.TestCase):
def write_settings(self, filename, apps=None, is_dir=False, sdict=None):
test_dir = os.path.dirname(os.path.dirname(__file__))
@@ -156,7 +157,7 @@ def assertNoOutput(self, stream):
self.assertEquals(len(stream), 0, "Stream should be empty: actually contains '%s'" % stream)
def assertOutput(self, stream, msg):
"Utility assertion: assert that the given message exists in the output"
- self.failUnless(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
+ self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
##########################################################################
# DJANGO ADMIN TESTS
Oops, something went wrong.

0 comments on commit cc48f66

Please sign in to comment.