Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

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

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14805 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cc48f66f733c9b2fdbc817d473c82300e807f779 1 parent 5a792ec
@alex alex authored
Showing with 402 additions and 387 deletions.
  1. +5 −5 django/test/testcases.py
  2. +5 −5 tests/modeltests/model_formsets/tests.py
  3. +2 −2 tests/modeltests/signals/tests.py
  4. +8 −8 tests/modeltests/test_client/models.py
  5. +10 −9 tests/modeltests/update/tests.py
  6. +11 −11 tests/regressiontests/admin_changelist/tests.py
  7. +6 −8 tests/regressiontests/admin_inlines/tests.py
  8. +2 −1  tests/regressiontests/admin_scripts/tests.py
  9. +214 −209 tests/regressiontests/admin_views/tests.py
  10. +1 −1  tests/regressiontests/admin_widgets/tests.py
  11. +5 −5 tests/regressiontests/app_loading/tests.py
  12. +2 −2 tests/regressiontests/bug8245/tests.py
  13. +1 −1  tests/regressiontests/builtin_server/tests.py
  14. +10 −7 tests/regressiontests/comment_tests/tests/comment_form_tests.py
  15. +5 −5 tests/regressiontests/comment_tests/tests/comment_view_tests.py
  16. +3 −2 tests/regressiontests/comment_tests/tests/model_tests.py
  17. +15 −13 tests/regressiontests/comment_tests/tests/moderation_view_tests.py
  18. +16 −16 tests/regressiontests/file_storage/tests.py
  19. +2 −1  tests/regressiontests/file_uploads/tests.py
  20. +10 −8 tests/regressiontests/generic_inline_admin/tests.py
  21. +32 −31 tests/regressiontests/httpwrappers/tests.py
  22. +3 −2 tests/regressiontests/inline_formsets/tests.py
  23. +8 −7 tests/regressiontests/middleware/tests.py
  24. +5 −7 tests/regressiontests/model_forms_regress/tests.py
  25. +13 −12 tests/regressiontests/test_client_regress/models.py
  26. +7 −8 tests/regressiontests/views/tests/debug.py
  27. +1 −1  tests/regressiontests/views/tests/generic/create_update.py
