diff --git a/django/contrib/formtools/tests/__init__.py b/django/contrib/formtools/tests/__init__.py index 6aeeaf5a3dd..b88f565d6b6 100644 --- a/django/contrib/formtools/tests/__init__.py +++ b/django/contrib/formtools/tests/__init__.py @@ -1,14 +1,13 @@ 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]) - diff --git a/django/test/testcases.py b/django/test/testcases.py index 398ad774d82..a79a3045478 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -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) diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py index 396f1bd5823..c856a5f1861 100644 --- a/tests/modeltests/model_formsets/tests.py +++ b/tests/modeltests/model_formsets/tests.py @@ -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): diff --git a/tests/modeltests/signals/tests.py b/tests/modeltests/signals/tests.py index 2b716091600..9b8bce04173 100644 --- a/tests/modeltests/signals/tests.py +++ b/tests/modeltests/signals/tests.py @@ -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, []) diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 59814a9bf13..426cc776861 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -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/') diff --git a/tests/modeltests/update/tests.py b/tests/modeltests/update/tests.py index 005690d0fc5..d0b6ea3ab0d 100644 --- a/tests/modeltests/update/tests.py +++ b/tests/modeltests/update/tests.py @@ -2,6 +2,7 @@ from django.test import TestCase from models import A, B, C, D, DataPoint, RelatedPoint + class SimpleTest(TestCase): def setUp(self): self.a1 = A.objects.create() @@ -15,18 +16,18 @@ class SimpleTest(TestCase): 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): """ @@ -34,9 +35,9 @@ class SimpleTest(TestCase): 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): """ @@ -44,9 +45,9 @@ class SimpleTest(TestCase): 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 @@ class AdvancedTests(TestCase): """ method = DataPoint.objects.all()[:2].update self.assertRaises(AssertionError, method, - another_value='another thing') \ No newline at end of file + another_value='another thing') diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py index c8ad1ce8f64..cb16f4b8928 100644 --- a/tests/regressiontests/admin_changelist/tests.py +++ b/tests/regressiontests/admin_changelist/tests.py @@ -11,8 +11,8 @@ class ChangeListTests(TransactionTestCase): 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 @@ class ChangeListTests(TransactionTestCase): 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 = 'nameParent object' - 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 @@ class ChangeListTests(TransactionTestCase): 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 @@ class ChangeListTests(TransactionTestCase): table_output = template.render(context) # make sure that hidden fields are in the correct place hiddenfields_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 = '' - self.failIf('%s' % editable_name_field == -1, + self.assertFalse('%s' % editable_name_field == -1, 'Failed to find "name" list_editable field in: %s' % table_output) class ChildAdmin(admin.ModelAdmin): diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index c0c2bb72582..b10474d001e 100644 --- a/tests/regressiontests/admin_inlines/tests.py +++ b/tests/regressiontests/admin_inlines/tests.py @@ -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 @@ class TestInline(TestCase): 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() diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 52f1bedc441..bc79f08ed87 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -12,6 +12,7 @@ from django import conf, bin, get_version from django.conf import settings from django.utils import unittest + 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 @@ class AdminScriptTestCase(unittest.TestCase): 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 diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 6b4f65b497a..db2d7f9be30 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -2,10 +2,12 @@ import re import datetime + from django.conf import settings from django.core import mail from django.core.files import temp as tempfile -from django.contrib.auth import REDIRECT_FIELD_NAME, admin # Register auth models with the admin. +# Register auth models with the admin. +from django.contrib.auth import REDIRECT_FIELD_NAME, admin from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD from django.contrib.contenttypes.models import ContentType from django.contrib.admin.models import LogEntry, DELETION @@ -62,12 +64,12 @@ class AdminViewBasicTest(TestCase): A smoke test to ensure GET on the add_view works. """ response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def testAddWithGETArgs(self): response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit, {'name': 'My Section'}) - self.failUnlessEqual(response.status_code, 200) - self.failUnless( + self.assertEqual(response.status_code, 200) + self.assertTrue( 'value="My Section"' in response.content, "Couldn't find an input with the right value in the response." ) @@ -77,7 +79,7 @@ class AdminViewBasicTest(TestCase): A smoke test to ensure GET on the change_view works. """ response = self.client.get('/test_admin/%s/admin_views/section/1/' % self.urlbit) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def testBasicEditGetStringPK(self): """ @@ -86,7 +88,7 @@ class AdminViewBasicTest(TestCase): model with an integer PK field. """ response = self.client.get('/test_admin/%s/admin_views/section/abc/' % self.urlbit) - self.failUnlessEqual(response.status_code, 404) + self.assertEqual(response.status_code, 404) def testBasicAddPost(self): """ @@ -100,7 +102,7 @@ class AdminViewBasicTest(TestCase): "article_set-MAX_NUM_FORMS": u"0", } response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data) - self.failUnlessEqual(response.status_code, 302) # redirect somewhere + self.assertEqual(response.status_code, 302) # redirect somewhere # Post data for edit inline inline_post_data = { @@ -148,7 +150,7 @@ class AdminViewBasicTest(TestCase): A smoke test to ensure POST on edit_view works. """ response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, self.inline_post_data) - self.failUnlessEqual(response.status_code, 302) # redirect somewhere + self.assertEqual(response.status_code, 302) # redirect somewhere def testEditSaveAs(self): """ @@ -164,7 +166,7 @@ class AdminViewBasicTest(TestCase): "article_set-5-section": u"1", }) response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data) - self.failUnlessEqual(response.status_code, 302) # redirect somewhere + self.assertEqual(response.status_code, 302) # redirect somewhere def testChangeListSortingCallable(self): """ @@ -172,8 +174,8 @@ class AdminViewBasicTest(TestCase): (column 2 is callable_year in ArticleAdmin) """ response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'ot': 'asc', 'o': 2}) - self.failUnlessEqual(response.status_code, 200) - self.failUnless( + self.assertEqual(response.status_code, 200) + self.assertTrue( response.content.index('Oldest content') < response.content.index('Middle content') and response.content.index('Middle content') < response.content.index('Newest content'), "Results of sorting on callable are out of order." @@ -185,8 +187,8 @@ class AdminViewBasicTest(TestCase): (colunn 3 is 'model_year' in ArticleAdmin) """ response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'ot': 'dsc', 'o': 3}) - self.failUnlessEqual(response.status_code, 200) - self.failUnless( + self.assertEqual(response.status_code, 200) + self.assertTrue( response.content.index('Newest content') < response.content.index('Middle content') and response.content.index('Middle content') < response.content.index('Oldest content'), "Results of sorting on Model method are out of order." @@ -198,8 +200,8 @@ class AdminViewBasicTest(TestCase): (colunn 4 is 'modeladmin_year' in ArticleAdmin) """ response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'ot': 'asc', 'o': 4}) - self.failUnlessEqual(response.status_code, 200) - self.failUnless( + self.assertEqual(response.status_code, 200) + self.assertTrue( response.content.index('Oldest content') < response.content.index('Middle content') and response.content.index('Middle content') < response.content.index('Newest content'), "Results of sorting on ModelAdmin method are out of order." @@ -210,12 +212,12 @@ class AdminViewBasicTest(TestCase): This also tests relation-spanning filters (e.g. 'color__value'). """ response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit) - self.failUnlessEqual(response.status_code, 200) - self.failUnless( + self.assertEqual(response.status_code, 200) + self.assertTrue( '
' in response.content, "Expected filter not found in changelist view." ) - self.failIf( + self.assertFalse( 'Blue' in response.content, "Changelist filter not correctly limited by limit_choices_to." ) @@ -223,7 +225,7 @@ class AdminViewBasicTest(TestCase): def testRelationSpanningFilters(self): response = self.client.get('/test_admin/%s/admin_views/chapterxtra1/' % self.urlbit) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) self.assertContains(response, '
') filters = { 'chap__id__exact': dict( @@ -256,7 +258,7 @@ class AdminViewBasicTest(TestCase): filtered_response = self.client.get( '/test_admin/%s/admin_views/chapterxtra1/?%s' % ( self.urlbit, query_string)) - self.failUnlessEqual(filtered_response.status_code, 200) + self.assertEqual(filtered_response.status_code, 200) # ensure changelist contains only valid objects for obj in filtered_response.context['cl'].query_set.all(): self.assertTrue(params['test'](obj, value)) @@ -280,8 +282,8 @@ class AdminViewBasicTest(TestCase): def testLogoutAndPasswordChangeURLs(self): response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit) - self.failIf('' % self.urlbit not in response.content) - self.failIf('' % self.urlbit not in response.content) + self.assertFalse('' % self.urlbit not in response.content) + self.assertFalse('' % self.urlbit not in response.content) def testNamedGroupFieldChoicesChangeList(self): """ @@ -290,8 +292,8 @@ class AdminViewBasicTest(TestCase): has been used in the choices option of a field. """ response = self.client.get('/test_admin/%s/admin_views/fabric/' % self.urlbit) - self.failUnlessEqual(response.status_code, 200) - self.failUnless( + self.assertEqual(response.status_code, 200) + self.assertTrue( 'Horizontal' in response.content and 'Vertical' in response.content, "Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group." @@ -303,12 +305,12 @@ class AdminViewBasicTest(TestCase): been used in the choices option of a model field. """ response = self.client.get('/test_admin/%s/admin_views/fabric/' % self.urlbit) - self.failUnlessEqual(response.status_code, 200) - self.failUnless( + self.assertEqual(response.status_code, 200) + self.assertTrue( '
' in response.content, "Expected filter not found in changelist view." ) - self.failUnless( + self.assertTrue( 'Horizontal' in response.content and 'Vertical' in response.content, "Changelist filter isn't showing options contained inside a model field 'choices' option named group." @@ -320,7 +322,7 @@ class AdminViewBasicTest(TestCase): # against the 'admin2' custom admin (which doesn't have the # Post model). response = self.client.get("/test_admin/admin/admin_views/post/") - self.failUnless('icon-unknown.gif' in response.content) + self.assertTrue('icon-unknown.gif' in response.content) def testI18NLanguageNonEnglishDefault(self): """ @@ -380,14 +382,14 @@ class CustomModelAdminTest(AdminViewBasicTest): def testCustomAdminSiteLoginForm(self): self.client.logout() request = self.client.get('/test_admin/admin2/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin2/', { REDIRECT_FIELD_NAME: '/test_admin/admin2/', LOGIN_FORM_KEY: 1, 'username': 'customform', 'password': 'secret', }) - self.failUnlessEqual(login.status_code, 200) + self.assertEqual(login.status_code, 200) self.assertContains(login, 'custom form error') def testCustomAdminSiteLoginTemplate(self): @@ -516,15 +518,15 @@ class AdminViewPermissionsTest(TestCase): """ # Super User request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.super_login) self.assertRedirects(login, '/test_admin/admin/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # Test if user enters e-mail address request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.super_email_login) self.assertContains(login, "Your e-mail address is not your username") # only correct passwords get a username hint @@ -538,46 +540,46 @@ class AdminViewPermissionsTest(TestCase): # Add User request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.adduser_login) self.assertRedirects(login, '/test_admin/admin/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # Change User request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.changeuser_login) self.assertRedirects(login, '/test_admin/admin/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # Delete User request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.deleteuser_login) self.assertRedirects(login, '/test_admin/admin/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # Regular User should not be able to login. request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.joepublic_login) - self.failUnlessEqual(login.status_code, 200) + self.assertEqual(login.status_code, 200) self.assertContains(login, "Please enter a correct username and password.") # Requests without username should not return 500 errors. request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/', self.no_username_login) - self.failUnlessEqual(login.status_code, 200) + self.assertEqual(login.status_code, 200) form = login.context[0].get('form') - self.failUnlessEqual(form.errors['username'][0], 'This field is required.') + self.assertEqual(form.errors['username'][0], 'This field is required.') def testLoginSuccessfullyRedirectsToOriginalUrl(self): request = self.client.get('/test_admin/admin/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) query_string = 'the-answer=42' redirect_url = '/test_admin/admin/?%s' % query_string new_next = {REDIRECT_FIELD_NAME: redirect_url} @@ -596,26 +598,26 @@ class AdminViewPermissionsTest(TestCase): self.client.get('/test_admin/admin/') self.client.post('/test_admin/admin/', self.changeuser_login) # make sure the view removes test cookie - self.failUnlessEqual(self.client.session.test_cookie_worked(), False) + self.assertEqual(self.client.session.test_cookie_worked(), False) request = self.client.get('/test_admin/admin/admin_views/article/add/') - self.failUnlessEqual(request.status_code, 403) + self.assertEqual(request.status_code, 403) # Try POST just to make sure post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict) - self.failUnlessEqual(post.status_code, 403) - self.failUnlessEqual(Article.objects.all().count(), 3) + self.assertEqual(post.status_code, 403) + self.assertEqual(Article.objects.all().count(), 3) self.client.get('/test_admin/admin/logout/') # Add user may login and POST to add view, then redirect to admin root self.client.get('/test_admin/admin/') self.client.post('/test_admin/admin/', self.adduser_login) addpage = self.client.get('/test_admin/admin/admin_views/article/add/') - self.failUnlessEqual(addpage.status_code, 200) + self.assertEqual(addpage.status_code, 200) change_list_link = 'Articles ›' - self.failIf(change_list_link in addpage.content, + self.assertFalse(change_list_link in addpage.content, 'User restricted to add permission is given link to change list view in breadcrumbs.') post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict) self.assertRedirects(post, '/test_admin/admin/') - self.failUnlessEqual(Article.objects.all().count(), 4) + self.assertEqual(Article.objects.all().count(), 4) self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].subject, 'Greetings from a created object') self.client.get('/test_admin/admin/logout/') @@ -624,12 +626,12 @@ class AdminViewPermissionsTest(TestCase): self.client.get('/test_admin/admin/') self.client.post('/test_admin/admin/', self.super_login) addpage = self.client.get('/test_admin/admin/admin_views/article/add/') - self.failUnlessEqual(addpage.status_code, 200) - self.failIf(change_list_link not in addpage.content, + self.assertEqual(addpage.status_code, 200) + self.assertFalse(change_list_link not in addpage.content, 'Unrestricted user is not given link to change list view in breadcrumbs.') post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict) self.assertRedirects(post, '/test_admin/admin/admin_views/article/') - self.failUnlessEqual(Article.objects.all().count(), 5) + self.assertEqual(Article.objects.all().count(), 5) self.client.get('/test_admin/admin/logout/') # 8509 - if a normal user is already logged in, it is possible @@ -639,7 +641,7 @@ class AdminViewPermissionsTest(TestCase): self.client.get('/test_admin/admin/') self.client.post('/test_admin/admin/', self.super_login) # make sure the view removes test cookie - self.failUnlessEqual(self.client.session.test_cookie_worked(), False) + self.assertEqual(self.client.session.test_cookie_worked(), False) def testChangeView(self): """Change view should restrict access and allow users to edit items.""" @@ -653,34 +655,34 @@ class AdminViewPermissionsTest(TestCase): self.client.get('/test_admin/admin/') self.client.post('/test_admin/admin/', self.adduser_login) request = self.client.get('/test_admin/admin/admin_views/article/') - self.failUnlessEqual(request.status_code, 403) + self.assertEqual(request.status_code, 403) request = self.client.get('/test_admin/admin/admin_views/article/1/') - self.failUnlessEqual(request.status_code, 403) + self.assertEqual(request.status_code, 403) post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict) - self.failUnlessEqual(post.status_code, 403) + self.assertEqual(post.status_code, 403) self.client.get('/test_admin/admin/logout/') # change user can view all items and edit them self.client.get('/test_admin/admin/') self.client.post('/test_admin/admin/', self.changeuser_login) request = self.client.get('/test_admin/admin/admin_views/article/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) request = self.client.get('/test_admin/admin/admin_views/article/1/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict) self.assertRedirects(post, '/test_admin/admin/admin_views/article/') - self.failUnlessEqual(Article.objects.get(pk=1).content, '

edited article

') + self.assertEqual(Article.objects.get(pk=1).content, '

edited article

') # one error in form should produce singular error message, multiple errors plural change_dict['title'] = '' post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict) - self.failUnlessEqual(request.status_code, 200) - self.failUnless('Please correct the error below.' in post.content, + self.assertEqual(request.status_code, 200) + self.assertTrue('Please correct the error below.' in post.content, 'Singular error message not found in response to post with one error.') change_dict['content'] = '' post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict) - self.failUnlessEqual(request.status_code, 200) - self.failUnless('Please correct the errors below.' in post.content, + self.assertEqual(request.status_code, 200) + self.assertTrue('Please correct the errors below.' in post.content, 'Plural error message not found in response to post with multiple errors.') self.client.get('/test_admin/admin/logout/') @@ -712,7 +714,7 @@ class AdminViewPermissionsTest(TestCase): # Test custom change list template with custom extra context request = self.client.get('/test_admin/admin/admin_views/customarticle/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) self.assert_("var hello = 'Hello!';" in request.content) self.assertTemplateUsed(request, 'custom_admin/change_list.html') @@ -727,7 +729,7 @@ class AdminViewPermissionsTest(TestCase): 'date_1': '10:54:39' }) self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/') - self.failUnlessEqual(CustomArticle.objects.all().count(), 1) + self.assertEqual(CustomArticle.objects.all().count(), 1) # Test custom delete, change, and object history templates # Test custom change form template @@ -755,10 +757,10 @@ class AdminViewPermissionsTest(TestCase): self.client.get('/test_admin/admin/') self.client.post('/test_admin/admin/', self.adduser_login) request = self.client.get('/test_admin/admin/admin_views/article/1/delete/') - self.failUnlessEqual(request.status_code, 403) + self.assertEqual(request.status_code, 403) post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict) - self.failUnlessEqual(post.status_code, 403) - self.failUnlessEqual(Article.objects.all().count(), 3) + self.assertEqual(post.status_code, 403) + self.assertEqual(Article.objects.all().count(), 3) self.client.get('/test_admin/admin/logout/') # Delete user can delete @@ -769,15 +771,15 @@ class AdminViewPermissionsTest(TestCase): self.assertContains(response, "admin_views/article/1/") response = self.client.get('/test_admin/admin/admin_views/article/1/delete/') - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict) self.assertRedirects(post, '/test_admin/admin/') - self.failUnlessEqual(Article.objects.all().count(), 2) + self.assertEqual(Article.objects.all().count(), 2) self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].subject, 'Greetings from a deleted object') article_ct = ContentType.objects.get_for_model(Article) logged = LogEntry.objects.get(content_type=article_ct, action_flag=DELETION) - self.failUnlessEqual(logged.object_id, u'1') + self.assertEqual(logged.object_id, u'1') self.client.get('/test_admin/admin/logout/') def testDisabledPermissionsWhenLoggedIn(self): @@ -810,7 +812,7 @@ class AdminViewDeletedObjectsTest(TestCase): """ pattern = re.compile(r"""
  • Plot: World Domination\s*
      \s*
    • Plot details: almost finished""") response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(1)) - self.failUnless(pattern.search(response.content)) + self.assertTrue(pattern.search(response.content)) def test_cyclic(self): """ @@ -831,7 +833,7 @@ class AdminViewDeletedObjectsTest(TestCase): delete_user.user_permissions.add(get_perm(Plot, Plot._meta.get_delete_permission())) - self.failUnless(self.client.login(username='deleteuser', + self.assertTrue(self.client.login(username='deleteuser', password='secret')) response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(1)) @@ -919,13 +921,13 @@ class AdminViewStringPrimaryKeyTest(TestCase): "Retrieving the history for the object using urlencoded form of primary key should work" response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/history/' % quote(self.pk)) self.assertContains(response, escape(self.pk)) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_get_change_view(self): "Retrieving the object using urlencoded form of primary key should work" response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(self.pk)) self.assertContains(response, escape(self.pk)) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_changelist_to_changeform_link(self): "The link from the changelist referring to the changeform of the object should be quoted" @@ -1049,7 +1051,7 @@ class SecureViewTest(TestCase): def test_secure_view_login_successfully_redirects_to_original_url(self): request = self.client.get('/test_admin/admin/secure-view/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) query_string = 'the-answer=42' redirect_url = '/test_admin/admin/secure-view/?%s' % query_string new_next = {REDIRECT_FIELD_NAME: redirect_url} @@ -1066,17 +1068,17 @@ class SecureViewTest(TestCase): """ # Super User request = self.client.get('/test_admin/admin/secure-view/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/secure-view/', self.super_login) self.assertRedirects(login, '/test_admin/admin/secure-view/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # make sure the view removes test cookie - self.failUnlessEqual(self.client.session.test_cookie_worked(), False) + self.assertEqual(self.client.session.test_cookie_worked(), False) # Test if user enters e-mail address request = self.client.get('/test_admin/admin/secure-view/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login) self.assertContains(login, "Your e-mail address is not your username") # only correct passwords get a username hint @@ -1090,33 +1092,33 @@ class SecureViewTest(TestCase): # Add User request = self.client.get('/test_admin/admin/secure-view/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/secure-view/', self.adduser_login) self.assertRedirects(login, '/test_admin/admin/secure-view/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # Change User request = self.client.get('/test_admin/admin/secure-view/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/secure-view/', self.changeuser_login) self.assertRedirects(login, '/test_admin/admin/secure-view/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # Delete User request = self.client.get('/test_admin/admin/secure-view/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/secure-view/', self.deleteuser_login) self.assertRedirects(login, '/test_admin/admin/secure-view/') - self.failIf(login.context) + self.assertFalse(login.context) self.client.get('/test_admin/admin/logout/') # Regular User should not be able to login. request = self.client.get('/test_admin/admin/secure-view/') - self.failUnlessEqual(request.status_code, 200) + self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/secure-view/', self.joepublic_login) - self.failUnlessEqual(login.status_code, 200) + self.assertEqual(login.status_code, 200) # Login.context is a list of context dicts we just need to check the first one. self.assertContains(login, "Please enter a correct username and password.") @@ -1127,7 +1129,7 @@ class SecureViewTest(TestCase): self.client.get('/test_admin/admin/secure-view/') self.client.post('/test_admin/admin/secure-view/', self.super_login) # make sure the view removes test cookie - self.failUnlessEqual(self.client.session.test_cookie_worked(), False) + self.assertEqual(self.client.session.test_cookie_worked(), False) class AdminViewUnicodeTest(TestCase): fixtures = ['admin-views-unicode.xml'] @@ -1169,7 +1171,7 @@ class AdminViewUnicodeTest(TestCase): } response = self.client.post('/test_admin/admin/admin_views/book/1/', post_data) - self.failUnlessEqual(response.status_code, 302) # redirect somewhere + self.assertEqual(response.status_code, 302) # redirect somewhere def testUnicodeDelete(self): """ @@ -1177,7 +1179,7 @@ class AdminViewUnicodeTest(TestCase): """ delete_dict = {'post': 'yes'} response = self.client.get('/test_admin/admin/admin_views/book/1/delete/') - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) response = self.client.post('/test_admin/admin/admin_views/book/1/delete/', delete_dict) self.assertRedirects(response, '/test_admin/admin/admin_views/book/') @@ -1195,17 +1197,17 @@ class AdminViewListEditable(TestCase): Podcast.objects.create(name="This Week in Django", release_date=datetime.date.today()) response = self.client.get('/test_admin/admin/admin_views/podcast/') - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_inheritance_2(self): Vodcast.objects.create(name="This Week in Django", released=True) response = self.client.get('/test_admin/admin/admin_views/vodcast/') - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_custom_pk(self): Language.objects.create(iso='en', name='English', english_name='English') response = self.client.get('/test_admin/admin/admin_views/language/') - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_changelist_input_html(self): response = self.client.get('/test_admin/admin/admin_views/person/') @@ -1217,9 +1219,9 @@ class AdminViewListEditable(TestCase): # CSRF field = 1 # field to track 'select all' across paginated views = 1 # 6 + 3 + 4 + 1 + 2 + 1 + 1 = 18 inputs - self.failUnlessEqual(response.content.count(" -1) + self.assertTrue(response._container[0].find("Currently:") > -1) class AdminInlineTests(TestCase): @@ -1891,7 +1893,7 @@ class AdminInlineTests(TestCase): } result = self.client.login(username='super', password='secret') - self.failUnlessEqual(result, True) + self.assertEqual(result, True) self.collector = Collector(pk=1,name='John Fowles') self.collector.save() @@ -1903,9 +1905,9 @@ class AdminInlineTests(TestCase): # First add a new inline self.post_data['widget_set-0-name'] = "Widget 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Widget.objects.count(), 1) - self.failUnlessEqual(Widget.objects.all()[0].name, "Widget 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(Widget.objects.count(), 1) + self.assertEqual(Widget.objects.all()[0].name, "Widget 1") # Check that the PK link exists on the rendered form response = self.client.get('/test_admin/admin/admin_views/collector/1/') @@ -1916,27 +1918,27 @@ class AdminInlineTests(TestCase): self.post_data['widget_set-0-id'] = "1" self.post_data['widget_set-0-name'] = "Widget 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Widget.objects.count(), 1) - self.failUnlessEqual(Widget.objects.all()[0].name, "Widget 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(Widget.objects.count(), 1) + self.assertEqual(Widget.objects.all()[0].name, "Widget 1") # Now modify that inline self.post_data['widget_set-INITIAL_FORMS'] = "1" self.post_data['widget_set-0-id'] = "1" self.post_data['widget_set-0-name'] = "Widget 1 Updated" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Widget.objects.count(), 1) - self.failUnlessEqual(Widget.objects.all()[0].name, "Widget 1 Updated") + self.assertEqual(response.status_code, 302) + self.assertEqual(Widget.objects.count(), 1) + self.assertEqual(Widget.objects.all()[0].name, "Widget 1 Updated") def test_explicit_autofield_inline(self): "A model with an explicit autofield primary key can be saved as inlines. Regression for #8093" # First add a new inline self.post_data['grommet_set-0-name'] = "Grommet 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Grommet.objects.count(), 1) - self.failUnlessEqual(Grommet.objects.all()[0].name, "Grommet 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(Grommet.objects.count(), 1) + self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1") # Check that the PK link exists on the rendered form response = self.client.get('/test_admin/admin/admin_views/collector/1/') @@ -1947,18 +1949,18 @@ class AdminInlineTests(TestCase): self.post_data['grommet_set-0-code'] = "1" self.post_data['grommet_set-0-name'] = "Grommet 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Grommet.objects.count(), 1) - self.failUnlessEqual(Grommet.objects.all()[0].name, "Grommet 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(Grommet.objects.count(), 1) + self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1") # Now modify that inline self.post_data['grommet_set-INITIAL_FORMS'] = "1" self.post_data['grommet_set-0-code'] = "1" self.post_data['grommet_set-0-name'] = "Grommet 1 Updated" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Grommet.objects.count(), 1) - self.failUnlessEqual(Grommet.objects.all()[0].name, "Grommet 1 Updated") + self.assertEqual(response.status_code, 302) + self.assertEqual(Grommet.objects.count(), 1) + self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1 Updated") def test_char_pk_inline(self): "A model with a character PK can be saved as inlines. Regression for #10992" @@ -1966,9 +1968,9 @@ class AdminInlineTests(TestCase): self.post_data['doohickey_set-0-code'] = "DH1" self.post_data['doohickey_set-0-name'] = "Doohickey 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(DooHickey.objects.count(), 1) - self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(DooHickey.objects.count(), 1) + self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1") # Check that the PK link exists on the rendered form response = self.client.get('/test_admin/admin/admin_views/collector/1/') @@ -1979,18 +1981,18 @@ class AdminInlineTests(TestCase): self.post_data['doohickey_set-0-code'] = "DH1" self.post_data['doohickey_set-0-name'] = "Doohickey 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(DooHickey.objects.count(), 1) - self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(DooHickey.objects.count(), 1) + self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1") # Now modify that inline self.post_data['doohickey_set-INITIAL_FORMS'] = "1" self.post_data['doohickey_set-0-code'] = "DH1" self.post_data['doohickey_set-0-name'] = "Doohickey 1 Updated" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(DooHickey.objects.count(), 1) - self.failUnlessEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated") + self.assertEqual(response.status_code, 302) + self.assertEqual(DooHickey.objects.count(), 1) + self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1 Updated") def test_integer_pk_inline(self): "A model with an integer PK can be saved as inlines. Regression for #10992" @@ -1998,9 +2000,9 @@ class AdminInlineTests(TestCase): self.post_data['whatsit_set-0-index'] = "42" self.post_data['whatsit_set-0-name'] = "Whatsit 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Whatsit.objects.count(), 1) - self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(Whatsit.objects.count(), 1) + self.assertEqual(Whatsit.objects.all()[0].name, "Whatsit 1") # Check that the PK link exists on the rendered form response = self.client.get('/test_admin/admin/admin_views/collector/1/') @@ -2011,27 +2013,27 @@ class AdminInlineTests(TestCase): self.post_data['whatsit_set-0-index'] = "42" self.post_data['whatsit_set-0-name'] = "Whatsit 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Whatsit.objects.count(), 1) - self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(Whatsit.objects.count(), 1) + self.assertEqual(Whatsit.objects.all()[0].name, "Whatsit 1") # Now modify that inline self.post_data['whatsit_set-INITIAL_FORMS'] = "1" self.post_data['whatsit_set-0-index'] = "42" self.post_data['whatsit_set-0-name'] = "Whatsit 1 Updated" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(Whatsit.objects.count(), 1) - self.failUnlessEqual(Whatsit.objects.all()[0].name, "Whatsit 1 Updated") + self.assertEqual(response.status_code, 302) + self.assertEqual(Whatsit.objects.count(), 1) + self.assertEqual(Whatsit.objects.all()[0].name, "Whatsit 1 Updated") def test_inherited_inline(self): "An inherited model can be saved as inlines. Regression for #11042" # First add a new inline self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(FancyDoodad.objects.count(), 1) - self.failUnlessEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(FancyDoodad.objects.count(), 1) + self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1") # Check that the PK link exists on the rendered form response = self.client.get('/test_admin/admin/admin_views/collector/1/') @@ -2042,18 +2044,18 @@ class AdminInlineTests(TestCase): self.post_data['fancydoodad_set-0-doodad_ptr'] = "1" self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(FancyDoodad.objects.count(), 1) - self.failUnlessEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1") + self.assertEqual(response.status_code, 302) + self.assertEqual(FancyDoodad.objects.count(), 1) + self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1") # Now modify that inline self.post_data['fancydoodad_set-INITIAL_FORMS'] = "1" self.post_data['fancydoodad_set-0-doodad_ptr'] = "1" self.post_data['fancydoodad_set-0-name'] = "Fancy Doodad 1 Updated" response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) - self.failUnlessEqual(response.status_code, 302) - self.failUnlessEqual(FancyDoodad.objects.count(), 1) - self.failUnlessEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated") + self.assertEqual(response.status_code, 302) + self.assertEqual(FancyDoodad.objects.count(), 1) + self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated") def test_ordered_inline(self): """Check that an inline with an editable ordering fields is @@ -2102,14 +2104,14 @@ class AdminInlineTests(TestCase): }) response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) # Successful post will redirect - self.failUnlessEqual(response.status_code, 302) + self.assertEqual(response.status_code, 302) # Check that the order values have been applied to the right objects - self.failUnlessEqual(self.collector.category_set.count(), 4) - self.failUnlessEqual(Category.objects.get(id=1).order, 14) - self.failUnlessEqual(Category.objects.get(id=2).order, 13) - self.failUnlessEqual(Category.objects.get(id=3).order, 1) - self.failUnlessEqual(Category.objects.get(id=4).order, 0) + self.assertEqual(self.collector.category_set.count(), 4) + self.assertEqual(Category.objects.get(id=1).order, 14) + self.assertEqual(Category.objects.get(id=2).order, 13) + self.assertEqual(Category.objects.get(id=3).order, 1) + self.assertEqual(Category.objects.get(id=4).order, 0) class NeverCacheTests(TestCase): @@ -2124,64 +2126,64 @@ class NeverCacheTests(TestCase): def testAdminIndex(self): "Check the never-cache status of the main index" response = self.client.get('/test_admin/admin/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testAppIndex(self): "Check the never-cache status of an application index" response = self.client.get('/test_admin/admin/admin_views/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testModelIndex(self): "Check the never-cache status of a model index" response = self.client.get('/test_admin/admin/admin_views/fabric/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testModelAdd(self): "Check the never-cache status of a model add page" response = self.client.get('/test_admin/admin/admin_views/fabric/add/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testModelView(self): "Check the never-cache status of a model edit page" response = self.client.get('/test_admin/admin/admin_views/section/1/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testModelHistory(self): "Check the never-cache status of a model history page" response = self.client.get('/test_admin/admin/admin_views/section/1/history/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testModelDelete(self): "Check the never-cache status of a model delete page" response = self.client.get('/test_admin/admin/admin_views/section/1/delete/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testLogin(self): "Check the never-cache status of login views" self.client.logout() response = self.client.get('/test_admin/admin/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testLogout(self): "Check the never-cache status of logout view" response = self.client.get('/test_admin/admin/logout/') - self.failUnlessEqual(get_max_age(response), 0) + self.assertEqual(get_max_age(response), 0) def testPasswordChange(self): "Check the never-cache status of the password change view" self.client.logout() response = self.client.get('/test_admin/password_change/') - self.failUnlessEqual(get_max_age(response), None) + self.assertEqual(get_max_age(response), None) def testPasswordChangeDone(self): "Check the never-cache status of the password change done view" response = self.client.get('/test_admin/admin/password_change/done/') - self.failUnlessEqual(get_max_age(response), None) + self.assertEqual(get_max_age(response), None) def testJsi18n(self): "Check the never-cache status of the Javascript i18n view" response = self.client.get('/test_admin/admin/jsi18n/') - self.failUnlessEqual(get_max_age(response), None) + self.assertEqual(get_max_age(response), None) class ReadonlyTest(TestCase): @@ -2391,5 +2393,5 @@ class ValidXHTMLTests(TestCase): def testLangNamePresent(self): response = self.client.get('/test_admin/%s/admin_views/' % self.urlbit) - self.failIf(' lang=""' in response.content) - self.failIf(' xml:lang=""' in response.content) + self.assertFalse(' lang=""' in response.content) + self.assertFalse(' xml:lang=""' in response.content) diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index 489013fea3d..78e7ba42d9b 100644 --- a/tests/regressiontests/admin_widgets/tests.py +++ b/tests/regressiontests/admin_widgets/tests.py @@ -143,7 +143,7 @@ class AdminForeignKeyWidgetChangeList(DjangoTestCase): def test_changelist_foreignkey(self): response = self.client.get('%s/admin_widgets/car/' % self.admin_root) - self.failUnless('%s/auth/user/add/' % self.admin_root in response.content) + self.assertTrue('%s/auth/user/add/' % self.admin_root in response.content) class AdminForeignKeyRawIdWidget(DjangoTestCase): diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py index 3135f445b89..70c14fdd287 100644 --- a/tests/regressiontests/app_loading/tests.py +++ b/tests/regressiontests/app_loading/tests.py @@ -47,28 +47,28 @@ class EggLoadingTest(TestCase): egg_name = '%s/modelapp.egg' % self.egg_dir sys.path.append(egg_name) models = load_app('app_with_models') - self.failIf(models is None) + self.assertFalse(models is None) def test_egg2(self): """Loading an app from an egg that has no models returns no models (and no error)""" egg_name = '%s/nomodelapp.egg' % self.egg_dir sys.path.append(egg_name) models = load_app('app_no_models') - self.failUnless(models is None) + self.assertTrue(models is None) def test_egg3(self): """Models module can be loaded from an app located under an egg's top-level package""" egg_name = '%s/omelet.egg' % self.egg_dir sys.path.append(egg_name) models = load_app('omelet.app_with_models') - self.failIf(models is None) + self.assertFalse(models is None) def test_egg4(self): """Loading an app with no models from under the top-level egg package generates no error""" egg_name = '%s/omelet.egg' % self.egg_dir sys.path.append(egg_name) models = load_app('omelet.app_no_models') - self.failUnless(models is None) + self.assertTrue(models is None) def test_egg5(self): """Loading an app from an egg that has an import error in its models module raises that error""" @@ -80,4 +80,4 @@ class EggLoadingTest(TestCase): except ImportError, e: # Make sure the message is indicating the actual # problem in the broken app. - self.failUnless("modelz" in e.args[0]) + self.assertTrue("modelz" in e.args[0]) diff --git a/tests/regressiontests/bug8245/tests.py b/tests/regressiontests/bug8245/tests.py index 1f957252c17..df35b8c7741 100644 --- a/tests/regressiontests/bug8245/tests.py +++ b/tests/regressiontests/bug8245/tests.py @@ -12,7 +12,7 @@ class Bug8245Test(TestCase): try: admin.autodiscover() except Exception, e: - self.failUnlessEqual(str(e), "Bad admin module") + self.assertEqual(str(e), "Bad admin module") else: self.fail( 'autodiscover should have raised a "Bad admin module" error.') @@ -22,7 +22,7 @@ class Bug8245Test(TestCase): try: admin.autodiscover() except Exception, e: - self.failUnlessEqual(str(e), "Bad admin module") + self.assertEqual(str(e), "Bad admin module") else: self.fail( 'autodiscover should have raised a "Bad admin module" error.') diff --git a/tests/regressiontests/builtin_server/tests.py b/tests/regressiontests/builtin_server/tests.py index 9563be4c4e8..eea6f5fc0c2 100644 --- a/tests/regressiontests/builtin_server/tests.py +++ b/tests/regressiontests/builtin_server/tests.py @@ -48,5 +48,5 @@ class WSGIFileWrapperTests(TestCase): err = StringIO() handler = FileWrapperHandler(None, StringIO(), err, env) handler.run(wsgi_app) - self.failIf(handler._used_sendfile) + self.assertFalse(handler._used_sendfile) self.assertEqual(handler.stdout.getvalue().splitlines()[-1],'Hello World!') diff --git a/tests/regressiontests/comment_tests/tests/comment_form_tests.py b/tests/regressiontests/comment_tests/tests/comment_form_tests.py index b9261d1330a..5efa5c64a8a 100644 --- a/tests/regressiontests/comment_tests/tests/comment_form_tests.py +++ b/tests/regressiontests/comment_tests/tests/comment_form_tests.py @@ -1,19 +1,21 @@ import time + from django.conf import settings -from django.contrib.comments.models import Comment from django.contrib.comments.forms import CommentForm +from django.contrib.comments.models import Comment from django.utils.hashcompat import sha_constructor + from regressiontests.comment_tests.models import Article from regressiontests.comment_tests.tests import CommentTestCase -class CommentFormTests(CommentTestCase): +class CommentFormTests(CommentTestCase): def testInit(self): f = CommentForm(Article.objects.get(pk=1)) self.assertEqual(f.initial['content_type'], str(Article._meta)) self.assertEqual(f.initial['object_pk'], "1") - self.failIfEqual(f.initial['security_hash'], None) - self.failIfEqual(f.initial['timestamp'], None) + self.assertNotEqual(f.initial['security_hash'], None) + self.assertNotEqual(f.initial['timestamp'], None) def testValidPost(self): a = Article.objects.get(pk=1) @@ -26,7 +28,7 @@ class CommentFormTests(CommentTestCase): d = self.getValidData(a) d.update(kwargs) f = CommentForm(Article.objects.get(pk=1), data=d) - self.failIf(f.is_valid()) + self.assertFalse(f.is_valid()) return f def testHoneypotTampering(self): @@ -88,12 +90,12 @@ class CommentFormTests(CommentTestCase): # Try with COMMENTS_ALLOW_PROFANITIES off settings.COMMENTS_ALLOW_PROFANITIES = False f = CommentForm(a, data=dict(d, comment="What a rooster!")) - self.failIf(f.is_valid()) + self.assertFalse(f.is_valid()) # Now with COMMENTS_ALLOW_PROFANITIES on settings.COMMENTS_ALLOW_PROFANITIES = True f = CommentForm(a, data=dict(d, comment="What a rooster!")) - self.failUnless(f.is_valid()) + self.assertTrue(f.is_valid()) # Restore settings settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES = saved diff --git a/tests/regressiontests/comment_tests/tests/comment_view_tests.py b/tests/regressiontests/comment_tests/tests/comment_view_tests.py index 49c6450e150..b8a62b42461 100644 --- a/tests/regressiontests/comment_tests/tests/comment_view_tests.py +++ b/tests/regressiontests/comment_tests/tests/comment_view_tests.py @@ -199,7 +199,7 @@ class CommentViewTests(CommentTestCase): signals.comment_will_be_posted.connect(receive) self.testCreateValidComment() c = Comment.objects.all()[0] - self.failIf(c.is_public) + self.assertFalse(c.is_public) def testCommentNext(self): """Test the different "next" actions the comment view can take""" @@ -208,14 +208,14 @@ class CommentViewTests(CommentTestCase): response = self.client.post("/post/", data) location = response["Location"] match = post_redirect_re.match(location) - self.failUnless(match != None, "Unexpected redirect location: %s" % location) + self.assertTrue(match != None, "Unexpected redirect location: %s" % location) data["next"] = "/somewhere/else/" data["comment"] = "This is another comment" response = self.client.post("/post/", data) location = response["Location"] match = re.search(r"^http://testserver/somewhere/else/\?c=\d+$", location) - self.failUnless(match != None, "Unexpected redirect location: %s" % location) + self.assertTrue(match != None, "Unexpected redirect location: %s" % location) def testCommentDoneView(self): a = Article.objects.get(pk=1) @@ -223,7 +223,7 @@ class CommentViewTests(CommentTestCase): response = self.client.post("/post/", data) location = response["Location"] match = post_redirect_re.match(location) - self.failUnless(match != None, "Unexpected redirect location: %s" % location) + self.assertTrue(match != None, "Unexpected redirect location: %s" % location) pk = int(match.group('pk')) response = self.client.get(location) self.assertTemplateUsed(response, "comments/posted.html") @@ -240,7 +240,7 @@ class CommentViewTests(CommentTestCase): response = self.client.post("/post/", data) location = response["Location"] match = re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+$", location) - self.failUnless(match != None, "Unexpected redirect location: %s" % location) + self.assertTrue(match != None, "Unexpected redirect location: %s" % location) def testCommentPostRedirectWithInvalidIntegerPK(self): """ diff --git a/tests/regressiontests/comment_tests/tests/model_tests.py b/tests/regressiontests/comment_tests/tests/model_tests.py index 17797bb7a6e..2cbf66f07ed 100644 --- a/tests/regressiontests/comment_tests/tests/model_tests.py +++ b/tests/regressiontests/comment_tests/tests/model_tests.py @@ -1,12 +1,13 @@ from django.contrib.comments.models import Comment + from regressiontests.comment_tests.models import Author, Article from regressiontests.comment_tests.tests import CommentTestCase -class CommentModelTests(CommentTestCase): +class CommentModelTests(CommentTestCase): def testSave(self): for c in self.createSomeComments(): - self.failIfEqual(c.submit_date, None) + self.assertNotEqual(c.submit_date, None) def testUserProperties(self): c1, c2, c3, c4 = self.createSomeComments() diff --git a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py index c9b50e29831..ef79b4dc151 100644 --- a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py +++ b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py @@ -1,8 +1,10 @@ -from django.contrib.comments.models import Comment, CommentFlag from django.contrib.auth.models import User, Permission -from django.contrib.contenttypes.models import ContentType -from regressiontests.comment_tests.tests import CommentTestCase from django.contrib.comments import signals +from django.contrib.comments.models import Comment, CommentFlag +from django.contrib.contenttypes.models import ContentType + +from regressiontests.comment_tests.tests import CommentTestCase + class FlagViewTests(CommentTestCase): @@ -35,7 +37,7 @@ class FlagViewTests(CommentTestCase): def testFlagAnon(self): """GET/POST the flag view while not logged in: redirect to log in.""" comments = self.createSomeComments() - pk = comments[0].pk + pk = comments[0].pk response = self.client.get("/flag/%d/" % pk) self.assertEqual(response["Location"], "http://testserver/accounts/login/?next=/flag/%d/" % pk) response = self.client.post("/flag/%d/" % pk) @@ -43,7 +45,7 @@ class FlagViewTests(CommentTestCase): def testFlaggedView(self): comments = self.createSomeComments() - pk = comments[0].pk + pk = comments[0].pk response = self.client.get("/flagged/", data={"c":pk}) self.assertTemplateUsed(response, "comments/flagged.html") @@ -75,7 +77,7 @@ class DeleteViewTests(CommentTestCase): def testDeletePermissions(self): """The delete view should only be accessible to 'moderators'""" comments = self.createSomeComments() - pk = comments[0].pk + pk = comments[0].pk self.client.login(username="normaluser", password="normaluser") response = self.client.get("/delete/%d/" % pk) self.assertEqual(response["Location"], "http://testserver/accounts/login/?next=/delete/%d/" % pk) @@ -93,7 +95,7 @@ class DeleteViewTests(CommentTestCase): response = self.client.post("/delete/%d/" % pk) self.assertEqual(response["Location"], "http://testserver/deleted/?c=%d" % pk) c = Comment.objects.get(pk=pk) - self.failUnless(c.is_removed) + self.assertTrue(c.is_removed) self.assertEqual(c.flags.filter(flag=CommentFlag.MODERATOR_DELETION, user__username="normaluser").count(), 1) def testDeleteSignals(self): @@ -110,7 +112,7 @@ class DeleteViewTests(CommentTestCase): def testDeletedView(self): comments = self.createSomeComments() - pk = comments[0].pk + pk = comments[0].pk response = self.client.get("/deleted/", data={"c":pk}) self.assertTemplateUsed(response, "comments/deleted.html") @@ -119,7 +121,7 @@ class ApproveViewTests(CommentTestCase): def testApprovePermissions(self): """The delete view should only be accessible to 'moderators'""" comments = self.createSomeComments() - pk = comments[0].pk + pk = comments[0].pk self.client.login(username="normaluser", password="normaluser") response = self.client.get("/approve/%d/" % pk) self.assertEqual(response["Location"], "http://testserver/accounts/login/?next=/approve/%d/" % pk) @@ -138,7 +140,7 @@ class ApproveViewTests(CommentTestCase): response = self.client.post("/approve/%d/" % c1.pk) self.assertEqual(response["Location"], "http://testserver/approved/?c=%d" % c1.pk) c = Comment.objects.get(pk=c1.pk) - self.failUnless(c.is_public) + self.assertTrue(c.is_public) self.assertEqual(c.flags.filter(flag=CommentFlag.MODERATOR_APPROVAL, user__username="normaluser").count(), 1) def testApproveSignals(self): @@ -155,21 +157,21 @@ class ApproveViewTests(CommentTestCase): def testApprovedView(self): comments = self.createSomeComments() - pk = comments[0].pk + pk = comments[0].pk response = self.client.get("/approved/", data={"c":pk}) self.assertTemplateUsed(response, "comments/approved.html") class AdminActionsTests(CommentTestCase): urls = "regressiontests.comment_tests.urls_admin" - + def setUp(self): super(AdminActionsTests, self).setUp() - + # Make "normaluser" a moderator u = User.objects.get(username="normaluser") u.is_staff = True perms = Permission.objects.filter( - content_type__app_label = 'comments', + content_type__app_label = 'comments', codename__endswith = 'comment' ) for perm in perms: diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py index e73b61fc219..44466fe9754 100644 --- a/tests/regressiontests/file_storage/tests.py +++ b/tests/regressiontests/file_storage/tests.py @@ -16,12 +16,11 @@ except ImportError: import dummy_threading as threading from django.conf import settings -from django.core.exceptions import SuspiciousOperation +from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured from django.core.files.base import ContentFile, File from django.core.files.images import get_image_dimensions from django.core.files.storage import FileSystemStorage, get_storage_class from django.core.files.uploadedfile import UploadedFile -from django.core.exceptions import ImproperlyConfigured from django.utils import unittest # Try to import PIL in either of the two ways it can end up installed. @@ -103,7 +102,7 @@ class FileStorageTests(unittest.TestCase): """ Standard file access options are available, and work as expected. """ - self.failIf(self.storage.exists('storage_test')) + self.assertFalse(self.storage.exists('storage_test')) f = self.storage.open('storage_test', 'w') f.write('storage contents') f.close() @@ -114,14 +113,14 @@ class FileStorageTests(unittest.TestCase): f.close() self.storage.delete('storage_test') - self.failIf(self.storage.exists('storage_test')) + self.assertFalse(self.storage.exists('storage_test')) def test_file_accessed_time(self): """ File storage returns a Datetime object for the last accessed time of a file. """ - self.failIf(self.storage.exists('test.file')) + self.assertFalse(self.storage.exists('test.file')) f = ContentFile('custom contents') f_name = self.storage.save('test.file', f) @@ -137,7 +136,7 @@ class FileStorageTests(unittest.TestCase): File storage returns a Datetime object for the creation time of a file. """ - self.failIf(self.storage.exists('test.file')) + self.assertFalse(self.storage.exists('test.file')) f = ContentFile('custom contents') f_name = self.storage.save('test.file', f) @@ -154,7 +153,7 @@ class FileStorageTests(unittest.TestCase): File storage returns a Datetime object for the last modified time of a file. """ - self.failIf(self.storage.exists('test.file')) + self.assertFalse(self.storage.exists('test.file')) f = ContentFile('custom contents') f_name = self.storage.save('test.file', f) @@ -171,7 +170,7 @@ class FileStorageTests(unittest.TestCase): File storage extracts the filename from the content object if no name is given explicitly. """ - self.failIf(self.storage.exists('test.file')) + self.assertFalse(self.storage.exists('test.file')) f = ContentFile('custom contents') f.name = 'test.file' @@ -188,7 +187,7 @@ class FileStorageTests(unittest.TestCase): """ File storage returns the full path of a file """ - self.failIf(self.storage.exists('test.file')) + self.assertFalse(self.storage.exists('test.file')) f = ContentFile('custom contents') f_name = self.storage.save('test.file', f) @@ -213,7 +212,7 @@ class FileStorageTests(unittest.TestCase): File storage can get a mixin to extend the functionality of the returned file. """ - self.failIf(self.storage.exists('test.file')) + self.assertFalse(self.storage.exists('test.file')) class TestFileMixin(object): mixed_in = True @@ -232,9 +231,9 @@ class FileStorageTests(unittest.TestCase): """ File storage returns a tuple containing directories and files. """ - self.failIf(self.storage.exists('storage_test_1')) - self.failIf(self.storage.exists('storage_test_2')) - self.failIf(self.storage.exists('storage_dir_1')) + self.assertFalse(self.storage.exists('storage_test_1')) + self.assertFalse(self.storage.exists('storage_test_2')) + self.assertFalse(self.storage.exists('storage_dir_1')) f = self.storage.save('storage_test_1', ContentFile('custom content')) f = self.storage.save('storage_test_2', ContentFile('custom content')) @@ -357,7 +356,7 @@ class FileStoragePathParsing(unittest.TestCase): self.storage.save('dotted.path/test', ContentFile("1")) self.storage.save('dotted.path/test', ContentFile("2")) - self.failIf(os.path.exists(os.path.join(self.storage_dir, 'dotted_.path'))) + self.assertFalse(os.path.exists(os.path.join(self.storage_dir, 'dotted_.path'))) self.assert_(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/test'))) self.assert_(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/test_1'))) diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py index ac1ec1656e8..31f2297d4f2 100644 --- a/tests/regressiontests/file_uploads/tests.py +++ b/tests/regressiontests/file_uploads/tests.py @@ -1,6 +1,6 @@ #! -*- coding: utf-8 -*- -import os import errno +import os import shutil from StringIO import StringIO @@ -15,6 +15,7 @@ from django.utils.hashcompat import sha_constructor from models import FileModel, temp_storage, UPLOAD_TO import uploadhandler + UNICODE_FILENAME = u'test-0123456789_中文_Orléans.jpg' class FileUploadTests(TestCase): diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py index f0e8f3e5589..84f6348fa33 100644 --- a/tests/regressiontests/generic_inline_admin/tests.py +++ b/tests/regressiontests/generic_inline_admin/tests.py @@ -1,13 +1,14 @@ # coding: utf-8 -from django.test import TestCase from django.conf import settings from django.contrib.contenttypes.generic import generic_inlineformset_factory +from django.test import TestCase # local test models from models import Episode, EpisodeExtra, EpisodeMaxNum, EpisodeExclude, \ Media, EpisodePermanent, MediaPermanentInline, Category + class GenericAdminViewTest(TestCase): fixtures = ['users.xml'] @@ -41,14 +42,14 @@ class GenericAdminViewTest(TestCase): A smoke test to ensure GET on the add_view works. """ response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episode/add/') - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def testBasicEditGet(self): """ A smoke test to ensure GET on the change_view works. """ response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episode/%d/' % self.episode_pk) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def testBasicAddPost(self): """ @@ -62,7 +63,7 @@ class GenericAdminViewTest(TestCase): "generic_inline_admin-media-content_type-object_id-MAX_NUM_FORMS": u"0", } response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/episode/add/', post_data) - self.failUnlessEqual(response.status_code, 302) # redirect somewhere + self.assertEqual(response.status_code, 302) # redirect somewhere def testBasicEditPost(self): """ @@ -83,7 +84,7 @@ class GenericAdminViewTest(TestCase): } 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 + self.assertEqual(response.status_code, 302) # redirect somewhere def testGenericInlineFormset(self): EpisodeMediaFormSet = generic_inlineformset_factory(Media, can_delete=False, extra=3) @@ -118,7 +119,7 @@ class GenericAdminViewTest(TestCase): # Regression test for #12340. e = Episode.objects.get(name='This Week in Django') formset = inline_formset(instance=e) - self.failUnless(formset.get_queryset().ordered) + self.assertTrue(formset.get_queryset().ordered) class GenericInlineAdminParametersTest(TestCase): fixtures = ['users.xml'] @@ -178,7 +179,7 @@ class GenericInlineAdminParametersTest(TestCase): e = self._create_object(EpisodeExclude) response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/episodeexclude/%s/' % e.pk) formset = response.context['inline_admin_formsets'][0].formset - self.failIf('url' in formset.forms[0], 'The formset has excluded "url" field.') + self.assertFalse('url' in formset.forms[0], 'The formset has excluded "url" field.') class GenericInlineAdminWithUniqueTogetherTest(TestCase): fixtures = ['users.xml'] @@ -202,9 +203,9 @@ class GenericInlineAdminWithUniqueTogetherTest(TestCase): "generic_inline_admin-phonenumber-content_type-object_id-0-category": "%s" % category_id, } response = self.client.get('/generic_inline_admin/admin/generic_inline_admin/contact/add/') - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data) - self.failUnlessEqual(response.status_code, 302) # redirect somewhere + self.assertEqual(response.status_code, 302) # redirect somewhere class NoInlineDeletionTest(TestCase): def test_no_deletion(self): diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index 65b06a1d77f..b983bca8abe 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -52,10 +52,10 @@ class QueryDictTests(unittest.TestCase): self.assertRaises(AttributeError, q.setlist, 'foo', ['bar']) self.assertRaises(AttributeError, q.appendlist, 'foo', ['bar']) - self.failUnless(q.has_key('foo')) - self.failUnless('foo' in q) - self.failIf(q.has_key('bar')) - self.failIf('bar' in q) + self.assertTrue(q.has_key('foo')) + self.assertTrue('foo' in q) + self.assertFalse(q.has_key('bar')) + self.assertFalse('bar' in q) self.assertEqual(q.items(), [(u'foo', u'bar')]) self.assertEqual(q.lists(), [(u'foo', [u'bar'])]) @@ -92,7 +92,7 @@ class QueryDictTests(unittest.TestCase): q = QueryDict('').copy() q['name'] = 'john' del q['name'] - self.failIf('name' in q) + self.assertFalse('name' in q) def test_basic_mutable_operations(self): q = QueryDict('').copy() @@ -109,8 +109,8 @@ class QueryDictTests(unittest.TestCase): q.appendlist('foo', 'another') self.assertEqual(q.getlist('foo'), ['bar', 'baz', 'another']) self.assertEqual(q['foo'], 'another') - self.failUnless(q.has_key('foo')) - self.failUnless('foo' in q) + self.assertTrue(q.has_key('foo')) + self.assertTrue('foo' in q) self.assertEqual(q.items(), [(u'foo', u'another'), (u'name', u'john')]) self.assertEqual(q.lists(), [(u'foo', [u'bar', u'baz', u'another']), (u'name', [u'john'])]) @@ -213,7 +213,7 @@ class HttpResponseTests(unittest.TestCase): # If we insert a unicode value it will be converted to an ascii r['value'] = u'test value' - self.failUnless(isinstance(r['value'], str)) + self.assertTrue(isinstance(r['value'], str)) # An error is raised ~hen a unicode object with non-ascii is assigned. self.assertRaises(UnicodeEncodeError, r.__setitem__, 'value', u't\xebst value') diff --git a/tests/regressiontests/i18n/commands/compilation.py b/tests/regressiontests/i18n/commands/compilation.py index 3ca2d571383..44bb2f6ab4e 100644 --- a/tests/regressiontests/i18n/commands/compilation.py +++ b/tests/regressiontests/i18n/commands/compilation.py @@ -32,4 +32,4 @@ class PoFileTests(MessageCompilationTests): # underlying compile_messages function instead out = StringIO() self.assertRaises(CommandError, compile_messages, out, locale=LOCALE) - self.failIf(os.path.exists(self.MO_FILE)) + self.assertFalse(os.path.exists(self.MO_FILE)) diff --git a/tests/regressiontests/inline_formsets/tests.py b/tests/regressiontests/inline_formsets/tests.py index 24488661c73..5bd9d18ddd1 100644 --- a/tests/regressiontests/inline_formsets/tests.py +++ b/tests/regressiontests/inline_formsets/tests.py @@ -1,5 +1,6 @@ -from django.test import TestCase from django.forms.models import inlineformset_factory +from django.test import TestCase + from regressiontests.inline_formsets.models import Poet, Poem, School, Parent, Child @@ -20,7 +21,7 @@ class DeletionTests(TestCase): } formset = PoemFormSet(data, instance=poet) formset.save() - self.failUnless(formset.is_valid()) + self.assertTrue(formset.is_valid()) self.assertEqual(Poem.objects.count(), 0) def test_add_form_deletion_when_invalid(self): diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py index fac15c15bc3..b77a2a38131 100644 --- a/tests/regressiontests/middleware/tests.py +++ b/tests/regressiontests/middleware/tests.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -from django.test import TestCase +from django.conf import settings from django.http import HttpRequest from django.middleware.common import CommonMiddleware -from django.conf import settings +from django.test import TestCase + class CommonMiddlewareTest(TestCase): def setUp(self): @@ -74,7 +75,7 @@ class CommonMiddlewareTest(TestCase): try: CommonMiddleware().process_request(request) except RuntimeError, e: - self.failUnless('end in a slash' in str(e)) + self.assertTrue('end in a slash' in str(e)) settings.DEBUG = False def test_append_slash_disabled(self): @@ -125,7 +126,7 @@ class CommonMiddlewareTest(TestCase): self.assertEquals(r.status_code, 301) self.assertEquals(r['Location'], 'http://www.testserver/middleware/slash/') - + # The following tests examine expected behavior given a custom urlconf that # overrides the default one through the request object. @@ -165,7 +166,7 @@ class CommonMiddlewareTest(TestCase): request = self._get_request('customurlconf/slash') request.urlconf = 'regressiontests.middleware.extra_urls' r = CommonMiddleware().process_request(request) - self.failIf(r is None, + self.assertFalse(r is None, "CommonMiddlware failed to return APPEND_SLASH redirect using request.urlconf") self.assertEquals(r.status_code, 301) self.assertEquals(r['Location'], 'http://testserver/middleware/customurlconf/slash/') @@ -188,7 +189,7 @@ class CommonMiddlewareTest(TestCase): try: CommonMiddleware().process_request(request) except RuntimeError, e: - self.failUnless('end in a slash' in str(e)) + self.assertTrue('end in a slash' in str(e)) settings.DEBUG = False def test_append_slash_disabled_custom_urlconf(self): @@ -209,7 +210,7 @@ class CommonMiddlewareTest(TestCase): request = self._get_request('customurlconf/needsquoting#') request.urlconf = 'regressiontests.middleware.extra_urls' r = CommonMiddleware().process_request(request) - self.failIf(r is None, + self.assertFalse(r is None, "CommonMiddlware failed to return APPEND_SLASH redirect using request.urlconf") self.assertEquals(r.status_code, 301) self.assertEquals( diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py index 4a88ce48001..e38df4a80f6 100644 --- a/tests/regressiontests/model_forms_regress/tests.py +++ b/tests/regressiontests/model_forms_regress/tests.py @@ -1,11 +1,12 @@ -import unittest from datetime import date from django import forms -from django.forms.models import modelform_factory, ModelChoiceField, fields_for_model, construct_instance -from django.test import TestCase from django.core.exceptions import FieldError, ValidationError from django.core.files.uploadedfile import SimpleUploadedFile +from django.forms.models import (modelform_factory, ModelChoiceField, + fields_for_model, construct_instance) +from django.utils import unittest +from django.test import TestCase from models import Person, RealPerson, Triple, FilePathModel, Article, \ Publication, CustomFF, Author, Author1, Homepage, Document, Edition @@ -38,10 +39,10 @@ class UniqueTogetherTests(TestCase): Triple.objects.create(left=1, middle=2, right=3) form = TripleForm({'left': '1', 'middle': '2', 'right': '3'}) - self.failIf(form.is_valid()) + self.assertFalse(form.is_valid()) form = TripleForm({'left': '1', 'middle': '3', 'right': '1'}) - self.failUnless(form.is_valid()) + self.assertTrue(form.is_valid()) class TripleFormWithCleanOverride(forms.ModelForm): class Meta: @@ -59,7 +60,7 @@ class OverrideCleanTests(TestCase): optional. """ form = TripleFormWithCleanOverride({'left': 1, 'middle': 2, 'right': 1}) - self.failUnless(form.is_valid()) + self.assertTrue(form.is_valid()) # form.instance.left will be None if the instance was not constructed # by form.full_clean(). self.assertEquals(form.instance.left, 1) diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py index 6cd581fff25..6a2825fed9b 100644 --- a/tests/regressiontests/staticfiles_tests/tests.py +++ b/tests/regressiontests/staticfiles_tests/tests.py @@ -1,23 +1,22 @@ -import tempfile -import shutil import os -import sys import posixpath +import shutil +import sys +import tempfile from StringIO import StringIO -from django.test import TestCase from django.conf import settings from django.contrib.staticfiles import finders, storage -from django.core.files.storage import default_storage from django.core.exceptions import ImproperlyConfigured +from django.core.files.storage import default_storage from django.core.management import call_command from django.db.models.loading import load_app from django.template import Template, Context +from django.test import TestCase TEST_ROOT = os.path.dirname(__file__) - class StaticFilesTestCase(TestCase): """ Test case with a couple utility assertions. @@ -73,7 +72,7 @@ class StaticFilesTestCase(TestCase): settings.INSTALLED_APPS = self.old_installed_apps def assertFileContains(self, filepath, text): - self.failUnless(text in self._get_file(filepath), + self.assertTrue(text in self._get_file(filepath), "'%s' not in '%s'" % (text, filepath)) def assertFileNotFound(self, filepath): @@ -178,8 +177,8 @@ class TestFindStatic(BuildStaticTestCase, TestDefaults): finally: sys.stdout = _stdout self.assertEquals(len(lines), 3) # three because there is also the "Found here" line - self.failUnless('project' in lines[1]) - self.failUnless('apps' in lines[2]) + self.assertTrue('project' in lines[1]) + self.assertTrue('apps' in lines[2]) class TestBuildStatic(BuildStaticTestCase, TestDefaults): @@ -252,7 +251,7 @@ if sys.platform != 'win32': With ``--link``, symbolic links are created. """ - self.failUnless(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt'))) + self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt'))) class TestServeStatic(StaticFilesTestCase): diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index 851d204a54f..1281b91ad8e 100644 --- a/tests/regressiontests/test_client_regress/models.py +++ b/tests/regressiontests/test_client_regress/models.py @@ -3,15 +3,16 @@ Regression tests for the Test Client, especially the customized assertions. """ import os -from django.conf import settings -from django.test import Client, TestCase -from django.test.utils import ContextList -from django.core.urlresolvers import reverse +from django.conf import settings from django.core.exceptions import SuspiciousOperation -from django.template import TemplateDoesNotExist, TemplateSyntaxError, Context, Template -from django.template import loader +from django.core.urlresolvers import reverse +from django.template import (TemplateDoesNotExist, TemplateSyntaxError, + Context, Template, loader) +from django.test import Client, TestCase from django.test.client import encode_file +from django.test.utils import ContextList + class AssertContainsTests(TestCase): def setUp(self): @@ -484,7 +485,7 @@ class LoginTests(TestCase): # Create a second client, and log in. c = Client() login = c.login(username='testclient', password='password') - self.failUnless(login, 'Could not log in') + self.assertTrue(login, 'Could not log in') # Get a redirection page with the second client. response = c.get("/test_client_regress/login_protected_redirect_view/") @@ -508,7 +509,7 @@ class SessionEngineTests(TestCase): def test_login(self): "A session engine that modifies the session key can be used to log in" login = self.client.login(username='testclient', password='password') - self.failUnless(login, 'Could not log in') + self.assertTrue(login, 'Could not log in') # Try to access a login protected page. response = self.client.get("/test_client/login_protected_view/") @@ -547,7 +548,7 @@ class ExceptionTests(TestCase): "#5836 - A stale user exception isn't re-raised by the test client." login = self.client.login(username='testclient',password='password') - self.failUnless(login, 'Could not log in') + self.assertTrue(login, 'Could not log in') try: response = self.client.get("/test_client_regress/staff_only/") self.fail("General users should not be able to visit this page") @@ -558,7 +559,7 @@ class ExceptionTests(TestCase): # This next operation should be successful; if it isn't we have a problem. login = self.client.login(username='staff', password='password') - self.failUnless(login, 'Could not log in') + self.assertTrue(login, 'Could not log in') try: self.client.get("/test_client_regress/staff_only/") except SuspiciousOperation: @@ -670,7 +671,7 @@ class SessionTests(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') # Session should still contain the modified value response = self.client.get('/test_client_regress/check_session/') @@ -681,7 +682,7 @@ class SessionTests(TestCase): """Logout should work whether the user is logged in or not (#9978).""" self.client.logout() login = self.client.login(username='testclient',password='password') - self.failUnless(login, 'Could not log in') + self.assertTrue(login, 'Could not log in') self.client.logout() self.client.logout() @@ -875,4 +876,3 @@ class ResponseTemplateDeprecationTests(TestCase): def test_response_no_template(self): response = self.client.get("/test_client_regress/request_methods/") self.assertEqual(response.template, None) - diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py index e072d4e1541..4ebe37f558c 100644 --- a/tests/regressiontests/views/tests/debug.py +++ b/tests/regressiontests/views/tests/debug.py @@ -12,8 +12,8 @@ class DebugViewTests(TestCase): def setUp(self): self.old_debug = settings.DEBUG settings.DEBUG = True - self.old_template_debug = settings.TEMPLATE_DEBUG - settings.TEMPLATE_DEBUG = True + self.old_template_debug = settings.TEMPLATE_DEBUG + settings.TEMPLATE_DEBUG = True def tearDown(self): settings.DEBUG = self.old_debug @@ -27,8 +27,8 @@ class DebugViewTests(TestCase): 'file_data.txt': SimpleUploadedFile('file_data.txt', 'haha'), } response = self.client.post('/views/raises/', data) - self.failUnless('file_data.txt' in response.content) - self.failIf('haha' in response.content) + self.assertTrue('file_data.txt' in response.content) + self.assertFalse('haha' in response.content) def test_404(self): response = self.client.get('/views/raises404/') @@ -45,7 +45,6 @@ class DebugViewTests(TestCase): self.client.get(reverse('template_exception', args=(n,))) except TemplateSyntaxError, e: raising_loc = inspect.trace()[-1][-2][0].strip() - self.failIf(raising_loc.find('raise BrokenException') == -1, - "Failed to find 'raise BrokenException' in last frame of traceback, instead found: %s" % - raising_loc) - + self.assertFalse(raising_loc.find('raise BrokenException') == -1, + "Failed to find 'raise BrokenException' in last frame of traceback, instead found: %s" % + raising_loc) diff --git a/tests/regressiontests/views/tests/generic/create_update.py b/tests/regressiontests/views/tests/generic/create_update.py index 3975c65706b..4ba1c35c6fb 100644 --- a/tests/regressiontests/views/tests/generic/create_update.py +++ b/tests/regressiontests/views/tests/generic/create_update.py @@ -19,7 +19,7 @@ class CreateObjectTest(TestCase): self.assertRedirects(response, '/accounts/login/?next=%s' % view_url) # Now login and try again. login = self.client.login(username='testclient', password='password') - self.failUnless(login, 'Could not log in') + self.assertTrue(login, 'Could not log in') response = self.client.get(view_url) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'views/article_form.html')