Permalink
Browse files

Updated test assertions that have been deprecated by the move to unit…

…test2. In summary, this means:

 assert_ -> assertTrue
 assertEquals -> assertEqual
 failUnless -> assertTrue

For full details, see http://www.voidspace.org.uk/python/articles/unittest2.shtml#deprecations

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15728 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent b7c41c1 commit afd040d4d3a06fe92e3080870b2ff2095ce86a75 @freakboy3742 freakboy3742 committed Mar 3, 2011
Showing with 1,198 additions and 1,198 deletions.
  1. +3 −3 django/contrib/auth/tests/basic.py
  2. +1 −1 django/contrib/auth/tests/decorators.py
  3. +4 −4 django/contrib/auth/tests/remote_user.py
  4. +57 −57 django/contrib/auth/tests/views.py
  5. +8 −8 django/contrib/flatpages/tests/csrf.py
  6. +6 −6 django/contrib/flatpages/tests/middleware.py
  7. +7 −7 django/contrib/flatpages/tests/templatetags.py
  8. +6 −6 django/contrib/flatpages/tests/views.py
  9. +8 −8 django/contrib/formtools/tests/__init__.py
  10. +2 −2 django/contrib/gis/gdal/tests/test_geom.py
  11. +9 −9 django/contrib/gis/geos/tests/test_geos.py
  12. +17 −17 django/contrib/gis/geos/tests/test_mutable_list.py
  13. +6 −6 django/contrib/gis/tests/geo3d/tests.py
  14. +5 −5 django/contrib/gis/tests/geoapp/tests.py
  15. +4 −4 django/contrib/gis/tests/relatedapp/tests.py
  16. +1 −1 django/contrib/gis/tests/test_geoforms.py
  17. +7 −7 django/contrib/gis/tests/test_measure.py
  18. +4 −4 django/contrib/messages/tests/base.py
  19. +1 −1 django/contrib/messages/tests/cookie.py
  20. +6 −6 django/contrib/sitemaps/tests/basic.py
  21. +3 −3 django/contrib/sites/tests.py
  22. +4 −4 django/utils/unittest/case.py
  23. +1 −1 docs/topics/testing.txt
  24. +1 −1 tests/modeltests/aggregation/tests.py
  25. +1 −1 tests/modeltests/model_formsets/tests.py
  26. +2 −2 tests/modeltests/model_inheritance_same_model_name/tests.py
  27. +2 −2 tests/modeltests/proxy_model_inheritance/tests.py
  28. +5 −5 tests/modeltests/raw_query/tests.py
  29. +1 −1 tests/modeltests/serializers/tests.py
  30. +3 −3 tests/modeltests/test_client/models.py
  31. +2 −2 tests/modeltests/unmanaged_models/tests.py
  32. +2 −2 tests/modeltests/user_commands/tests.py
  33. +2 −2 tests/modeltests/validation/__init__.py
  34. +6 −6 tests/modeltests/validators/tests.py
  35. +30 −30 tests/regressiontests/admin_filterspecs/tests.py
  36. +2 −2 tests/regressiontests/admin_scripts/tests.py
  37. +17 −17 tests/regressiontests/admin_util/tests.py
  38. +31 −31 tests/regressiontests/admin_views/tests.py
  39. +3 −3 tests/regressiontests/admin_widgets/tests.py
  40. +9 −9 tests/regressiontests/aggregation_regress/tests.py
  41. +1 −1 tests/regressiontests/app_loading/tests.py
  42. +1 −1 tests/regressiontests/builtin_server/tests.py
  43. +42 −42 tests/regressiontests/cache/tests.py
  44. +3 −3 tests/regressiontests/comment_tests/tests/comment_form_tests.py
  45. +6 −6 tests/regressiontests/comment_tests/tests/comment_utils_moderators_tests.py
  46. +3 −3 tests/regressiontests/comment_tests/tests/comment_view_tests.py
  47. +2 −2 tests/regressiontests/comment_tests/tests/feed_tests.py
  48. +3 −3 tests/regressiontests/comment_tests/tests/moderation_view_tests.py
  49. +5 −5 tests/regressiontests/comment_tests/tests/templatetag_tests.py
  50. +10 −10 tests/regressiontests/conditional_processing/models.py
  51. +13 −13 tests/regressiontests/csrf_tests/tests.py
  52. +3 −3 tests/regressiontests/datatypes/tests.py
  53. +3 −3 tests/regressiontests/decorators/tests.py
  54. +7 −7 tests/regressiontests/delete_regress/tests.py
  55. +1 −1 tests/regressiontests/dispatch/tests/test_dispatcher.py
  56. +6 −6 tests/regressiontests/dispatch/tests/test_saferef.py
  57. +12 −12 tests/regressiontests/file_storage/tests.py
  58. +5 −5 tests/regressiontests/file_uploads/tests.py
  59. +1 −1 tests/regressiontests/forms/localflavor/fi.py
  60. +1 −1 tests/regressiontests/forms/localflavor/us.py
  61. +4 −4 tests/regressiontests/forms/tests/formsets.py
  62. +4 −4 tests/regressiontests/forms/tests/models.py
  63. +11 −11 tests/regressiontests/generic_inline_admin/tests.py
  64. +11 −11 tests/regressiontests/generic_views/base.py
  65. +2 −2 tests/regressiontests/httpwrappers/tests.py
  66. +17 −17 tests/regressiontests/i18n/commands/extraction.py
  67. +1 −1 tests/regressiontests/i18n/tests.py
  68. +4 −4 tests/regressiontests/introspection/tests.py
  69. +1 −1 tests/regressiontests/mail/tests.py
  70. +1 −1 tests/regressiontests/max_lengths/tests.py
  71. +37 −37 tests/regressiontests/middleware/tests.py
  72. +2 −2 tests/regressiontests/middleware_exceptions/tests.py
  73. +2 −2 tests/regressiontests/model_fields/tests.py
  74. +19 −19 tests/regressiontests/model_forms_regress/tests.py
  75. +3 −3 tests/regressiontests/model_inheritance_regress/tests.py
  76. +1 −1 tests/regressiontests/modeladmin/tests.py
  77. +268 −268 tests/regressiontests/multiple_database/tests.py
  78. +2 −2 tests/regressiontests/null_fk/tests.py
  79. +1 −1 tests/regressiontests/null_queries/tests.py
  80. +2 −2 tests/regressiontests/one_to_one_regress/tests.py
  81. +5 −5 tests/regressiontests/queries/tests.py
  82. +2 −2 tests/regressiontests/reverse_single_related/tests.py
  83. +23 −23 tests/regressiontests/select_related_regress/tests.py
  84. +1 −1 tests/regressiontests/serializers_regress/tests.py
  85. +5 −5 tests/regressiontests/signals_regress/tests.py
  86. +5 −5 tests/regressiontests/staticfiles_tests/tests.py
  87. +9 −9 tests/regressiontests/string_lookup/tests.py
  88. +4 −4 tests/regressiontests/syndication/tests.py
  89. +8 −8 tests/regressiontests/templates/custom.py
  90. +7 −7 tests/regressiontests/templates/response.py
  91. +2 −2 tests/regressiontests/templates/smartif.py
  92. +2 −2 tests/regressiontests/templates/tests.py
  93. +20 −20 tests/regressiontests/test_client_regress/models.py
  94. +22 −22 tests/regressiontests/text/tests.py
  95. +1 −1 tests/regressiontests/transactions_regress/tests.py
  96. +40 −40 tests/regressiontests/urlpatterns_reverse/tests.py
  97. +48 −48 tests/regressiontests/utils/datastructures.py
  98. +45 −45 tests/regressiontests/utils/dateformat.py
  99. +8 −8 tests/regressiontests/utils/datetime_safe.py
  100. +1 −1 tests/regressiontests/utils/simplelazyobject.py
  101. +42 −42 tests/regressiontests/utils/termcolors.py
  102. +31 −31 tests/regressiontests/utils/timesince.py
  103. +11 −11 tests/regressiontests/utils/tzinfo.py
  104. +2 −2 tests/regressiontests/views/tests/debug.py
  105. +7 −7 tests/regressiontests/views/tests/defaults.py
  106. +2 −2 tests/regressiontests/views/tests/generic/create_update.py
  107. +1 −1 tests/regressiontests/views/tests/i18n.py
  108. +22 −22 tests/regressiontests/views/tests/shortcuts.py
  109. +10 −10 tests/regressiontests/views/tests/static.py
  110. +2 −2 tests/runtests.py