View
10 django/test/testcases.py
@@ -313,7 +313,7 @@ def assertRedirects(self, response, expected_url, status_code=302,
if hasattr(response, 'redirect_chain'):
# The request was a followed redirect
- self.failUnless(len(response.redirect_chain) > 0,
+ self.assertTrue(len(response.redirect_chain) > 0,
msg_prefix + "Response didn't redirect as expected: Response"
" code was %d (expected %d)" %
(response.status_code, status_code))
@@ -427,7 +427,7 @@ def assertFormError(self, response, form, field, errors, msg_prefix=''):
if field:
if field in context[form].errors:
field_errors = context[form].errors[field]
- self.failUnless(err in field_errors,
+ self.assertTrue(err in field_errors,
msg_prefix + "The field '%s' on form '%s' in"
" context %d does not contain the error '%s'"
" (actual errors: %s)" %
@@ -442,7 +442,7 @@ def assertFormError(self, response, form, field, errors, msg_prefix=''):
(form, i, field))
else:
non_field_errors = context[form].non_field_errors()
- self.failUnless(err in non_field_errors,
+ self.assertTrue(err in non_field_errors,
msg_prefix + "The form '%s' in context %d does not"
" contain the non-field error '%s'"
" (actual errors: %s)" %
@@ -462,7 +462,7 @@ def assertTemplateUsed(self, response, template_name, msg_prefix=''):
template_names = [t.name for t in to_list(response.template)]
if not template_names:
self.fail(msg_prefix + "No templates used to render the response")
- self.failUnless(template_name in template_names,
+ self.assertTrue(template_name in template_names,
msg_prefix + "Template '%s' was not a template used to render"
" the response. Actual template(s) used: %s" %
(template_name, u', '.join(template_names)))
@@ -476,7 +476,7 @@ def assertTemplateNotUsed(self, response, template_name, msg_prefix=''):
msg_prefix += ": "
template_names = [t.name for t in to_list(response.template)]
- self.failIf(template_name in template_names,
+ self.assertFalse(template_name in template_names,
msg_prefix + "Template '%s' was used unexpectedly in rendering"
" the response" % template_name)
View
10 tests/modeltests/model_formsets/tests.py
@@ -2,13 +2,13 @@
import re
from datetime import date
from decimal import Decimal
+
from django import forms
from django.db import models
-from django.forms.models import _get_foreign_key
-from django.forms.models import inlineformset_factory
-from django.forms.models import modelformset_factory
-from django.forms.models import modelformset_factory
+from django.forms.models import (_get_foreign_key, inlineformset_factory,
+ modelformset_factory, modelformset_factory)
from django.test import TestCase
+
from modeltests.model_formsets.models import (
Author, BetterAuthor, Book, BookWithCustomPK, Editor,
BookWithOptionalAltEditor, AlternateBook, AuthorMeeting, CustomPrimaryKey,
@@ -30,7 +30,7 @@ def test_deletion(self):
}
formset = PoetFormSet(data, queryset=Poet.objects.all())
formset.save()
- self.failUnless(formset.is_valid())
+ self.assertTrue(formset.is_valid())
self.assertEqual(Poet.objects.count(), 0)
def test_add_form_deletion_when_invalid(self):
View
4 tests/modeltests/signals/tests.py
@@ -143,6 +143,6 @@ def test_disconnect_in_dispatch(self):
signals.post_save.connect(sender=Person, receiver=b)
p = Person.objects.create(first_name='John', last_name='Smith')
- self.failUnless(a._run)
- self.failUnless(b._run)
+ self.assertTrue(a._run)
+ self.assertTrue(b._run)
self.assertEqual(signals.post_save.receivers, [])
View
16 tests/modeltests/test_client/models.py
@@ -70,7 +70,7 @@ def test_post(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['data'], '37')
self.assertEqual(response.template.name, 'POST Template')
- self.failUnless('Data received' in response.content)
+ self.assertTrue('Data received' in response.content)
def test_response_headers(self):
"Check the value of HTTP headers returned in a response"
@@ -275,7 +275,7 @@ def test_view_with_login(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Request a page that requires a login
response = self.client.get('/test_client/login_protected_view/')
@@ -291,7 +291,7 @@ def test_view_with_method_login(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Request a page that requires a login
response = self.client.get('/test_client/login_protected_method_view/')
@@ -307,7 +307,7 @@ def test_view_with_login_and_custom_redirect(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Request a page that requires a login
response = self.client.get('/test_client/login_protected_view_custom_redirect/')
@@ -318,13 +318,13 @@ def test_view_with_bad_login(self):
"Request a page that is protected with @login, but use bad credentials"
login = self.client.login(username='otheruser', password='nopassword')
- self.failIf(login)
+ self.assertFalse(login)
def test_view_with_inactive_login(self):
"Request a page that is protected with @login, but use an inactive login"
login = self.client.login(username='inactive', password='password')
- self.failIf(login)
+ self.assertFalse(login)
def test_logout(self):
"Request a logout after logging in"
@@ -352,7 +352,7 @@ def test_view_with_permissions(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Log in with wrong permissions. Should result in 302.
response = self.client.get('/test_client/permission_protected_view/')
@@ -369,7 +369,7 @@ def test_view_with_method_permissions(self):
# Log in
login = self.client.login(username='testclient', password='password')
- self.failUnless(login, 'Could not log in')
+ self.assertTrue(login, 'Could not log in')
# Log in with wrong permissions. Should result in 302.
response = self.client.get('/test_client/permission_protected_method_view/')
View
19 tests/modeltests/update/tests.py
@@ -2,6 +2,7 @@
from models import A, B, C, D, DataPoint, RelatedPoint
+
class SimpleTest(TestCase):
def setUp(self):
self.a1 = A.objects.create()
@@ -15,18 +16,18 @@ def test_nonempty_update(self):
Test that update changes the right number of rows for a nonempty queryset
"""
num_updated = self.a1.b_set.update(y=100)
- self.failUnlessEqual(num_updated, 20)
+ self.assertEqual(num_updated, 20)
cnt = B.objects.filter(y=100).count()
- self.failUnlessEqual(cnt, 20)
+ self.assertEqual(cnt, 20)
def test_empty_update(self):
"""
Test that update changes the right number of rows for an empty queryset
"""
num_updated = self.a2.b_set.update(y=100)
- self.failUnlessEqual(num_updated, 0)
+ self.assertEqual(num_updated, 0)
cnt = B.objects.filter(y=100).count()
- self.failUnlessEqual(cnt, 0)
+ self.assertEqual(cnt, 0)
def test_nonempty_update_with_inheritance(self):
"""
@@ -34,9 +35,9 @@ def test_nonempty_update_with_inheritance(self):
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 @@ def test_empty_update_with_inheritance(self):
when the update affects only a base table
"""
num_updated = self.a2.d_set.update(y=100)
- self.failUnlessEqual(num_updated, 0)
+ self.assertEqual(num_updated, 0)
cnt = D.objects.filter(y=100).count()
- self.failUnlessEqual(cnt, 0)
+ self.assertEqual(cnt, 0)
class AdvancedTests(TestCase):
@@ -112,4 +113,4 @@ def test_update_slice_fail(self):
"""
method = DataPoint.objects.all()[:2].update
self.assertRaises(AssertionError, method,
- another_value='another thing')
+ another_value='another thing')
View
22 tests/regressiontests/admin_changelist/tests.py
@@ -11,8 +11,8 @@ def test_select_related_preserved(self):
overwrite a custom select_related provided by ModelAdmin.queryset().
"""
m = ChildAdmin(Child, admin.site)
- cl = ChangeList(MockRequest(), Child, m.list_display, m.list_display_links,
- m.list_filter, m.date_hierarchy, m.search_fields,
+ cl = ChangeList(MockRequest(), Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_editable, m)
self.assertEqual(cl.query_set.query.select_related, {'parent': {'name': {}}})
@@ -25,24 +25,24 @@ def test_result_list_html(self):
new_child = Child.objects.create(name='name', parent=new_parent)
request = MockRequest()
m = ChildAdmin(Child, admin.site)
- cl = ChangeList(request, Child, m.list_display, m.list_display_links,
- m.list_filter, m.date_hierarchy, m.search_fields,
+ cl = ChangeList(request, Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_editable, m)
cl.formset = None
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
context = Context({'cl': cl})
table_output = template.render(context)
row_html = '<tbody><tr class="row1"><td><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td>Parent object</td></tr></tbody>'
- self.failIf(table_output.find(row_html) == -1,
+ self.assertFalse(table_output.find(row_html) == -1,
'Failed to find expected row element: %s' % table_output)
def test_result_list_editable_html(self):
"""
- Regression tests for #11791: Inclusion tag result_list generates a
+ Regression tests for #11791: Inclusion tag result_list generates a
table and this checks that the items are nested within the table
element tags.
Also a regression test for #13599, verifies that hidden fields
- when list_editable is enabled are rendered in a div outside the
+ when list_editable is enabled are rendered in a div outside the
table.
"""
new_parent = Parent.objects.create(name='parent')
@@ -54,8 +54,8 @@ def test_result_list_editable_html(self):
m.list_display = ['id', 'name', 'parent']
m.list_display_links = ['id']
m.list_editable = ['name']
- cl = ChangeList(request, Child, m.list_display, m.list_display_links,
- m.list_filter, m.date_hierarchy, m.search_fields,
+ cl = ChangeList(request, Child, m.list_display, m.list_display_links,
+ m.list_filter, m.date_hierarchy, m.search_fields,
m.list_select_related, m.list_per_page, m.list_editable, m)
FormSet = m.get_changelist_formset(request)
cl.formset = FormSet(queryset=cl.result_list)
@@ -64,11 +64,11 @@ def test_result_list_editable_html(self):
table_output = template.render(context)
# make sure that hidden fields are in the correct place
hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></div>'
- self.failIf(table_output.find(hiddenfields_div) == -1,
+ self.assertFalse(table_output.find(hiddenfields_div) == -1,
'Failed to find hidden fields in: %s' % table_output)
# make sure that list editable fields are rendered in divs correctly
editable_name_field = '<input name="form-0-name" value="name" class="vTextField" maxlength="30" type="text" id="id_form-0-name" />'
- self.failIf('<td>%s</td>' % editable_name_field == -1,
+ self.assertFalse('<td>%s</td>' % editable_name_field == -1,
'Failed to find "name" list_editable field in: %s' % table_output)
class ChildAdmin(admin.ModelAdmin):
View
14 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 @@ def setUp(self):
self.change_url = '/test_admin/admin/admin_inlines/holder/%i/' % holder.id
result = self.client.login(username='super', password='secret')
- self.failUnlessEqual(result, True)
+ self.assertEqual(result, True)
def tearDown(self):
self.client.logout()
@@ -75,7 +73,7 @@ class TestInlineMedia(TestCase):
def setUp(self):
result = self.client.login(username='super', password='secret')
- self.failUnlessEqual(result, True)
+ self.assertEqual(result, True)
def tearDown(self):
self.client.logout()
View
3  tests/regressiontests/admin_scripts/tests.py
@@ -12,6 +12,7 @@
from django import conf, bin, get_version
from django.conf import settings
+
class AdminScriptTestCase(unittest.TestCase):
def write_settings(self, filename, apps=None, is_dir=False, sdict=None):
test_dir = os.path.dirname(os.path.dirname(__file__))
@@ -156,7 +157,7 @@ def assertNoOutput(self, stream):
self.assertEquals(len(stream), 0, "Stream should be empty: actually contains '%s'" % stream)
def assertOutput(self, stream, msg):
"Utility assertion: assert that the given message exists in the output"
- self.failUnless(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
+ self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
##########################################################################
# DJANGO ADMIN TESTS
View
423 tests/regressiontests/admin_views/tests.py
@@ -2,9 +2,11 @@
import re
import datetime
+
from django.conf import settings
from django.core.files import temp as tempfile
-from django.contrib.auth import 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
@@ -58,12 +60,12 @@ def testBasicAddGet(self):
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."
)
@@ -73,7 +75,7 @@ def testBasicEditGet(self):
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):
"""
@@ -82,7 +84,7 @@ def testBasicEditGetStringPK(self):
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):
"""
@@ -96,7 +98,7 @@ def testBasicAddPost(self):
"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 = {
@@ -144,7 +146,7 @@ def testBasicEditPost(self):
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):
"""
@@ -160,7 +162,7 @@ def testEditSaveAs(self):
"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):
"""
@@ -168,8 +170,8 @@ def testChangeListSortingCallable(self):
(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."
@@ -181,8 +183,8 @@ def testChangeListSortingModel(self):
(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."
@@ -194,8 +196,8 @@ def testChangeListSortingModelAdmin(self):
(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."
@@ -204,12 +206,12 @@ def testChangeListSortingModelAdmin(self):
def testLimitedFilter(self):
"""Ensure admin changelist filters do not contain objects excluded via limit_choices_to."""
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(
'<div id="changelist-filter">' in response.content,
"Expected filter not found in changelist view."
)
- self.failIf(
+ self.assertFalse(
'<a href="?color__id__exact=3">Blue</a>' in response.content,
"Changelist filter not correctly limited by limit_choices_to."
)
@@ -233,8 +235,8 @@ def testIsNullLookups(self):
def testLogoutAndPasswordChangeURLs(self):
response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
- self.failIf('<a href="/test_admin/%s/logout/">' % self.urlbit not in response.content)
- self.failIf('<a href="/test_admin/%s/password_change/">' % self.urlbit not in response.content)
+ self.assertFalse('<a href="/test_admin/%s/logout/">' % self.urlbit not in response.content)
+ self.assertFalse('<a href="/test_admin/%s/password_change/">' % self.urlbit not in response.content)
def testNamedGroupFieldChoicesChangeList(self):
"""
@@ -243,8 +245,8 @@ def testNamedGroupFieldChoicesChangeList(self):
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(
'<a href="1/">Horizontal</a>' in response.content and
'<a href="2/">Vertical</a>' in response.content,
"Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group."
@@ -256,12 +258,12 @@ def testNamedGroupFieldChoicesFilter(self):
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(
'<div id="changelist-filter">' in response.content,
"Expected filter not found in changelist view."
)
- self.failUnless(
+ self.assertTrue(
'<a href="?surface__exact=x">Horizontal</a>' in response.content and
'<a href="?surface__exact=y">Vertical</a>' in response.content,
"Changelist filter isn't showing options contained inside a model field 'choices' option named group."
@@ -273,7 +275,7 @@ def testChangeListNullBooleanDisplay(self):
# 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):
"""
@@ -440,15 +442,15 @@ def testLogin(self):
"""
# 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
@@ -462,50 +464,51 @@ def testLogin(self):
# 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)
- # Login.context is a list of context dicts we just need to check the first one.
- self.assert_(login.context[0].get('error_message'))
+ 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)
- # Login.context is a list of context dicts we just need to check the first one.
+ self.assertEqual(login.status_code, 200)
+ form = login.context[0].get('form')
self.assert_(login.context[0].get('error_message'))
def testLoginSuccessfullyRedirectsToOriginalUrl(self):
request = self.client.get('/test_admin/admin/')
- self.failUnlessEqual(request.status_code, 200)
- query_string = "the-answer=42"
- login = self.client.post('/test_admin/admin/', self.super_login, QUERY_STRING = query_string )
- self.assertRedirects(login, '/test_admin/admin/?%s' % query_string)
+ 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}
+ login = self.client.post('/test_admin/admin/', dict(self.super_login, **new_next), QUERY_STRING=query_string)
+ self.assertRedirects(login, redirect_url)
def testAddView(self):
"""Test add view restricts access and actually adds items."""
@@ -519,38 +522,38 @@ def testAddView(self):
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 = '<a href="../">Articles</a> &rsaquo;'
- 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.client.get('/test_admin/admin/logout/')
# Super can add too, but is redirected to the change list view
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
@@ -560,7 +563,7 @@ def testAddView(self):
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."""
@@ -574,34 +577,34 @@ def testChangeView(self):
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, '<p>edited article</p>')
+ self.assertEqual(Article.objects.get(pk=1).content, '<p>edited article</p>')
# 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/')
@@ -611,7 +614,7 @@ def testCustomModelAdminTemplates(self):
# 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')
@@ -626,7 +629,7 @@ def testCustomModelAdminTemplates(self):
'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
@@ -654,10 +657,10 @@ def testDeleteView(self):
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
@@ -668,13 +671,13 @@ def testDeleteView(self):
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)
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):
@@ -707,7 +710,7 @@ def test_nesting(self):
"""
pattern = re.compile(r"""<li>Plot: <a href=".+/admin_views/plot/1/">World Domination</a>\s*<ul>\s*<li>Plot details: <a href=".+/admin_views/plotdetails/1/">almost finished</a>""")
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):
"""
@@ -728,7 +731,7 @@ def test_perms_needed(self):
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))
@@ -816,13 +819,13 @@ def test_get_history_view(self):
"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"
@@ -932,10 +935,12 @@ def test_secure_view_shows_login_if_not_logged_in(self):
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)
- query_string = "the-answer=42"
- login = self.client.post('/test_admin/admin/secure-view/', self.super_login, QUERY_STRING = query_string )
- self.assertRedirects(login, '/test_admin/admin/secure-view/?%s' % query_string)
+ 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}
+ login = self.client.post('/test_admin/admin/secure-view/', dict(self.super_login, **new_next), QUERY_STRING=query_string)
+ self.assertRedirects(login, redirect_url)
def test_staff_member_required_decorator_works_as_per_admin_login(self):
"""
@@ -947,17 +952,17 @@ def test_staff_member_required_decorator_works_as_per_admin_login(self):
"""
# 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
@@ -971,33 +976,33 @@ def test_staff_member_required_decorator_works_as_per_admin_login(self):
# 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.assert_(login.context[0].get('error_message'))
@@ -1008,7 +1013,7 @@ def test_staff_member_required_decorator_works_as_per_admin_login(self):
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']
@@ -1050,7 +1055,7 @@ def testUnicodeEdit(self):
}
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):
"""
@@ -1058,7 +1063,7 @@ def testUnicodeDelete(self):
"""
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/')
@@ -1076,17 +1081,17 @@ def test_inheritance(self):
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/')
@@ -1098,9 +1103,9 @@ def test_changelist_input_html(self):
# 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("<input"), 18)
+ self.assertEqual(response.content.count("<input"), 18)
# 1 select per object = 3 selects
- self.failUnlessEqual(response.content.count("<select"), 4)
+ self.assertEqual(response.content.count("<select"), 4)
def test_post_messages(self):
# Ticket 12707: Saving inline editable should not show admin
@@ -1146,8 +1151,8 @@ def test_post_submission(self):
}
self.client.post('/test_admin/admin/admin_views/person/', data)
- self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
- self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 2)
+ self.assertEqual(Person.objects.get(name="John Mauchly").alive, False)
+ self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 2)
# test a filtered page
data = {
@@ -1167,7 +1172,7 @@ def test_post_submission(self):
}
self.client.post('/test_admin/admin/admin_views/person/?gender__exact=1', data)
- self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, True)
+ self.assertEqual(Person.objects.get(name="John Mauchly").alive, True)
# test a searched page
data = {
@@ -1182,7 +1187,7 @@ def test_post_submission(self):
}
self.client.post('/test_admin/admin/admin_views/person/?q=mauchly', data)
- self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
+ self.assertEqual(Person.objects.get(name="John Mauchly").alive, False)
def test_non_form_errors(self):
# test if non-form errors are handled; ticket #12716
@@ -1256,13 +1261,13 @@ def test_list_editable_ordering(self):
}
response = self.client.post('/test_admin/admin/admin_views/category/', 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(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(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)
def test_list_editable_action_submit(self):
# List editable changes should not be executed if the action "Go" button is
@@ -1288,8 +1293,8 @@ def test_list_editable_action_submit(self):
}
self.client.post('/test_admin/admin/admin_views/person/', data)
- self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, True)
- self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 1)
+ self.assertEqual(Person.objects.get(name="John Mauchly").alive, True)
+ self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 1)
def test_list_editable_action_choices(self):
# List editable changes should be executed if the "Save" button is
@@ -1315,8 +1320,8 @@ def test_list_editable_action_choices(self):
}
self.client.post('/test_admin/admin/admin_views/person/', data)
- self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
- self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 2)
+ self.assertEqual(Person.objects.get(name="John Mauchly").alive, False)
+ self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 2)
@@ -1357,7 +1362,7 @@ def testInline(self):
response = self.client.get('/test_admin/admin/admin_views/persona/add/')
names = name_re.findall(response.content)
# make sure we have no duplicate HTML names
- self.failUnlessEqual(len(names), len(set(names)))
+ self.assertEqual(len(names), len(set(names)))
# test the add case
post_data = {
@@ -1374,20 +1379,20 @@ def testInline(self):
}
response = self.client.post('/test_admin/admin/admin_views/persona/add/', post_data)
- self.failUnlessEqual(response.status_code, 302) # redirect somewhere
- self.failUnlessEqual(Persona.objects.count(), 1)
- self.failUnlessEqual(FooAccount.objects.count(), 1)
- self.failUnlessEqual(BarAccount.objects.count(), 1)
- self.failUnlessEqual(FooAccount.objects.all()[0].username, foo_user)
- self.failUnlessEqual(BarAccount.objects.all()[0].username, bar_user)
- self.failUnlessEqual(Persona.objects.all()[0].accounts.count(), 2)
+ self.assertEqual(response.status_code, 302) # redirect somewhere
+ self.assertEqual(Persona.objects.count(), 1)
+ self.assertEqual(FooAccount.objects.count(), 1)
+ self.assertEqual(BarAccount.objects.count(), 1)
+ self.assertEqual(FooAccount.objects.all()[0].username, foo_user)
+ self.assertEqual(BarAccount.objects.all()[0].username, bar_user)
+ self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
# test the edit case
response = self.client.get('/test_admin/admin/admin_views/persona/1/')
names = name_re.findall(response.content)
# make sure we have no duplicate HTML names
- self.failUnlessEqual(len(names), len(set(names)))
+ self.assertEqual(len(names), len(set(names)))
post_data = {
"name": u"Test Name",
@@ -1409,13 +1414,13 @@ def testInline(self):
"accounts-2-0-persona": "1",
}
response = self.client.post('/test_admin/admin/admin_views/persona/1/', post_data)
- self.failUnlessEqual(response.status_code, 302)
- self.failUnlessEqual(Persona.objects.count(), 1)
- self.failUnlessEqual(FooAccount.objects.count(), 1)
- self.failUnlessEqual(BarAccount.objects.count(), 1)
- self.failUnlessEqual(FooAccount.objects.all()[0].username, "%s-1" % foo_user)
- self.failUnlessEqual(BarAccount.objects.all()[0].username, "%s-1" % bar_user)
- self.failUnlessEqual(Persona.objects.all()[0].accounts.count(), 2)
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(Persona.objects.count(), 1)
+ self.assertEqual(FooAccount.objects.count(), 1)
+ self.assertEqual(BarAccount.objects.count(), 1)
+ self.assertEqual(FooAccount.objects.all()[0].username, "%s-1" % foo_user)
+ self.assertEqual(BarAccount.objects.all()[0].username, "%s-1" % bar_user)
+ self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
from django.core import mail
@@ -1453,9 +1458,9 @@ def test_model_admin_default_delete_action(self):
}
confirmation = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
self.assertContains(confirmation, "Are you sure you want to delete the selected subscriber objects")
- self.failUnless(confirmation.content.count(ACTION_CHECKBOX_NAME) == 2)
+ self.assertTrue(confirmation.content.count(ACTION_CHECKBOX_NAME) == 2)
response = self.client.post('/test_admin/admin/admin_views/subscriber/', delete_confirmation_data)
- self.failUnlessEqual(Subscriber.objects.count(), 0)
+ self.assertEqual(Subscriber.objects.count(), 0)
def test_custom_function_mail_action(self):
"Tests a custom action defined in a function"
@@ -1476,7 +1481,7 @@ def test_custom_function_action_with_redirect(self):
'index': 0,
}
response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
- self.failUnlessEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
def test_default_redirect(self):
"""
@@ -1548,7 +1553,7 @@ def test_user_message_on_none_selected(self):
response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
msg = """Items must be selected in order to perform actions on them. No items have been changed."""
self.assertContains(response, msg)
- self.failUnlessEqual(Subscriber.objects.count(), 2)
+ self.assertEqual(Subscriber.objects.count(), 2)
def test_user_message_on_no_action(self):
"""
@@ -1562,7 +1567,7 @@ def test_user_message_on_no_action(self):
response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
msg = """No action selected."""
self.assertContains(response, msg)
- self.failUnlessEqual(Subscriber.objects.count(), 2)
+ self.assertEqual(Subscriber.objects.count(), 2)
def test_selection_counter(self):
"""
@@ -1578,7 +1583,7 @@ class TestCustomChangeList(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()
@@ -1590,12 +1595,12 @@ def test_custom_changelist(self):
# Insert some data
post_data = {"name": u"First Gadget"}
response = self.client.post('/test_admin/%s/admin_views/gadget/add/' % self.urlbit, post_data)
- self.failUnlessEqual(response.status_code, 302) # redirect somewhere
+ self.assertEqual(response.status_code, 302) # redirect somewhere
# Hit the page once to get messages out of the queue message list
response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit)
# Ensure that that data is still not visible on the page
response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit)
- self.failUnlessEqual(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
self.assertNotContains(response, 'First Gadget')
@@ -1604,7 +1609,7 @@ class TestInlineNotEditable(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()
@@ -1614,7 +1619,7 @@ def test(self):
InlineModelAdmin broken?
"""
response = self.client.get('/test_admin/admin/admin_views/parent/add/')
- self.failUnlessEqual(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
class AdminCustomQuerysetTest(TestCase):
fixtures = ['admin-views-users.xml']
@@ -1681,7 +1686,7 @@ def test_inline_file_upload_edit_validation_error_post(self):
"pictures-1-image": "",
}
response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data)
- self.failUnless(response._container[0].find("Currently:") > -1)
+ self.assertTrue(response._container[0].find("Currently:") > -1)
class AdminInlineTests(TestCase):
@@ -1774,7 +1779,7 @@ def setUp(self):
}
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()
@@ -1786,9 +1791,9 @@ def test_simple_inline(self):
# 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/')
@@ -1799,27 +1804,27 @@ def test_simple_inline(self):
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/')
@@ -1830,18 +1835,18 @@ def test_explicit_autofield_inline(self):
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"
@@ -1849,9 +1854,9 @@ def test_char_pk_inline(self):
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/')
@@ -1862,18 +1867,18 @@ def test_char_pk_inline(self):
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"
@@ -1881,9 +1886,9 @@ def test_integer_pk_inline(self):
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/')
@@ -1894,27 +1899,27 @@ def test_integer_pk_inline(self):
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/')
@@ -1925,18 +1930,18 @@ def test_inherited_inline(self):
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
@@ -1985,14 +1990,14 @@ def test_ordered_inline(self):
})
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):
@@ -2007,64 +2012,64 @@ def tearDown(self):
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):
@@ -2273,5 +2278,5 @@ def tearDown(self):
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)
View
2  tests/regressiontests/admin_widgets/tests.py
@@ -142,7 +142,7 @@ def tearDown(self):
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):
View
10 tests/regressiontests/app_loading/tests.py
@@ -47,28 +47,28 @@ def test_egg1(self):
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 @@ def test_egg5(self):
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])
View
4 tests/regressiontests/bug8245/tests.py
@@ -13,7 +13,7 @@ def test_bug_8245(self):
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.')
@@ -23,7 +23,7 @@ def test_bug_8245(self):
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.')
View
2  tests/regressiontests/builtin_server/tests.py
@@ -47,5 +47,5 @@ def test_file_wrapper_no_sendfile(self):
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!')
View
17 tests/regressiontests/comment_tests/tests/comment_form_tests.py
@@ -1,18 +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)
@@ -25,7 +28,7 @@ def tamperWithForm(self, **kwargs):
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):
@@ -70,12 +73,12 @@ def testProfanities(self):
# 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
View
10 tests/regressiontests/comment_tests/tests/comment_view_tests.py
@@ -199,7 +199,7 @@ def receive(sender, **kwargs):
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 @@ def testCommentNext(self):
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 @@ def testCommentDoneView(self):
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 @@ def testCommentNextWithQueryString(self):
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):
"""
View
5 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()
View
28 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.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
-from django.contrib.comments import signals
+
class FlagViewTests(CommentTestCase):
@@ -35,7 +37,7 @@ def testFlagPostTwice(self):
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 @@ def testFlagAnon(self):
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 @@ def testDeletePost(self):
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 @@ def receive(sender, **kwargs):
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 @@ def testApprovePost(self):
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 @@ def receive(sender, **kwargs):
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:
View
32 tests/regressiontests/file_storage/tests.py
@@ -7,13 +7,13 @@
import unittest
from cStringIO import StringIO
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 unittest import TestCase
+
try:
import threading
except ImportError:
@@ -81,21 +81,21 @@ def test_get_nonexisting_storage_module(self):
class FileStorageTests(unittest.TestCase):
storage_class = FileSystemStorage
-
+
def setUp(self):
self.temp_dir = tempfile.mktemp()
os.makedirs(self.temp_dir)
self.storage = self.storage_class(location=self.temp_dir,
base_url='/test_media_url/')
-
+
def tearDown(self):
shutil.rmtree(self.temp_dir)
-
+
def test_file_access_options(self):
"""
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()
@@ -104,16 +104,16 @@ def test_file_access_options(self):
f = self.storage.open('storage_test', 'r')
self.assertEqual(f.read(), 'storage contents')
f.close()
-
+
self.storage.delete('storage_test')