Permalink
Browse files

Replaced deprecated TestCase methods. Refs #17049.

  • Loading branch information...
1 parent e84f79f commit b52672d77822e88752cb178c8a359adde83ff0ba @claudep claudep committed May 3, 2012
@@ -50,7 +50,7 @@ def test_that_changepassword_command_changes_joes_password(self):
command.execute("joe", stdout=self.stdout)
command_output = self.stdout.getvalue().strip()
- self.assertEquals(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'")
+ self.assertEqual(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'")
self.assertTrue(models.User.objects.get(username="joe").check_password("not qwerty"))
def test_that_max_tries_exits_1(self):
@@ -46,12 +46,12 @@ class NaturalKeysTestCase(TestCase):
def test_user_natural_key(self):
staff_user = User.objects.get(username='staff')
- self.assertEquals(User.objects.get_by_natural_key('staff'), staff_user)
- self.assertEquals(staff_user.natural_key(), ('staff',))
+ self.assertEqual(User.objects.get_by_natural_key('staff'), staff_user)
+ self.assertEqual(staff_user.natural_key(), ('staff',))
def test_group_natural_key(self):
users_group = Group.objects.create(name='users')
- self.assertEquals(Group.objects.get_by_natural_key('users'), users_group)
+ self.assertEqual(Group.objects.get_by_natural_key('users'), users_group)
@override_settings(USE_TZ=False)
@@ -61,7 +61,7 @@ class LoadDataWithoutNaturalKeysTestCase(TestCase):
def test_user_is_created_and_added_to_group(self):
user = User.objects.get(username='my_username')
group = Group.objects.get(name='my_group')
- self.assertEquals(group, user.groups.get())
+ self.assertEqual(group, user.groups.get())
@override_settings(USE_TZ=False)
@@ -71,31 +71,31 @@ class LoadDataWithNaturalKeysTestCase(TestCase):
def test_user_is_created_and_added_to_group(self):
user = User.objects.get(username='my_username')
group = Group.objects.get(name='my_group')
- self.assertEquals(group, user.groups.get())
+ self.assertEqual(group, user.groups.get())
class UserManagerTestCase(TestCase):
def test_create_user(self):
email_lowercase = 'normal@normal.com'
user = User.objects.create_user('user', email_lowercase)
- self.assertEquals(user.email, email_lowercase)
- self.assertEquals(user.username, 'user')
- self.assertEquals(user.password, '!')
+ self.assertEqual(user.email, email_lowercase)
+ self.assertEqual(user.username, 'user')
+ self.assertEqual(user.password, '!')
def test_create_user_email_domain_normalize_rfc3696(self):
# According to http://tools.ietf.org/html/rfc3696#section-3
# the "@" symbol can be part of the local part of an email address
returned = UserManager.normalize_email(r'Abc\@DEF@EXAMPLE.com')
- self.assertEquals(returned, r'Abc\@DEF@example.com')
+ self.assertEqual(returned, r'Abc\@DEF@example.com')
def test_create_user_email_domain_normalize(self):
returned = UserManager.normalize_email('normal@DOMAIN.COM')
- self.assertEquals(returned, 'normal@domain.com')
+ self.assertEqual(returned, 'normal@domain.com')
def test_create_user_email_domain_normalize_with_whitespace(self):
returned = UserManager.normalize_email('email\ with_whitespace@D.COM')
- self.assertEquals(returned, 'email\ with_whitespace@d.com')
+ self.assertEqual(returned, 'email\ with_whitespace@d.com')
def test_empty_username(self):
self.assertRaisesMessage(ValueError,
@@ -303,7 +303,7 @@ def get_context_data(self, **kwargs):
view = TestWizard.as_view([forms.Form])
response = view(factory.get('/'))
- self.assertEquals(response.context_data['test_key'], 'test_value')
+ self.assertEqual(response.context_data['test_key'], 'test_value')
def test_get_context_data_with_mixin(self):
class AnotherMixin(object):
@@ -329,8 +329,8 @@ def get_context_data(self, **kwargs):
view = TestWizard.as_view([forms.Form])
response = view(factory.get('/'))
- self.assertEquals(response.context_data['test_key'], 'test_value')
- self.assertEquals(response.context_data['another_key'], 'another_value')
+ self.assertEqual(response.context_data['test_key'], 'test_value')
+ self.assertEqual(response.context_data['another_key'], 'another_value')
class WizardFormKwargsOverrideTests(TestCase):
@@ -87,7 +87,7 @@ def test04_city(self):
self.assertEqual('TX', d['region'])
self.assertEqual(713, d['area_code'])
geom = g.geos(query)
- self.failIf(not isinstance(geom, GEOSGeometry))
+ self.assertTrue(isinstance(geom, GEOSGeometry))
lon, lat = (-95.4010, 29.7079)
lat_lon = g.lat_lon(query)
lat_lon = (lat_lon[1], lat_lon[0])
@@ -45,7 +45,7 @@ def testAccess(self):
def testAccessInvalid(self):
"Testing access in invalid units"
d = D(m=100)
- self.failIf(hasattr(d, 'banana'))
+ self.assertFalse(hasattr(d, 'banana'))
def testAddition(self):
"Test addition & subtraction"
@@ -133,7 +133,7 @@ def testComparisons(self):
self.assertTrue(d2 > d1)
self.assertTrue(d1 == d1)
self.assertTrue(d1 < d2)
- self.failIf(d3)
+ self.assertFalse(d3)
def testUnitsStr(self):
"Testing conversion to strings"
@@ -179,7 +179,7 @@ def testAccess(self):
def testAccessInvaliA(self):
"Testing access in invalid units"
a = A(sq_m=100)
- self.failIf(hasattr(a, 'banana'))
+ self.assertFalse(hasattr(a, 'banana'))
def testAddition(self):
"Test addition & subtraction"
@@ -267,7 +267,7 @@ def testComparisons(self):
self.assertTrue(a2 > a1)
self.assertTrue(a1 == a1)
self.assertTrue(a1 < a2)
- self.failIf(a3)
+ self.assertFalse(a3)
def testUnitsStr(self):
"Testing conversion to strings"
@@ -341,7 +341,7 @@ def test_foreignkey(self):
qs = AuthorWithAge.objects.prefetch_related('addresses')
addresses = [[unicode(address) for address in obj.addresses.all()]
for obj in qs]
- self.assertEquals(addresses, [[unicode(self.authorAddress)], [], []])
+ self.assertEqual(addresses, [[unicode(self.authorAddress)], [], []])
def test_m2m_to_inheriting_model(self):
qs = AuthorWithAge.objects.prefetch_related('books_with_year')
@@ -351,7 +351,7 @@ def test_m2m_to_inheriting_model(self):
qs = AuthorWithAge.objects.all()
lst2 = [[unicode(book) for book in author.books_with_year.all()]
for author in qs]
- self.assertEquals(lst, lst2)
+ self.assertEqual(lst, lst2)
qs = BookWithYear.objects.prefetch_related('aged_authors')
with self.assertNumQueries(2):
@@ -360,7 +360,7 @@ def test_m2m_to_inheriting_model(self):
qs = BookWithYear.objects.all()
lst2 = [[unicode(author) for author in book.aged_authors.all()]
for book in qs]
- self.assertEquals(lst, lst2)
+ self.assertEqual(lst, lst2)
def test_parent_link_prefetch(self):
with self.assertNumQueries(2):
@@ -402,7 +402,7 @@ def test_foreignkey(self):
qs = Author.objects.prefetch_related('addresses')
addresses = [[unicode(address) for address in obj.addresses.all()]
for obj in qs]
- self.assertEquals(addresses, [[unicode(self.authorAddress)], [], []])
+ self.assertEqual(addresses, [[unicode(self.authorAddress)], [], []])
def test_m2m(self):
with self.assertNumQueries(3):
@@ -411,7 +411,7 @@ def test_m2m(self):
[unicode(i_like) for i_like in author.favorite_authors.all()],
[unicode(likes_me) for likes_me in author.favors_me.all()]
) for author in qs]
- self.assertEquals(
+ self.assertEqual(
favorites,
[
([unicode(self.author2)],[unicode(self.author3)]),
@@ -549,7 +549,7 @@ def test_using_is_honored_m2m(self):
authors = "".join(["%s: %s\n" %
(author.name, ", ".join(b.title for b in author.books.all()))
for author in qs2])
- self.assertEquals(authors,
+ self.assertEqual(authors,
"Charlotte: Poems, Jane Eyre\n"
"Anne: Poems\n"
"Emily: Poems, Wuthering Heights\n"
@@ -80,7 +80,7 @@ def has_for_update_sql(self, tested_connection, nowait=False):
return bool(sql.find(for_update_sql) > -1)
def check_exc(self, exc):
- self.failUnless(isinstance(exc, DatabaseError))
+ self.assertTrue(isinstance(exc, DatabaseError))
@skipUnlessDBFeature('has_select_for_update')
def test_for_update_sql_generated(self):
@@ -217,7 +217,7 @@ def test_block(self):
# Check the thread has finished. Assuming it has, we should
# find that it has updated the person's name.
- self.failIf(thread.isAlive())
+ self.assertFalse(thread.isAlive())
# We must commit the transaction to ensure that MySQL gets a fresh read,
# since by default it runs in REPEATABLE READ mode
@@ -378,15 +378,15 @@ def test_view_with_permissions_exception(self):
# Get the page without logging in. Should result in 403.
response = self.client.get('/test_client/permission_protected_view_exception/')
- self.assertEquals(response.status_code, 403)
+ self.assertEqual(response.status_code, 403)
# Log in
login = self.client.login(username='testclient', password='password')
self.assertTrue(login, 'Could not log in')
# Log in with wrong permissions. Should result in 403.
response = self.client.get('/test_client/permission_protected_view_exception/')
- self.assertEquals(response.status_code, 403)
+ self.assertEqual(response.status_code, 403)
def test_view_with_method_permissions(self):
"Request a page that is protected with a @permission_required method"
@@ -270,7 +270,7 @@ def test_relatedfieldlistfilter_foreignkey(self):
# Make sure the last choice is None and is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEquals(force_unicode(filterspec.title), u'Verbose Author')
+ self.assertEqual(force_unicode(filterspec.title), u'Verbose Author')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[-1]['selected'], True)
self.assertEqual(choices[-1]['query_string'], '?author__isnull=True')
@@ -280,7 +280,7 @@ def test_relatedfieldlistfilter_foreignkey(self):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEquals(force_unicode(filterspec.title), u'Verbose Author')
+ self.assertEqual(force_unicode(filterspec.title), u'Verbose Author')
# order of choices depends on User model, which has no order
choice = select_by(filterspec.choices(changelist), "display", "alfred")
self.assertEqual(choice['selected'], True)
@@ -298,7 +298,7 @@ def test_relatedfieldlistfilter_manytomany(self):
# Make sure the last choice is None and is selected
filterspec = changelist.get_filters(request)[0][2]
- self.assertEquals(force_unicode(filterspec.title), u'Verbose Contributors')
+ self.assertEqual(force_unicode(filterspec.title), u'Verbose Contributors')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[-1]['selected'], True)
self.assertEqual(choices[-1]['query_string'], '?contributors__isnull=True')
@@ -308,7 +308,7 @@ def test_relatedfieldlistfilter_manytomany(self):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][2]
- self.assertEquals(force_unicode(filterspec.title), u'Verbose Contributors')
+ self.assertEqual(force_unicode(filterspec.title), u'Verbose Contributors')
choice = select_by(filterspec.choices(changelist), "display", "bob")
self.assertEqual(choice['selected'], True)
self.assertEqual(choice['query_string'], '?contributors__id__exact=%d' % self.bob.pk)
@@ -509,7 +509,7 @@ def test_simplelistfilter(self):
self.assertEqual(choices[3]['query_string'], '?publication-decade=the+00s&author__id__exact=%s' % self.alfred.pk)
filterspec = changelist.get_filters(request)[0][0]
- self.assertEquals(force_unicode(filterspec.title), u'Verbose Author')
+ self.assertEqual(force_unicode(filterspec.title), u'Verbose Author')
choice = select_by(filterspec.choices(changelist), "display", "alfred")
self.assertEqual(choice['selected'], True)
self.assertEqual(choice['query_string'], '?publication-decade=the+00s&author__id__exact=%s' % self.alfred.pk)
@@ -405,39 +405,39 @@ def test_add_inlines(self):
# Check that there's only one inline to start with and that it has the
# correct ID.
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set')), 1)
- self.failUnlessEqual(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set')[0].get_attribute('id'),
'profile_set-0')
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set#profile_set-0 input[name=profile_set-0-first_name]')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set#profile_set-0 input[name=profile_set-0-last_name]')), 1)
# Add an inline
self.selenium.find_element_by_link_text('Add another Profile').click()
# Check that the inline has been added, that it has the right id, and
# that it contains the right fields.
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set')), 2)
- self.failUnlessEqual(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set')[1].get_attribute('id'), 'profile_set-1')
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set#profile_set-1 input[name=profile_set-1-first_name]')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set#profile_set-1 input[name=profile_set-1-last_name]')), 1)
# Let's add another one to be sure
self.selenium.find_element_by_link_text('Add another Profile').click()
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set')), 3)
- self.failUnlessEqual(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set')[2].get_attribute('id'), 'profile_set-2')
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set#profile_set-2 input[name=profile_set-2-first_name]')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'.dynamic-profile_set#profile_set-2 input[name=profile_set-2-last_name]')), 1)
# Enter some data and click 'Save'
@@ -473,17 +473,17 @@ def test_delete_inlines(self):
self.selenium.find_element_by_link_text('Add another Profile').click()
self.selenium.find_element_by_link_text('Add another Profile').click()
self.selenium.find_element_by_link_text('Add another Profile').click()
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'#profile_set-group table tr.dynamic-profile_set')), 5)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-0')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-1')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-2')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-3')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-4')), 1)
# Click on a few delete buttons
@@ -492,13 +492,13 @@ def test_delete_inlines(self):
self.selenium.find_element_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-2 td.delete a').click()
# Verify that they're gone and that the IDs have been re-sequenced
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'#profile_set-group table tr.dynamic-profile_set')), 3)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-0')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-1')), 1)
- self.failUnlessEqual(len(self.selenium.find_elements_by_css_selector(
+ self.assertEqual(len(self.selenium.find_elements_by_css_selector(
'form#profilecollection_form tr.dynamic-profile_set#profile_set-2')), 1)
@@ -3144,7 +3144,7 @@ def test_readonly_manytomany(self):
def test_user_password_change_limited_queryset(self):
su = User.objects.filter(is_superuser=True)[0]
response = self.client.get('/test_admin/admin2/auth/user/%s/password/' % su.pk)
- self.assertEquals(response.status_code, 404)
+ self.assertEqual(response.status_code, 404)
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
Oops, something went wrong.

0 comments on commit b52672d

Please sign in to comment.