@@ -61,7 +61,7 @@ def test_createsuperuser_management_command(self):
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, 'Superuser created successfully.')
u = User.objects.get(username="joe")
- self.assertEquals(u.email, 'joe@somewhere.org')
+ self.assertEqual(u.email, 'joe@somewhere.org')
# created password should be unusable
self.assertFalse(u.has_usable_password())
@@ -78,7 +78,7 @@ def test_createsuperuser_management_command(self):
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, '')
u = User.objects.get(username="joe2")
- self.assertEquals(u.email, 'joe2@somewhere.org')
+ self.assertEqual(u.email, 'joe2@somewhere.org')
self.assertFalse(u.has_usable_password())
@@ -90,6 +90,6 @@ def test_createsuperuser_management_command(self):
stdout=new_io
)
u = User.objects.get(username="joe+admin@somewhere.org")
- self.assertEquals(u.email, 'joe@somewhere.org')
+ self.assertEqual(u.email, 'joe@somewhere.org')
self.assertFalse(u.has_usable_password())
@@ -32,7 +32,7 @@ def testLoginRequired(self, view_url='/login_required/', login_url=settings.LOGI
"""
response = self.client.get(view_url)
self.assertEqual(response.status_code, 302)
- self.assert_(login_url in response['Location'])
+ self.assertTrue(login_url in response['Location'])
self.login()
response = self.client.get(view_url)
self.assertEqual(response.status_code, 200)
@@ -30,15 +30,15 @@ def test_no_remote_user(self):
num_users = User.objects.count()
response = self.client.get('/remote_user/')
- self.assert_(response.context['user'].is_anonymous())
+ self.assertTrue(response.context['user'].is_anonymous())
self.assertEqual(User.objects.count(), num_users)
response = self.client.get('/remote_user/', REMOTE_USER=None)
- self.assert_(response.context['user'].is_anonymous())
+ self.assertTrue(response.context['user'].is_anonymous())
self.assertEqual(User.objects.count(), num_users)
response = self.client.get('/remote_user/', REMOTE_USER='')
- self.assert_(response.context['user'].is_anonymous())
+ self.assertTrue(response.context['user'].is_anonymous())
self.assertEqual(User.objects.count(), num_users)
def test_unknown_user(self):
@@ -115,7 +115,7 @@ class that doesn't create unknown users.
def test_unknown_user(self):
num_users = User.objects.count()
response = self.client.get('/remote_user/', REMOTE_USER='newuser')
- self.assert_(response.context['user'].is_anonymous())
+ self.assertTrue(response.context['user'].is_anonymous())
self.assertEqual(User.objects.count(), num_users)
@@ -40,53 +40,53 @@ def login(self, password='password'):
'password': password
}
)
- self.assertEquals(response.status_code, 302)
- self.assert_(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))
- self.assert_(SESSION_KEY in self.client.session)
+ self.assertEqual(response.status_code, 302)
+ self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))
+ self.assertTrue(SESSION_KEY in self.client.session)
class PasswordResetTest(AuthViewsTestCase):
def test_email_not_found(self):
"Error is raised if the provided email address isn't currently registered"
response = self.client.get('/password_reset/')
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
response = self.client.post('/password_reset/', {'email': 'not_a_real_email@email.com'})
self.assertContains(response, "That e-mail address doesn't have an associated user account")
- self.assertEquals(len(mail.outbox), 0)
+ self.assertEqual(len(mail.outbox), 0)
def test_email_found(self):
"Email is sent if a valid email address is provided for password reset"
response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
- self.assertEquals(response.status_code, 302)
- self.assertEquals(len(mail.outbox), 1)
- self.assert_("http://" in mail.outbox[0].body)
- self.assertEquals(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertTrue("http://" in mail.outbox[0].body)
+ self.assertEqual(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)
def test_email_found_custom_from(self):
"Email is sent if a valid email address is provided for password reset when a custom from_email is provided."
response = self.client.post('/password_reset_from_email/', {'email': 'staffmember@example.com'})
- self.assertEquals(response.status_code, 302)
- self.assertEquals(len(mail.outbox), 1)
- self.assertEquals("staffmember@example.com", mail.outbox[0].from_email)
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual("staffmember@example.com", mail.outbox[0].from_email)
def _test_confirm_start(self):
# Start by creating the email
response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
- self.assertEquals(response.status_code, 302)
- self.assertEquals(len(mail.outbox), 1)
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(len(mail.outbox), 1)
return self._read_signup_email(mail.outbox[0])
def _read_signup_email(self, email):
urlmatch = re.search(r"https?://[^/]*(/.*reset/\S*)", email.body)
- self.assert_(urlmatch is not None, "No URL found in sent email")
+ self.assertTrue(urlmatch is not None, "No URL found in sent email")
return urlmatch.group(), urlmatch.groups()[0]
def test_confirm_valid(self):
url, path = self._test_confirm_start()
response = self.client.get(path)
# redirect to a 'complete' page:
- self.assertEquals(response.status_code, 200)
- self.assert_("Please enter your new password" in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("Please enter your new password" in response.content)
def test_confirm_invalid(self):
url, path = self._test_confirm_start()
@@ -95,20 +95,20 @@ def test_confirm_invalid(self):
path = path[:-5] + ("0"*4) + path[-1]
response = self.client.get(path)
- self.assertEquals(response.status_code, 200)
- self.assert_("The password reset link was invalid" in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("The password reset link was invalid" in response.content)
def test_confirm_invalid_user(self):
# Ensure that we get a 200 response for a non-existant user, not a 404
response = self.client.get('/reset/123456-1-1/')
- self.assertEquals(response.status_code, 200)
- self.assert_("The password reset link was invalid" in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("The password reset link was invalid" in response.content)
def test_confirm_overflow_user(self):
# Ensure that we get a 200 response for a base36 user id that overflows int
response = self.client.get('/reset/zzzzzzzzzzzzz-1-1/')
- self.assertEquals(response.status_code, 200)
- self.assert_("The password reset link was invalid" in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("The password reset link was invalid" in response.content)
def test_confirm_invalid_post(self):
# Same as test_confirm_invalid, but trying
@@ -120,29 +120,29 @@ def test_confirm_invalid_post(self):
'new_password2':' anewpassword'})
# Check the password has not been changed
u = User.objects.get(email='staffmember@example.com')
- self.assert_(not u.check_password("anewpassword"))
+ self.assertTrue(not u.check_password("anewpassword"))
def test_confirm_complete(self):
url, path = self._test_confirm_start()
response = self.client.post(path, {'new_password1': 'anewpassword',
'new_password2': 'anewpassword'})
# It redirects us to a 'complete' page:
- self.assertEquals(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
# Check the password has been changed
u = User.objects.get(email='staffmember@example.com')
- self.assert_(u.check_password("anewpassword"))
+ self.assertTrue(u.check_password("anewpassword"))
# Check we can't use the link again
response = self.client.get(path)
- self.assertEquals(response.status_code, 200)
- self.assert_("The password reset link was invalid" in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("The password reset link was invalid" in response.content)
def test_confirm_different_passwords(self):
url, path = self._test_confirm_start()
response = self.client.post(path, {'new_password1': 'anewpassword',
'new_password2':' x'})
- self.assertEquals(response.status_code, 200)
- self.assert_("The two password fields didn't match" in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("The two password fields didn't match" in response.content)
class ChangePasswordTest(AuthViewsTestCase):
@@ -152,8 +152,8 @@ def fail_login(self, password='password'):
'password': password
}
)
- self.assertEquals(response.status_code, 200)
- self.assert_("Please enter a correct username and password. Note that both fields are case-sensitive." in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("Please enter a correct username and password. Note that both fields are case-sensitive." in response.content)
def logout(self):
response = self.client.get('/logout/')
@@ -166,8 +166,8 @@ def test_password_change_fails_with_invalid_old_password(self):
'new_password2': 'password1',
}
)
- self.assertEquals(response.status_code, 200)
- self.assert_("Your old password was entered incorrectly. Please enter it again." in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("Your old password was entered incorrectly. Please enter it again." in response.content)
def test_password_change_fails_with_mismatched_passwords(self):
self.login()
@@ -177,8 +177,8 @@ def test_password_change_fails_with_mismatched_passwords(self):
'new_password2': 'donuts',
}
)
- self.assertEquals(response.status_code, 200)
- self.assert_("The two password fields didn't match." in response.content)
+ self.assertEqual(response.status_code, 200)
+ self.assertTrue("The two password fields didn't match." in response.content)
def test_password_change_succeeds(self):
self.login()
@@ -188,23 +188,23 @@ def test_password_change_succeeds(self):
'new_password2': 'password1',
}
)
- self.assertEquals(response.status_code, 302)
- self.assert_(response['Location'].endswith('/password_change/done/'))
+ self.assertEqual(response.status_code, 302)
+ self.assertTrue(response['Location'].endswith('/password_change/done/'))
self.fail_login()
self.login(password='password1')
class LoginTest(AuthViewsTestCase):
def test_current_site_in_context_after_login(self):
response = self.client.get(reverse('django.contrib.auth.views.login'))
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
if Site._meta.installed:
site = Site.objects.get_current()
- self.assertEquals(response.context['site'], site)
- self.assertEquals(response.context['site_name'], site.name)
+ self.assertEqual(response.context['site'], site)
+ self.assertEqual(response.context['site_name'], site.name)
else:
self.assertIsInstance(response.context['site'], RequestSite)
- self.assert_(isinstance(response.context['form'], AuthenticationForm),
+ self.assertTrue(isinstance(response.context['form'], AuthenticationForm),
'Login form is not an AuthenticationForm')
def test_security_check(self, password='password'):
@@ -226,7 +226,7 @@ def test_security_check(self, password='password'):
'password': password,
}
)
- self.assertEquals(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
self.assertFalse(bad_url in response['Location'],
"%s should be blocked" % bad_url)
@@ -249,14 +249,14 @@ def test_security_check(self, password='password'):
'password': password,
}
)
- self.assertEquals(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
self.assertTrue(good_url in response['Location'],
"%s should be allowed" % good_url)
class LoginURLSettings(AuthViewsTestCase):
urls = 'django.contrib.auth.tests.urls'
-
+
def setUp(self):
super(LoginURLSettings, self).setUp()
self.old_LOGIN_URL = settings.LOGIN_URL
@@ -268,7 +268,7 @@ def tearDown(self):
def get_login_required_url(self, login_url):
settings.LOGIN_URL = login_url
response = self.client.get('/login_required/')
- self.assertEquals(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
return response['Location']
def test_standard_login_url(self):
@@ -317,14 +317,14 @@ class LogoutTest(AuthViewsTestCase):
urls = 'django.contrib.auth.tests.urls'
def confirm_logged_out(self):
- self.assert_(SESSION_KEY not in self.client.session)
+ self.assertTrue(SESSION_KEY not in self.client.session)
def test_logout_default(self):
"Logout without next_page option renders the default template"
self.login()
response = self.client.get('/logout/')
- self.assertEquals(200, response.status_code)
- self.assert_('Logged out' in response.content)
+ self.assertEqual(200, response.status_code)
+ self.assertTrue('Logged out' in response.content)
self.confirm_logged_out()
def test_14377(self):
@@ -338,36 +338,36 @@ def test_logout_with_overridden_redirect_url(self):
self.login()
response = self.client.get('/logout/next_page/')
self.assertEqual(response.status_code, 302)
- self.assert_(response['Location'].endswith('/somewhere/'))
+ self.assertTrue(response['Location'].endswith('/somewhere/'))
response = self.client.get('/logout/next_page/?next=/login/')
self.assertEqual(response.status_code, 302)
- self.assert_(response['Location'].endswith('/login/'))
+ self.assertTrue(response['Location'].endswith('/login/'))
self.confirm_logged_out()
- def test_logout_with_next_page_specified(self):
+ def test_logout_with_next_page_specified(self):
"Logout with next_page option given redirects to specified resource"
self.login()
response = self.client.get('/logout/next_page/')
self.assertEqual(response.status_code, 302)
- self.assert_(response['Location'].endswith('/somewhere/'))
+ self.assertTrue(response['Location'].endswith('/somewhere/'))
self.confirm_logged_out()
def test_logout_with_redirect_argument(self):
"Logout with query string redirects to specified resource"
self.login()
response = self.client.get('/logout/?next=/login/')
self.assertEqual(response.status_code, 302)
- self.assert_(response['Location'].endswith('/login/'))
+ self.assertTrue(response['Location'].endswith('/login/'))
self.confirm_logged_out()
def test_logout_with_custom_redirect_argument(self):
"Logout with custom query string redirects to specified resource"
self.login()
response = self.client.get('/logout/custom_query/?follow=/somewhere/')
self.assertEqual(response.status_code, 302)
- self.assert_(response['Location'].endswith('/somewhere/'))
+ self.assertTrue(response['Location'].endswith('/somewhere/'))
self.confirm_logged_out()
def test_security_check(self, password='password'):
@@ -386,7 +386,7 @@ def test_security_check(self, password='password'):
}
self.login()
response = self.client.get(nasty_url)
- self.assertEquals(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
self.assertFalse(bad_url in response['Location'],
"%s should be blocked" % bad_url)
self.confirm_logged_out()
@@ -407,7 +407,7 @@ def test_security_check(self, password='password'):
}
self.login()
response = self.client.get(safe_url)
- self.assertEquals(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
self.assertTrue(good_url in response['Location'],
"%s should be allowed" % good_url)
self.confirm_logged_out()
Oops, something went wrong.

0 comments on commit afd040d

Please sign in to comment.