From afd040d4d3a06fe92e3080870b2ff2095ce86a75 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 3 Mar 2011 15:04:39 +0000 Subject: Updated test assertions that have been deprecated by the move to unittest2. 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 --- tests/modeltests/aggregation/tests.py | 2 +- tests/modeltests/model_formsets/tests.py | 2 +- .../model_inheritance_same_model_name/tests.py | 4 +- tests/modeltests/proxy_model_inheritance/tests.py | 4 +- tests/modeltests/raw_query/tests.py | 10 +- tests/modeltests/serializers/tests.py | 2 +- tests/modeltests/test_client/models.py | 6 +- tests/modeltests/unmanaged_models/tests.py | 4 +- tests/modeltests/user_commands/tests.py | 4 +- tests/modeltests/validation/__init__.py | 4 +- tests/modeltests/validators/tests.py | 12 +- tests/regressiontests/admin_filterspecs/tests.py | 60 +-- tests/regressiontests/admin_scripts/tests.py | 4 +- tests/regressiontests/admin_util/tests.py | 34 +- tests/regressiontests/admin_views/tests.py | 62 +-- tests/regressiontests/admin_widgets/tests.py | 6 +- tests/regressiontests/aggregation_regress/tests.py | 18 +- tests/regressiontests/app_loading/tests.py | 2 +- tests/regressiontests/builtin_server/tests.py | 2 +- tests/regressiontests/cache/tests.py | 84 ++-- .../comment_tests/tests/comment_form_tests.py | 6 +- .../tests/comment_utils_moderators_tests.py | 12 +- .../comment_tests/tests/comment_view_tests.py | 6 +- .../comment_tests/tests/feed_tests.py | 4 +- .../comment_tests/tests/moderation_view_tests.py | 6 +- .../comment_tests/tests/templatetag_tests.py | 10 +- .../conditional_processing/models.py | 20 +- tests/regressiontests/csrf_tests/tests.py | 26 +- tests/regressiontests/datatypes/tests.py | 6 +- tests/regressiontests/decorators/tests.py | 6 +- tests/regressiontests/delete_regress/tests.py | 14 +- .../dispatch/tests/test_dispatcher.py | 2 +- .../regressiontests/dispatch/tests/test_saferef.py | 12 +- tests/regressiontests/file_storage/tests.py | 24 +- tests/regressiontests/file_uploads/tests.py | 10 +- tests/regressiontests/forms/localflavor/fi.py | 2 +- tests/regressiontests/forms/localflavor/us.py | 2 +- tests/regressiontests/forms/tests/formsets.py | 8 +- tests/regressiontests/forms/tests/models.py | 8 +- .../regressiontests/generic_inline_admin/tests.py | 22 +- tests/regressiontests/generic_views/base.py | 22 +- tests/regressiontests/httpwrappers/tests.py | 4 +- tests/regressiontests/i18n/commands/extraction.py | 34 +- tests/regressiontests/i18n/tests.py | 2 +- tests/regressiontests/introspection/tests.py | 8 +- tests/regressiontests/mail/tests.py | 2 +- tests/regressiontests/max_lengths/tests.py | 2 +- tests/regressiontests/middleware/tests.py | 74 +-- .../regressiontests/middleware_exceptions/tests.py | 4 +- tests/regressiontests/model_fields/tests.py | 4 +- tests/regressiontests/model_forms_regress/tests.py | 38 +- .../model_inheritance_regress/tests.py | 6 +- tests/regressiontests/modeladmin/tests.py | 2 +- tests/regressiontests/multiple_database/tests.py | 536 ++++++++++----------- tests/regressiontests/null_fk/tests.py | 4 +- tests/regressiontests/null_queries/tests.py | 2 +- tests/regressiontests/one_to_one_regress/tests.py | 4 +- tests/regressiontests/queries/tests.py | 10 +- .../reverse_single_related/tests.py | 4 +- .../select_related_regress/tests.py | 46 +- tests/regressiontests/serializers_regress/tests.py | 2 +- tests/regressiontests/signals_regress/tests.py | 10 +- tests/regressiontests/staticfiles_tests/tests.py | 10 +- tests/regressiontests/string_lookup/tests.py | 18 +- tests/regressiontests/syndication/tests.py | 8 +- tests/regressiontests/templates/custom.py | 16 +- tests/regressiontests/templates/response.py | 14 +- tests/regressiontests/templates/smartif.py | 4 +- tests/regressiontests/templates/tests.py | 4 +- .../regressiontests/test_client_regress/models.py | 40 +- tests/regressiontests/text/tests.py | 44 +- .../regressiontests/transactions_regress/tests.py | 2 +- tests/regressiontests/urlpatterns_reverse/tests.py | 80 +-- tests/regressiontests/utils/datastructures.py | 96 ++-- tests/regressiontests/utils/dateformat.py | 90 ++-- tests/regressiontests/utils/datetime_safe.py | 16 +- tests/regressiontests/utils/simplelazyobject.py | 2 +- tests/regressiontests/utils/termcolors.py | 84 ++-- tests/regressiontests/utils/timesince.py | 62 +-- tests/regressiontests/utils/tzinfo.py | 22 +- tests/regressiontests/views/tests/debug.py | 4 +- tests/regressiontests/views/tests/defaults.py | 14 +- .../views/tests/generic/create_update.py | 4 +- tests/regressiontests/views/tests/i18n.py | 2 +- tests/regressiontests/views/tests/shortcuts.py | 44 +- tests/regressiontests/views/tests/static.py | 20 +- tests/runtests.py | 4 +- 87 files changed, 1028 insertions(+), 1028 deletions(-) (limited to 'tests') diff --git a/tests/modeltests/aggregation/tests.py b/tests/modeltests/aggregation/tests.py index c830368b9d..6f68800ad2 100644 --- a/tests/modeltests/aggregation/tests.py +++ b/tests/modeltests/aggregation/tests.py @@ -41,7 +41,7 @@ class BaseAggregateTestCase(TestCase): vals = Book.objects.aggregate(Sum("publisher__num_awards")) self.assertEqual(len(vals), 1) - self.assertEquals(vals["publisher__num_awards__sum"], 30) + self.assertEqual(vals["publisher__num_awards__sum"], 30) vals = Publisher.objects.aggregate(Sum("book__price")) self.assertEqual(len(vals), 1) diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py index 91c9043e75..5e6d88ebe8 100644 --- a/tests/modeltests/model_formsets/tests.py +++ b/tests/modeltests/model_formsets/tests.py @@ -946,7 +946,7 @@ class ModelFormsetTest(TestCase): # default. This is required to ensure the value is tested for change correctly # when determine what extra forms have changed to save. - self.assertEquals(len(formset.forms), 1) # this formset only has one form + self.assertEqual(len(formset.forms), 1) # this formset only has one form form = formset.forms[0] now = form.fields['date_joined'].initial() result = form.as_p() diff --git a/tests/modeltests/model_inheritance_same_model_name/tests.py b/tests/modeltests/model_inheritance_same_model_name/tests.py index 3f1e3458e6..3d173e62a6 100644 --- a/tests/modeltests/model_inheritance_same_model_name/tests.py +++ b/tests/modeltests/model_inheritance_same_model_name/tests.py @@ -11,7 +11,7 @@ class InheritanceSameModelNameTests(TestCase): def test_inheritance_related_name(self): from modeltests.model_inheritance.models import Copy - self.assertEquals( + self.assertEqual( self.title.attached_model_inheritance_copy_set.create( content='Save $ on V1agr@', url='http://v1agra.com/', @@ -20,7 +20,7 @@ class InheritanceSameModelNameTests(TestCase): def test_inheritance_with_same_model_name(self): from modeltests.model_inheritance_same_model_name.models import Copy - self.assertEquals( + self.assertEqual( self.title.attached_model_inheritance_same_model_name_copy_set.create( content='The Web framework for perfectionists with deadlines.', url='http://www.djangoproject.com/', diff --git a/tests/modeltests/proxy_model_inheritance/tests.py b/tests/modeltests/proxy_model_inheritance/tests.py index b6828515ab..7426f41de5 100644 --- a/tests/modeltests/proxy_model_inheritance/tests.py +++ b/tests/modeltests/proxy_model_inheritance/tests.py @@ -32,5 +32,5 @@ class ProxyModelInheritanceTests(TransactionTestCase): sys.path = self.old_sys_path def test_table_exists(self): - self.assertEquals(NiceModel.objects.all().count(), 0) - self.assertEquals(ProxyModel.objects.all().count(), 0) + self.assertEqual(NiceModel.objects.all().count(), 0) + self.assertEqual(ProxyModel.objects.all().count(), 0) diff --git a/tests/modeltests/raw_query/tests.py b/tests/modeltests/raw_query/tests.py index e7cadfae8c..5334412680 100644 --- a/tests/modeltests/raw_query/tests.py +++ b/tests/modeltests/raw_query/tests.py @@ -30,10 +30,10 @@ class RawQueryTests(TestCase): for field in model._meta.fields: # Check that all values on the model are equal - self.assertEquals(getattr(item,field.attname), + self.assertEqual(getattr(item,field.attname), getattr(orig_item,field.attname)) # This includes checking that they are the same type - self.assertEquals(type(getattr(item,field.attname)), + self.assertEqual(type(getattr(item,field.attname)), type(getattr(orig_item,field.attname))) def assertNoAnnotations(self, results): @@ -67,9 +67,9 @@ class RawQueryTests(TestCase): iterated over. """ q = Author.objects.raw('SELECT * FROM raw_query_author') - self.assert_(q.query.cursor is None) + self.assertTrue(q.query.cursor is None) list(q) - self.assert_(q.query.cursor is not None) + self.assertTrue(q.query.cursor is not None) def testFkeyRawQuery(self): """ @@ -204,7 +204,7 @@ class RawQueryTests(TestCase): self.assertEqual(third_author.first_name, 'Bob') first_two = Author.objects.raw(query)[0:2] - self.assertEquals(len(first_two), 2) + self.assertEqual(len(first_two), 2) self.assertRaises(TypeError, lambda: Author.objects.raw(query)['test']) diff --git a/tests/modeltests/serializers/tests.py b/tests/modeltests/serializers/tests.py index 01b4b68ac2..013438ed29 100644 --- a/tests/modeltests/serializers/tests.py +++ b/tests/modeltests/serializers/tests.py @@ -225,7 +225,7 @@ class SerializersTestBase(object): serial_str = serializers.serialize(self.serializer_name, [a]) date_values = self._get_field_values(serial_str, "pub_date") - self.assertEquals(date_values[0], "0001-02-03 04:05:06") + self.assertEqual(date_values[0], "0001-02-03 04:05:06") def test_pkless_serialized_strings(self): """ diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 0960929004..16bdd2d29a 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -79,7 +79,7 @@ class ClientTest(TestCase): "Check the value of HTTP headers returned in a response" response = self.client.get("/test_client/header_view/") - self.assertEquals(response['X-DJANGO-TEST'], 'Slartibartfast') + self.assertEqual(response['X-DJANGO-TEST'], 'Slartibartfast') def test_raw_post(self): "POST raw data (with a content type) to a view" @@ -140,7 +140,7 @@ class ClientTest(TestCase): "A URL that redirects can be followed to termination." response = self.client.get('/test_client/double_redirect_view/', follow=True) self.assertRedirects(response, 'http://testserver/test_client/get_view/', status_code=302, target_status_code=200) - self.assertEquals(len(response.redirect_chain), 2) + self.assertEqual(len(response.redirect_chain), 2) def test_redirect_http(self): "GET a URL that redirects to an http URI" @@ -400,7 +400,7 @@ class ClientTest(TestCase): response = self.client.post('/test_client/session_view/') # Check that the session was modified - self.assertEquals(self.client.session['tobacconist'], 'hovercraft') + self.assertEqual(self.client.session['tobacconist'], 'hovercraft') def test_view_with_exception(self): "Request a page that is known to throw an error" diff --git a/tests/modeltests/unmanaged_models/tests.py b/tests/modeltests/unmanaged_models/tests.py index dbbe848cce..dee3799234 100644 --- a/tests/modeltests/unmanaged_models/tests.py +++ b/tests/modeltests/unmanaged_models/tests.py @@ -47,7 +47,7 @@ class ManyToManyUnmanagedTests(TestCase): """ table = Unmanaged2._meta.get_field('mm').m2m_db_table() tables = connection.introspection.table_names() - self.assert_(table not in tables, "Table '%s' should not exist, but it does." % table) + self.assertTrue(table not in tables, "Table '%s' should not exist, but it does." % table) def test_many_to_many_between_unmanaged_and_managed(self): """ @@ -55,4 +55,4 @@ class ManyToManyUnmanagedTests(TestCase): """ table = Managed1._meta.get_field('mm').m2m_db_table() tables = connection.introspection.table_names() - self.assert_(table in tables, "Table '%s' does not exist." % table) + self.assertTrue(table in tables, "Table '%s' does not exist." % table) diff --git a/tests/modeltests/user_commands/tests.py b/tests/modeltests/user_commands/tests.py index 84aa7a53d5..aa1398f50f 100644 --- a/tests/modeltests/user_commands/tests.py +++ b/tests/modeltests/user_commands/tests.py @@ -8,13 +8,13 @@ class CommandTests(TestCase): def test_command(self): out = StringIO() management.call_command('dance', stdout=out) - self.assertEquals(out.getvalue(), + self.assertEqual(out.getvalue(), "I don't feel like dancing Rock'n'Roll.") def test_command_style(self): out = StringIO() management.call_command('dance', style='Jive', stdout=out) - self.assertEquals(out.getvalue(), + self.assertEqual(out.getvalue(), "I don't feel like dancing Jive.") def test_explode(self): diff --git a/tests/modeltests/validation/__init__.py b/tests/modeltests/validation/__init__.py index ca18c1bd68..c8a89cd36f 100644 --- a/tests/modeltests/validation/__init__.py +++ b/tests/modeltests/validation/__init__.py @@ -8,7 +8,7 @@ class ValidationTestCase(unittest.TestCase): try: clean() except ValidationError, e: - self.assertEquals(sorted(failed_fields), sorted(e.message_dict.keys())) + self.assertEqual(sorted(failed_fields), sorted(e.message_dict.keys())) def assertFieldFailsValidationWithMessage(self, clean, field_name, message): self.assertRaises(ValidationError, clean) @@ -16,6 +16,6 @@ class ValidationTestCase(unittest.TestCase): clean() except ValidationError, e: self.assertTrue(field_name in e.message_dict) - self.assertEquals(message, e.message_dict[field_name]) + self.assertEqual(message, e.message_dict[field_name]) diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py index 6fe154288d..e58526285b 100644 --- a/tests/modeltests/validators/tests.py +++ b/tests/modeltests/validators/tests.py @@ -141,18 +141,18 @@ def create_simple_test_method(validator, expected, value, num): class TestSimpleValidators(TestCase): def test_single_message(self): v = ValidationError('Not Valid') - self.assertEquals(str(v), "[u'Not Valid']") - self.assertEquals(repr(v), "ValidationError([u'Not Valid'])") + self.assertEqual(str(v), "[u'Not Valid']") + self.assertEqual(repr(v), "ValidationError([u'Not Valid'])") def test_message_list(self): v = ValidationError(['First Problem', 'Second Problem']) - self.assertEquals(str(v), "[u'First Problem', u'Second Problem']") - self.assertEquals(repr(v), "ValidationError([u'First Problem', u'Second Problem'])") + self.assertEqual(str(v), "[u'First Problem', u'Second Problem']") + self.assertEqual(repr(v), "ValidationError([u'First Problem', u'Second Problem'])") def test_message_dict(self): v = ValidationError({'first': 'First Problem'}) - self.assertEquals(str(v), "{'first': 'First Problem'}") - self.assertEquals(repr(v), "ValidationError({'first': 'First Problem'})") + self.assertEqual(str(v), "{'first': 'First Problem'}") + self.assertEqual(repr(v), "ValidationError({'first': 'First Problem'})") test_counter = 0 for validator, value, expected in TEST_DATA: diff --git a/tests/regressiontests/admin_filterspecs/tests.py b/tests/regressiontests/admin_filterspecs/tests.py index 64a6ac700e..b4b3056805 100644 --- a/tests/regressiontests/admin_filterspecs/tests.py +++ b/tests/regressiontests/admin_filterspecs/tests.py @@ -42,20 +42,20 @@ class FilterSpecsTests(TestCase): # Make sure the last choice is None and is selected filterspec = changelist.get_filters(request)[0][0] - self.assertEquals(force_unicode(filterspec.title()), u'year') + self.assertEqual(force_unicode(filterspec.title()), u'year') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[-1]['selected'], True) - self.assertEquals(choices[-1]['query_string'], '?year__isnull=True') + self.assertEqual(choices[-1]['selected'], True) + self.assertEqual(choices[-1]['query_string'], '?year__isnull=True') request = self.request_factory.get('/', {'year': '2002'}) changelist = self.get_changelist(request, Book, modeladmin) # Make sure the correct choice is selected filterspec = changelist.get_filters(request)[0][0] - self.assertEquals(force_unicode(filterspec.title()), u'year') + self.assertEqual(force_unicode(filterspec.title()), u'year') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[2]['selected'], True) - self.assertEquals(choices[2]['query_string'], '?year=2002') + self.assertEqual(choices[2]['selected'], True) + self.assertEqual(choices[2]['query_string'], '?year=2002') def test_RelatedFilterSpec_ForeignKey(self): modeladmin = BookAdmin(Book, admin.site) @@ -70,20 +70,20 @@ class FilterSpecsTests(TestCase): # Make sure the last choice is None and is selected filterspec = changelist.get_filters(request)[0][1] - self.assertEquals(force_unicode(filterspec.title()), u'author') + self.assertEqual(force_unicode(filterspec.title()), u'author') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[-1]['selected'], True) - self.assertEquals(choices[-1]['query_string'], '?author__isnull=True') + self.assertEqual(choices[-1]['selected'], True) + self.assertEqual(choices[-1]['query_string'], '?author__isnull=True') request = self.request_factory.get('/', {'author__id__exact': '1'}) changelist = self.get_changelist(request, Book, modeladmin) # Make sure the correct choice is selected filterspec = changelist.get_filters(request)[0][1] - self.assertEquals(force_unicode(filterspec.title()), u'author') + self.assertEqual(force_unicode(filterspec.title()), u'author') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[1]['selected'], True) - self.assertEquals(choices[1]['query_string'], '?author__id__exact=1') + self.assertEqual(choices[1]['selected'], True) + self.assertEqual(choices[1]['query_string'], '?author__id__exact=1') def test_RelatedFilterSpec_ManyToMany(self): modeladmin = BookAdmin(Book, admin.site) @@ -96,20 +96,20 @@ class FilterSpecsTests(TestCase): # Make sure the last choice is None and is selected filterspec = changelist.get_filters(request)[0][2] - self.assertEquals(force_unicode(filterspec.title()), u'user') + self.assertEqual(force_unicode(filterspec.title()), u'user') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[-1]['selected'], True) - self.assertEquals(choices[-1]['query_string'], '?contributors__isnull=True') + self.assertEqual(choices[-1]['selected'], True) + self.assertEqual(choices[-1]['query_string'], '?contributors__isnull=True') request = self.request_factory.get('/', {'contributors__id__exact': '2'}) changelist = self.get_changelist(request, Book, modeladmin) # Make sure the correct choice is selected filterspec = changelist.get_filters(request)[0][2] - self.assertEquals(force_unicode(filterspec.title()), u'user') + self.assertEqual(force_unicode(filterspec.title()), u'user') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[2]['selected'], True) - self.assertEquals(choices[2]['query_string'], '?contributors__id__exact=2') + self.assertEqual(choices[2]['selected'], True) + self.assertEqual(choices[2]['query_string'], '?contributors__id__exact=2') def test_RelatedFilterSpec_reverse_relationships(self): @@ -124,20 +124,20 @@ class FilterSpecsTests(TestCase): # Make sure the last choice is None and is selected filterspec = changelist.get_filters(request)[0][0] - self.assertEquals(force_unicode(filterspec.title()), u'book') + self.assertEqual(force_unicode(filterspec.title()), u'book') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[-1]['selected'], True) - self.assertEquals(choices[-1]['query_string'], '?books_authored__isnull=True') + self.assertEqual(choices[-1]['selected'], True) + self.assertEqual(choices[-1]['query_string'], '?books_authored__isnull=True') request = self.request_factory.get('/', {'books_authored__id__exact': '1'}) changelist = self.get_changelist(request, User, modeladmin) # Make sure the correct choice is selected filterspec = changelist.get_filters(request)[0][0] - self.assertEquals(force_unicode(filterspec.title()), u'book') + self.assertEqual(force_unicode(filterspec.title()), u'book') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[1]['selected'], True) - self.assertEquals(choices[1]['query_string'], '?books_authored__id__exact=1') + self.assertEqual(choices[1]['selected'], True) + self.assertEqual(choices[1]['query_string'], '?books_authored__id__exact=1') # M2M relationship ----- request = self.request_factory.get('/', {'books_contributed__isnull': 'True'}) @@ -148,20 +148,20 @@ class FilterSpecsTests(TestCase): # Make sure the last choice is None and is selected filterspec = changelist.get_filters(request)[0][1] - self.assertEquals(force_unicode(filterspec.title()), u'book') + self.assertEqual(force_unicode(filterspec.title()), u'book') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[-1]['selected'], True) - self.assertEquals(choices[-1]['query_string'], '?books_contributed__isnull=True') + self.assertEqual(choices[-1]['selected'], True) + self.assertEqual(choices[-1]['query_string'], '?books_contributed__isnull=True') request = self.request_factory.get('/', {'books_contributed__id__exact': '2'}) changelist = self.get_changelist(request, User, modeladmin) # Make sure the correct choice is selected filterspec = changelist.get_filters(request)[0][1] - self.assertEquals(force_unicode(filterspec.title()), u'book') + self.assertEqual(force_unicode(filterspec.title()), u'book') choices = list(filterspec.choices(changelist)) - self.assertEquals(choices[2]['selected'], True) - self.assertEquals(choices[2]['query_string'], '?books_contributed__id__exact=2') + self.assertEqual(choices[2]['selected'], True) + self.assertEqual(choices[2]['query_string'], '?books_contributed__id__exact=2') class CustomUserAdmin(UserAdmin): list_filter = ('books_authored', 'books_contributed') diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 76cecc0842..ed4bd356ba 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -155,7 +155,7 @@ class AdminScriptTestCase(unittest.TestCase): def assertNoOutput(self, stream): "Utility assertion: assert that the given stream is empty" - self.assertEquals(len(stream), 0, "Stream should be empty: actually contains '%s'" % stream) + self.assertEqual(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.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream)) @@ -545,7 +545,7 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase): args = ['startapp','settings_test'] out, err = self.run_django_admin(args,'settings') self.assertNoOutput(err) - self.assert_(os.path.exists(os.path.join(test_dir, 'settings_test'))) + self.assertTrue(os.path.exists(os.path.join(test_dir, 'settings_test'))) shutil.rmtree(os.path.join(test_dir, 'settings_test')) def test_builtin_command(self): diff --git a/tests/regressiontests/admin_util/tests.py b/tests/regressiontests/admin_util/tests.py index 24dde41c25..f4b3dd935d 100644 --- a/tests/regressiontests/admin_util/tests.py +++ b/tests/regressiontests/admin_util/tests.py @@ -24,7 +24,7 @@ class NestedObjectsTests(TestCase): self.objs = [Count.objects.create(num=i) for i in range(5)] def _check(self, target): - self.assertEquals(self.n.nested(lambda obj: obj.num), target) + self.assertEqual(self.n.nested(lambda obj: obj.num), target) def _connect(self, i, j): self.objs[i].parent = self.objs[j] @@ -146,24 +146,24 @@ class UtilTests(unittest.TestCase): """ Tests for label_for_field """ - self.assertEquals( + self.assertEqual( label_for_field("title", Article), "title" ) - self.assertEquals( + self.assertEqual( label_for_field("title2", Article), "another name" ) - self.assertEquals( + self.assertEqual( label_for_field("title2", Article, return_attr=True), ("another name", None) ) - self.assertEquals( + self.assertEqual( label_for_field("__unicode__", Article), "article" ) - self.assertEquals( + self.assertEqual( label_for_field("__str__", Article), "article" ) @@ -175,29 +175,29 @@ class UtilTests(unittest.TestCase): def test_callable(obj): return "nothing" - self.assertEquals( + self.assertEqual( label_for_field(test_callable, Article), "Test callable" ) - self.assertEquals( + self.assertEqual( label_for_field(test_callable, Article, return_attr=True), ("Test callable", test_callable) ) - self.assertEquals( + self.assertEqual( label_for_field("test_from_model", Article), "Test from model" ) - self.assertEquals( + self.assertEqual( label_for_field("test_from_model", Article, return_attr=True), ("Test from model", Article.test_from_model) ) - self.assertEquals( + self.assertEqual( label_for_field("test_from_model_with_override", Article), "not What you Expect" ) - self.assertEquals( + self.assertEqual( label_for_field(lambda x: "nothing", Article), "--" ) @@ -207,11 +207,11 @@ class UtilTests(unittest.TestCase): return "nothing" test_from_model.short_description = "not Really the Model" - self.assertEquals( + self.assertEqual( label_for_field("test_from_model", Article, model_admin=MockModelAdmin), "not Really the Model" ) - self.assertEquals( + self.assertEqual( label_for_field("test_from_model", Article, model_admin = MockModelAdmin, return_attr = True @@ -223,15 +223,15 @@ class UtilTests(unittest.TestCase): """ Regression test for #13963 """ - self.assertEquals( + self.assertEqual( label_for_field('location', Event, return_attr=True), ('location', None), ) - self.assertEquals( + self.assertEqual( label_for_field('event', Location, return_attr=True), ('awesome event', None), ) - self.assertEquals( + self.assertEqual( label_for_field('guest', Event, return_attr=True), ('awesome guest', None), ) diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index eca8adedc9..127dd685b2 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -478,7 +478,7 @@ class SaveAsTests(TestCase): initial model. """ response = self.client.get('/test_admin/admin/admin_views/person/1/') - self.assert_(response.context['save_as']) + self.assertTrue(response.context['save_as']) post_data = {'_saveasnew':'', 'name':'John M', 'gender':3, 'alive':'checked'} response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data) self.assertEqual(response.context['form_url'], '../add/') @@ -503,32 +503,32 @@ class CustomModelAdminTest(AdminViewBasicTest): self.client.logout() request = self.client.get('/test_admin/admin2/') self.assertTemplateUsed(request, 'custom_admin/login.html') - self.assert_('Hello from a custom login template' in request.content) + self.assertTrue('Hello from a custom login template' in request.content) def testCustomAdminSiteLogoutTemplate(self): request = self.client.get('/test_admin/admin2/logout/') self.assertTemplateUsed(request, 'custom_admin/logout.html') - self.assert_('Hello from a custom logout template' in request.content) + self.assertTrue('Hello from a custom logout template' in request.content) def testCustomAdminSiteIndexViewAndTemplate(self): request = self.client.get('/test_admin/admin2/') self.assertTemplateUsed(request, 'custom_admin/index.html') - self.assert_('Hello from a custom index template *bar*' in request.content) + self.assertTrue('Hello from a custom index template *bar*' in request.content) def testCustomAdminSitePasswordChangeTemplate(self): request = self.client.get('/test_admin/admin2/password_change/') self.assertTemplateUsed(request, 'custom_admin/password_change_form.html') - self.assert_('Hello from a custom password change form template' in request.content) + self.assertTrue('Hello from a custom password change form template' in request.content) def testCustomAdminSitePasswordChangeDoneTemplate(self): request = self.client.get('/test_admin/admin2/password_change/done/') self.assertTemplateUsed(request, 'custom_admin/password_change_done.html') - self.assert_('Hello from a custom password change done template' in request.content) + self.assertTrue('Hello from a custom password change done template' in request.content) def testCustomAdminSiteView(self): self.client.login(username='super', password='secret') response = self.client.get('/test_admin/%s/my_view/' % self.urlbit) - self.assert_(response.content == "Django is a magical pony!", response.content) + self.assertTrue(response.content == "Django is a magical pony!", response.content) def get_perm(Model, perm): """Return the permission object, for the Model""" @@ -725,8 +725,8 @@ class AdminViewPermissionsTest(TestCase): post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict) self.assertRedirects(post, '/test_admin/admin/') self.assertEqual(Article.objects.all().count(), 4) - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].subject, 'Greetings from a created object') + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, 'Greetings from a created object') self.client.get('/test_admin/admin/logout/') # Super can add too, but is redirected to the change list view @@ -801,12 +801,12 @@ class AdminViewPermissionsTest(TestCase): request = self.client.get('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/') self.assertEqual(request.status_code, 403) request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/', {'name': 'changed'}) - self.assertEquals(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') self.assertEqual(request.status_code, 403) request = self.client.get('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/') self.assertEqual(request.status_code, 200) request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/', {'name': 'changed'}) - self.assertEquals(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') self.assertRedirects(request, '/test_admin/admin/') self.client.get('/test_admin/admin/logout/') for login_dict in [self.joepublic_login, self.no_username_login]: @@ -815,14 +815,14 @@ class AdminViewPermissionsTest(TestCase): self.assertEqual(request.status_code, 200) self.assertContains(request, 'login-form') request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/', {'name': 'changed'}) - self.assertEquals(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') self.assertEqual(request.status_code, 200) self.assertContains(request, 'login-form') request = self.client.get('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/') self.assertEqual(request.status_code, 200) self.assertContains(request, 'login-form') request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/', {'name': 'changed again'}) - self.assertEquals(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') self.assertEqual(request.status_code, 200) self.assertContains(request, 'login-form') self.client.get('/test_admin/admin/logout/') @@ -856,7 +856,7 @@ class AdminViewPermissionsTest(TestCase): # Test custom change list template with custom extra context request = self.client.get('/test_admin/admin/admin_views/customarticle/') self.assertEqual(request.status_code, 200) - self.assert_("var hello = 'Hello!';" in request.content) + self.assertTrue("var hello = 'Hello!';" in request.content) self.assertTemplateUsed(request, 'custom_admin/change_list.html') # Test custom add form template @@ -916,8 +916,8 @@ class AdminViewPermissionsTest(TestCase): post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict) self.assertRedirects(post, '/test_admin/admin/') self.assertEqual(Article.objects.all().count(), 2) - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].subject, 'Greetings from a deleted object') + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, 'Greetings from a deleted object') article_ct = ContentType.objects.get_for_model(Article) logged = LogEntry.objects.get(content_type=article_ct, action_flag=DELETION) self.assertEqual(logged.object_id, u'1') @@ -1108,7 +1108,7 @@ class AdminViewStringPrimaryKeyTest(TestCase): counted_presence_before = response.content.count(should_contain) response = self.client.get('/test_admin/admin/') counted_presence_after = response.content.count(should_contain) - self.assertEquals(counted_presence_before - 1, + self.assertEqual(counted_presence_before - 1, counted_presence_after) def test_deleteconfirmation_link(self): @@ -1568,7 +1568,7 @@ class AdminViewListEditable(TestCase): } response = self.client.post('/test_admin/admin/admin_views/person/', data) non_form_errors = response.context['cl'].formset.non_form_errors() - self.assert_(isinstance(non_form_errors, ErrorList)) + self.assertTrue(isinstance(non_form_errors, ErrorList)) self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"]))) def test_list_editable_ordering(self): @@ -1853,8 +1853,8 @@ class AdminActionsTest(TestCase): 'index': 0, } response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].subject, 'Greetings from a ModelAdmin action') + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, 'Greetings from a ModelAdmin action') def test_model_admin_default_delete_action(self): "Tests the default delete action defined as a ModelAdmin method" @@ -1927,8 +1927,8 @@ class AdminActionsTest(TestCase): 'index': 0, } response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data) - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action') + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, 'Greetings from a function action') def test_custom_function_action_with_redirect(self): "Tests a custom action defined in a function" @@ -1958,19 +1958,19 @@ class AdminActionsTest(TestCase): def test_model_without_action(self): "Tests a ModelAdmin without any action" response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/') - self.assertEquals(response.context["action_form"], None) - self.assert_( + self.assertEqual(response.context["action_form"], None) + self.assertTrue( '') self.assertContains(response, 'example.com comments') self.assertContains(response, 'http://example.com/') diff --git a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py index e5094ab0cc..c9be06a340 100644 --- a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py +++ b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py @@ -182,14 +182,14 @@ class AdminActionsTests(CommentTestCase): comments = self.createSomeComments() self.client.login(username="normaluser", password="normaluser") response = self.client.get("/admin/comments/comment/") - self.assertEquals("approve_comments" in response.content, False) + self.assertEqual("approve_comments" in response.content, False) def testActionsModerator(self): comments = self.createSomeComments() makeModerator("normaluser") self.client.login(username="normaluser", password="normaluser") response = self.client.get("/admin/comments/comment/") - self.assertEquals("approve_comments" in response.content, True) + self.assertEqual("approve_comments" in response.content, True) def testActionsDisabledDelete(self): "Tests a CommentAdmin where 'delete_selected' has been disabled." @@ -197,7 +197,7 @@ class AdminActionsTests(CommentTestCase): self.client.login(username="normaluser", password="normaluser") response = self.client.get('/admin2/comments/comment/') self.assertEqual(response.status_code, 200) - self.assert_( + self.assertTrue( '