Commit 5bc0ec4e authored by Alex Gaynor's avatar Alex Gaynor
Browse files

Removed all usages of deprecated TestCase methods (self.fail*). This removed...

Removed all usages of deprecated TestCase methods (self.fail*).  This removed most of the Warnings emitted (with -Wall) during the test suite.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14803 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 6770c362
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
import os

from django import forms
from django import http
from django import forms, http
from django.conf import settings
from django.contrib.formtools import preview, wizard, utils
from django.test import TestCase
from django.utils import unittest

success_string = "Done was called!"

success_string = "Done was called!"

class TestFormPreview(preview.FormPreview):
    def get_context(self, request, form):
@@ -100,7 +99,7 @@ class PreviewTests(TestCase):
        # show we previously saw first stage of the form.
        self.test_data.update({'stage':2})
        response = self.client.post('/test1/', self.test_data)
        self.failIfEqual(response.content, success_string)
        self.assertNotEqual(response.content, success_string)
        hash = self.preview.security_hash(None, TestForm(self.test_data))
        self.test_data.update({'hash': hash})
        response = self.client.post('/test1/', self.test_data)
@@ -134,7 +133,7 @@ class PreviewTests(TestCase):
        # show we previously saw first stage of the form.
        self.test_data.update({'stage':2})
        response = self.client.post('/test1/', self.test_data)
        self.failIfEqual(response.content, success_string)
        self.assertNotEqual(response.content, success_string)
        hash = utils.security_hash(None, TestForm(self.test_data))
        self.test_data.update({'hash': hash})
        response = self.client.post('/test1/', self.test_data)
@@ -151,11 +150,11 @@ class PreviewTests(TestCase):
        self.test_data.update({'stage':2})
        response = self.client.post('/test2/', self.test_data)
        self.assertEqual(response.status_code, 200)
        self.failIfEqual(response.content, success_string)
        self.assertNotEqual(response.content, success_string)
        hash = utils.security_hash(None, TestForm(self.test_data))
        self.test_data.update({'hash': hash})
        response = self.client.post('/test2/', self.test_data)
        self.failIfEqual(response.content, success_string)
        self.assertNotEqual(response.content, success_string)


class SecurityHashTests(unittest.TestCase):
@@ -392,4 +391,3 @@ class WizardTests(TestCase):
                "wizard_step": "1"}
        wizard(DummyRequest(POST=data))
        self.assertTrue(reached[0])
+5 −5
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ class TransactionTestCase(ut2.TestCase):

        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))
@@ -469,7 +469,7 @@ class TransactionTestCase(ut2.TestCase):
                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)" %
@@ -484,7 +484,7 @@ class TransactionTestCase(ut2.TestCase):
                                      (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)" %
@@ -504,7 +504,7 @@ class TransactionTestCase(ut2.TestCase):
        template_names = [t.name for t in response.templates]
        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)))
@@ -518,7 +518,7 @@ class TransactionTestCase(ut2.TestCase):
            msg_prefix += ": "

        template_names = [t.name for t in response.templates]
        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)

+5 −5
Original line number Diff line number Diff line
@@ -2,13 +2,13 @@ import datetime
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 @@ class DeletionTests(TestCase):
        }
        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):
+2 −2
Original line number Diff line number Diff line
@@ -171,6 +171,6 @@ class SignalTests(TestCase):
        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, [])
+8 −8
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class ClientTest(TestCase):
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['data'], '37')
        self.assertEqual(response.templates[0].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"
@@ -278,7 +278,7 @@ class ClientTest(TestCase):

        # 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/')
@@ -294,7 +294,7 @@ class ClientTest(TestCase):

        # 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/')
@@ -310,7 +310,7 @@ class ClientTest(TestCase):

        # 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/')
@@ -321,13 +321,13 @@ class ClientTest(TestCase):
        "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"
@@ -355,7 +355,7 @@ class ClientTest(TestCase):

        # 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/')
@@ -372,7 +372,7 @@ class ClientTest(TestCase):

        # 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/')
Loading