summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-07-02 10:49:53 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-07-02 10:49:53 +0100
commitb1e0ec06f0d538eb2ab16a7c1ecefd1d896e6382 (patch)
treeb837c6144106f304a7aacdfd4fae47ea95f4158a /tests
parent7a47ba6f6aeca36b8b092dbafd36abb342d34d4b (diff)
parent6c66a41c3dc697dc3bda4e31e8b05084d2ede915 (diff)
Merge branch 'master' into schema-alteration
Diffstat (limited to 'tests')
-rw-r--r--tests/.coveragerc2
-rw-r--r--tests/admin_scripts/app_with_import/models.py6
-rw-r--r--tests/admin_scripts/tests.py5
-rw-r--r--tests/admin_views/tests.py19
-rw-r--r--tests/admin_widgets/tests.py2
-rw-r--r--tests/aggregation_regress/tests.py1
-rw-r--r--tests/app_loading/tests.py3
-rw-r--r--tests/backends/tests.py18
-rw-r--r--tests/bash_completion/tests.py2
-rw-r--r--tests/bug639/tests.py2
-rw-r--r--tests/bug8245/tests.py3
-rw-r--r--tests/builtin_server/tests.py2
-rw-r--r--tests/cache/tests.py11
-rw-r--r--tests/db_typecasts/tests.py2
-rw-r--r--tests/decorators/tests.py2
-rw-r--r--tests/defaultfilters/tests.py3
-rw-r--r--tests/deprecation/tests.py2
-rw-r--r--tests/dispatch/tests/test_dispatcher.py2
-rw-r--r--tests/dispatch/tests/test_saferef.py3
-rw-r--r--tests/file_storage/tests.py10
-rw-r--r--tests/file_uploads/tests.py2
-rw-r--r--tests/files/tests.py2
-rw-r--r--tests/fixtures/tests.py56
-rw-r--r--tests/fixtures_model_package/tests.py7
-rw-r--r--tests/fixtures_regress/tests.py32
-rw-r--r--tests/forms_tests/tests/test_validators.py3
-rw-r--r--tests/generic_views/test_base.py2
-rw-r--r--tests/generic_views/test_dates.py2
-rw-r--r--tests/generic_views/test_edit.py8
-rw-r--r--tests/httpwrappers/tests.py27
-rw-r--r--tests/indexes/tests.py3
-rw-r--r--tests/inspectdb/tests.py2
-rw-r--r--tests/introspection/tests.py3
-rw-r--r--tests/invalid_models/tests.py3
-rw-r--r--tests/logging_tests/tests.py2
-rw-r--r--tests/max_lengths/tests.py4
-rw-r--r--tests/middleware/tests.py12
-rw-r--r--tests/model_fields/test_imagefield.py2
-rw-r--r--tests/model_fields/tests.py13
-rw-r--r--tests/model_forms/tests.py8
-rw-r--r--tests/model_forms_regress/tests.py6
-rw-r--r--tests/model_formsets/tests.py2
-rw-r--r--tests/model_inheritance_regress/tests.py4
-rw-r--r--tests/model_regress/tests.py2
-rw-r--r--tests/modeladmin/tests.py3
-rw-r--r--tests/multiple_database/tests.py21
-rw-r--r--tests/pagination/tests.py2
-rw-r--r--tests/proxy_models/tests.py2
-rw-r--r--tests/queries/tests.py2
-rw-r--r--tests/requests/tests.py6
-rw-r--r--tests/resolve_url/tests.py3
-rwxr-xr-xtests/runtests.py2
-rw-r--r--tests/select_for_update/tests.py2
-rw-r--r--tests/select_related/tests.py58
-rw-r--r--tests/select_related_onetoone/tests.py3
-rw-r--r--tests/serializers/tests.py2
-rw-r--r--tests/serializers_regress/tests.py4
-rw-r--r--tests/settings_tests/tests.py3
-rw-r--r--tests/str/tests.py2
-rw-r--r--tests/template_tests/loaders.py7
-rw-r--r--tests/template_tests/test_callables.py3
-rw-r--r--tests/template_tests/test_context.py4
-rw-r--r--tests/template_tests/test_custom.py3
-rw-r--r--tests/template_tests/test_nodelist.py3
-rw-r--r--tests/template_tests/test_parser.py3
-rw-r--r--tests/template_tests/test_smartif.py3
-rw-r--r--tests/template_tests/test_unicode.py3
-rw-r--r--tests/template_tests/tests.py4
-rw-r--r--tests/test_discovery_sample/tests_sample.py11
-rw-r--r--tests/test_runner/test_discover_runner.py35
-rw-r--r--tests/test_runner/tests.py9
-rw-r--r--tests/test_suite_override/tests.py8
-rw-r--r--tests/test_utils/tests.py41
-rw-r--r--tests/timezones/tests.py2
-rw-r--r--tests/transactions/tests.py10
-rw-r--r--tests/transactions_regress/tests.py15
-rw-r--r--tests/urlpatterns_reverse/tests.py4
-rw-r--r--tests/utils_tests/test_archive.py2
-rw-r--r--tests/utils_tests/test_baseconv.py3
-rw-r--r--tests/utils_tests/test_crypto.py4
-rw-r--r--tests/utils_tests/test_datastructures.py15
-rw-r--r--tests/utils_tests/test_dateformat.py4
-rw-r--r--tests/utils_tests/test_dateparse.py2
-rw-r--r--tests/utils_tests/test_encoding.py3
-rw-r--r--tests/utils_tests/test_feedgenerator.py5
-rw-r--r--tests/utils_tests/test_functional.py3
-rw-r--r--tests/utils_tests/test_html.py2
-rw-r--r--tests/utils_tests/test_http.py2
-rw-r--r--tests/utils_tests/test_ipv6.py3
-rw-r--r--tests/utils_tests/test_module_loading.py4
-rw-r--r--tests/utils_tests/test_os_utils.py2
-rw-r--r--tests/utils_tests/test_regex_helper.py3
-rw-r--r--tests/utils_tests/test_simplelazyobject.py2
-rw-r--r--tests/utils_tests/test_termcolors.py3
-rw-r--r--tests/utils_tests/test_timezone.py3
-rw-r--r--tests/utils_tests/test_tzinfo.py3
-rw-r--r--tests/validation/test_error_messages.py3
-rw-r--r--tests/validation/test_unique.py2
-rw-r--r--tests/validators/tests.py4
-rw-r--r--tests/version/tests.py2
-rw-r--r--tests/view_tests/tests/test_debug.py2
-rw-r--r--tests/view_tests/tests/test_i18n.py3
-rw-r--r--tests/wsgi/tests.py4
103 files changed, 287 insertions, 391 deletions
diff --git a/tests/.coveragerc b/tests/.coveragerc
index cd7fee3c89..1b4c087f14 100644
--- a/tests/.coveragerc
+++ b/tests/.coveragerc
@@ -1,5 +1,5 @@
[run]
-omit = */django/contrib/*/tests*,*/django/utils/unittest*,*/django/utils/simplejson*,*/django/utils/importlib.py,*/django/test/_doctest.py,*/django/core/servers/fastcgi.py,*/django/utils/autoreload.py,*/django/utils/dictconfig.py
+omit = */django/contrib/*/tests*,*/django/utils/unittest*,*/django/utils/importlib.py,*/django/test/_doctest.py,*/django/core/servers/fastcgi.py,*/django/utils/autoreload.py,*/django/utils/dictconfig.py
[html]
directory = coverage_html
diff --git a/tests/admin_scripts/app_with_import/models.py b/tests/admin_scripts/app_with_import/models.py
index 17a892bd17..89125c386f 100644
--- a/tests/admin_scripts/app_with_import/models.py
+++ b/tests/admin_scripts/app_with_import/models.py
@@ -1,8 +1,8 @@
from django.db import models
-from django.contrib.comments.models import Comment
+from django.contrib.auth.models import User
# Regression for #13368. This is an example of a model
# that imports a class that has an abstract base class.
-class CommentScore(models.Model):
- comment = models.OneToOneField(Comment, primary_key=True)
+class UserProfile(models.Model):
+ user = models.OneToOneField(User, primary_key=True)
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 2f399acb23..28f2dcb841 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -6,13 +6,14 @@ and default settings.py files.
"""
from __future__ import unicode_literals
+import codecs
import os
import re
import shutil
import socket
import subprocess
import sys
-import codecs
+import unittest
import django
from django import conf, get_version
@@ -20,7 +21,6 @@ from django.conf import settings
from django.core.management import BaseCommand, CommandError
from django.db import connection
from django.test.runner import DiscoverRunner
-from django.utils import unittest
from django.utils.encoding import force_text
from django.utils._os import upath
from django.utils.six import StringIO
@@ -1079,7 +1079,6 @@ class ManageValidate(AdminScriptTestCase):
"manage.py validate does not raise errors when an app imports a base class that itself has an abstract base"
self.write_settings('settings.py',
apps=['admin_scripts.app_with_import',
- 'django.contrib.comments',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sites'],
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 235fe0cb54..101fcd90f6 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -4,6 +4,7 @@ from __future__ import absolute_import, unicode_literals
import os
import re
import datetime
+import unittest
try:
from urllib.parse import urljoin
except ImportError: # Python 2
@@ -15,6 +16,7 @@ from django.core.files import temp as tempfile
from django.core.urlresolvers import reverse
# Register auth models with the admin.
from django.contrib import admin
+from django.contrib.auth import get_permission_codename
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import LogEntry, DELETION
from django.contrib.admin.sites import LOGIN_FORM_KEY
@@ -30,7 +32,8 @@ from django.forms.util import ErrorList
from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.utils import patch_logger
-from django.utils import formats, translation, unittest
+from django.utils import formats
+from django.utils import translation
from django.utils.cache import get_max_age
from django.utils.encoding import iri_to_uri, force_bytes
from django.utils.html import escape
@@ -854,20 +857,20 @@ class AdminViewPermissionsTest(TestCase):
# User who can add Articles
add_user = User.objects.get(username='adduser')
add_user.user_permissions.add(get_perm(Article,
- opts.get_add_permission()))
+ get_permission_codename('add', opts)))
# User who can change Articles
change_user = User.objects.get(username='changeuser')
change_user.user_permissions.add(get_perm(Article,
- opts.get_change_permission()))
+ get_permission_codename('change', opts)))
# User who can delete Articles
delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Article,
- opts.get_delete_permission()))
+ get_permission_codename('delete', opts)))
delete_user.user_permissions.add(get_perm(Section,
- Section._meta.get_delete_permission()))
+ get_permission_codename('delete', Section._meta)))
# login POST dicts
self.super_login = {
@@ -1210,7 +1213,7 @@ class AdminViewPermissionsTest(TestCase):
# Allow the add user to add sections too. Now they can see the "add
# section" link.
add_user = User.objects.get(username='adduser')
- perm = get_perm(Section, Section._meta.get_add_permission())
+ perm = get_perm(Section, get_permission_codename('add', Section._meta))
add_user.user_permissions.add(perm)
response = self.client.get(url)
self.assertContains(response, add_link_text)
@@ -1315,7 +1318,7 @@ class AdminViewsNoUrlTest(TestCase):
# User who can change Reports
change_user = User.objects.get(username='changeuser')
change_user.user_permissions.add(get_perm(Report,
- opts.get_change_permission()))
+ get_permission_codename('change', opts)))
# login POST dict
self.changeuser_login = {
@@ -1372,7 +1375,7 @@ class AdminViewDeletedObjectsTest(TestCase):
self.client.logout()
delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Plot,
- Plot._meta.get_delete_permission()))
+ get_permission_codename('delete', Plot._meta)))
self.assertTrue(self.client.login(username='deleteuser',
password='secret'))
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index 4823883f42..8edb2f5904 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -2,6 +2,7 @@
from __future__ import absolute_import, unicode_literals
from datetime import datetime
+from unittest import TestCase
from django import forms
from django.conf import settings
@@ -16,7 +17,6 @@ from django.test.utils import override_settings
from django.utils import six
from django.utils import translation
from django.utils.html import conditional_escape
-from django.utils.unittest import TestCase
from . import models
from .widgetadmin import site as widget_admin_site
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index 80441b9a60..35ac57d9be 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -10,7 +10,6 @@ from django.contrib.contenttypes.models import ContentType
from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q
from django.test import TestCase, Approximate, skipUnlessDBFeature
from django.utils import six
-from django.utils.unittest import expectedFailure
from .models import (Author, Book, Publisher, Clues, Entries, HardbackBook,
ItemTag, WithManualPK)
diff --git a/tests/app_loading/tests.py b/tests/app_loading/tests.py
index 6dd0be2194..e0c7cbd78c 100644
--- a/tests/app_loading/tests.py
+++ b/tests/app_loading/tests.py
@@ -4,11 +4,12 @@ import copy
import os
import sys
import time
+from unittest import TestCase
from django.conf import Settings
from django.db.models.loading import cache, load_app, get_model, get_models
from django.utils._os import upath
-from django.utils.unittest import TestCase
+
class EggLoadingTest(TestCase):
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index c1a26df7fc..b1bfa4cb21 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -5,6 +5,7 @@ from __future__ import absolute_import, unicode_literals
import datetime
from decimal import Decimal
import threading
+import unittest
from django.conf import settings
from django.core.management.color import no_style
@@ -21,7 +22,7 @@ from django.db.utils import ConnectionHandler
from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
TransactionTestCase)
from django.test.utils import override_settings, str_prefix
-from django.utils import six, unittest
+from django.utils import six
from django.utils.six.moves import xrange
from . import models
@@ -164,6 +165,17 @@ class DateQuotingTest(TestCase):
@override_settings(DEBUG=True)
class LastExecutedQueryTest(TestCase):
+ def test_last_executed_query(self):
+ """
+ last_executed_query should not raise an exception even if no previous
+ query has been run.
+ """
+ cursor = connection.cursor()
+ try:
+ connection.ops.last_executed_query(cursor, '', ())
+ except Exception:
+ self.fail("'last_executed_query' should not raise an exception.")
+
def test_debug_sql(self):
list(models.Reporter.objects.filter(first_name="test"))
sql = connection.queries[-1]['sql'].lower()
@@ -458,7 +470,7 @@ class BackendTestCase(TestCase):
def create_squares_with_executemany(self, args):
self.create_squares(args, 'format', True)
- def create_squares(self, args, paramstyle, multiple):
+ def create_squares(self, args, paramstyle, multiple):
cursor = connection.cursor()
opts = models.Square._meta
tbl = connection.introspection.table_name_converter(opts.db_table)
@@ -530,7 +542,7 @@ class BackendTestCase(TestCase):
# same test for DebugCursorWrapper
self.create_squares(args, 'pyformat', multiple=True)
self.assertEqual(models.Square.objects.count(), 9)
-
+
def test_unicode_fetches(self):
#6254: fetchone, fetchmany, fetchall return strings as unicode objects
qn = connection.ops.quote_name
diff --git a/tests/bash_completion/tests.py b/tests/bash_completion/tests.py
index 4fdb793feb..2da68b588a 100644
--- a/tests/bash_completion/tests.py
+++ b/tests/bash_completion/tests.py
@@ -3,10 +3,10 @@ A series of tests to establish that the command-line bash completion works.
"""
import os
import sys
+import unittest
from django.conf import settings
from django.core.management import ManagementUtility
-from django.utils import unittest
from django.utils.six import StringIO
diff --git a/tests/bug639/tests.py b/tests/bug639/tests.py
index fcc1e0f7d1..71c50e14aa 100644
--- a/tests/bug639/tests.py
+++ b/tests/bug639/tests.py
@@ -8,9 +8,9 @@ from __future__ import absolute_import
import os
import shutil
+import unittest
from django.core.files.uploadedfile import SimpleUploadedFile
-from django.utils import unittest
from django.utils._os import upath
from .models import Photo, PhotoForm, temp_storage_dir
diff --git a/tests/bug8245/tests.py b/tests/bug8245/tests.py
index 5da0b1f718..7a91d04af1 100644
--- a/tests/bug8245/tests.py
+++ b/tests/bug8245/tests.py
@@ -1,5 +1,6 @@
+from unittest import TestCase
+
from django.contrib import admin
-from django.utils.unittest import TestCase
class Bug8245Test(TestCase):
diff --git a/tests/builtin_server/tests.py b/tests/builtin_server/tests.py
index 662466a110..ef215ccf97 100644
--- a/tests/builtin_server/tests.py
+++ b/tests/builtin_server/tests.py
@@ -1,9 +1,9 @@
from __future__ import unicode_literals
from io import BytesIO
+from unittest import TestCase
from django.core.servers.basehttp import ServerHandler, MAX_SOCKET_CHUNK_SIZE
-from django.utils.unittest import TestCase
class DummyHandler(object):
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 7413a4aae6..bccac6b5a8 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -6,13 +6,14 @@ from __future__ import absolute_import, unicode_literals
import hashlib
import os
+import pickle
import random
import re
import string
import tempfile
import time
+import unittest
import warnings
-import pickle
from django.conf import settings
from django.core import management
@@ -28,8 +29,10 @@ from django.middleware.cache import (FetchFromCacheMiddleware,
from django.template import Template
from django.template.response import TemplateResponse
from django.test import TestCase, TransactionTestCase, RequestFactory
-from django.test.utils import override_settings, IgnorePendingDeprecationWarningsMixin
-from django.utils import six, timezone, translation, unittest
+from django.test.utils import override_settings, IgnoreDeprecationWarningsMixin
+from django.utils import six
+from django.utils import timezone
+from django.utils import translation
from django.utils.cache import (patch_vary_headers, get_cache_key,
learn_cache_key, patch_cache_control, patch_response_headers)
from django.utils.encoding import force_text
@@ -1594,7 +1597,7 @@ def hello_world_view(request, value):
},
},
)
-class CacheMiddlewareTest(IgnorePendingDeprecationWarningsMixin, TestCase):
+class CacheMiddlewareTest(IgnoreDeprecationWarningsMixin, TestCase):
def setUp(self):
super(CacheMiddlewareTest, self).setUp()
diff --git a/tests/db_typecasts/tests.py b/tests/db_typecasts/tests.py
index 2cf835d94e..fc5305dcdd 100644
--- a/tests/db_typecasts/tests.py
+++ b/tests/db_typecasts/tests.py
@@ -1,10 +1,10 @@
# Unit tests for typecast functions in django.db.backends.util
import datetime
+import unittest
from django.db.backends import util as typecasts
from django.utils import six
-from django.utils import unittest
TEST_CASES = {
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py
index 05016be231..2aaea49500 100644
--- a/tests/decorators/tests.py
+++ b/tests/decorators/tests.py
@@ -1,4 +1,5 @@
from functools import wraps
+from unittest import TestCase
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required, permission_required, user_passes_test
@@ -6,7 +7,6 @@ from django.http import HttpResponse, HttpRequest, HttpResponseNotAllowed
from django.middleware.clickjacking import XFrameOptionsMiddleware
from django.utils.decorators import method_decorator
from django.utils.functional import allow_lazy, lazy, memoize
-from django.utils.unittest import TestCase
from django.views.decorators.cache import cache_page, never_cache, cache_control
from django.views.decorators.clickjacking import xframe_options_deny, xframe_options_sameorigin, xframe_options_exempt
from django.views.decorators.http import require_http_methods, require_GET, require_POST, require_safe, condition
diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py
index d0009c6e66..15b96be881 100644
--- a/tests/defaultfilters/tests.py
+++ b/tests/defaultfilters/tests.py
@@ -3,11 +3,12 @@ from __future__ import unicode_literals
import datetime
import decimal
+import unittest
from django.template.defaultfilters import *
from django.test import TestCase
from django.utils import six
-from django.utils import unittest, translation
+from django.utils import translation
from django.utils.safestring import SafeData
from django.utils.encoding import python_2_unicode_compatible
diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py
index df752b3149..fda780c7e6 100644
--- a/tests/deprecation/tests.py
+++ b/tests/deprecation/tests.py
@@ -8,7 +8,7 @@ from django.utils.deprecation import RenameMethodsBase
class RenameManagerMethods(RenameMethodsBase):
renamed_methods = (
- ('old', 'new', PendingDeprecationWarning),
+ ('old', 'new', DeprecationWarning),
)
diff --git a/tests/dispatch/tests/test_dispatcher.py b/tests/dispatch/tests/test_dispatcher.py
index a1d4c7e176..5f7dca87cc 100644
--- a/tests/dispatch/tests/test_dispatcher.py
+++ b/tests/dispatch/tests/test_dispatcher.py
@@ -1,9 +1,9 @@
import gc
import sys
import time
+import unittest
from django.dispatch import Signal, receiver
-from django.utils import unittest
if sys.platform.startswith('java'):
diff --git a/tests/dispatch/tests/test_saferef.py b/tests/dispatch/tests/test_saferef.py
index 30eaddfe18..a9a246304e 100644
--- a/tests/dispatch/tests/test_saferef.py
+++ b/tests/dispatch/tests/test_saferef.py
@@ -1,6 +1,7 @@
+import unittest
+
from django.dispatch.saferef import safeRef
from django.utils.six.moves import xrange
-from django.utils import unittest
class Test1(object):
def x(self):
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 6c3c559660..8cf4c33091 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -7,6 +7,7 @@ import shutil
import sys
import tempfile
import time
+import unittest
try:
from urllib.request import urlopen
except ImportError: # Python 2
@@ -28,7 +29,6 @@ from django.core.files.storage import FileSystemStorage, get_storage_class
from django.core.files.uploadedfile import UploadedFile
from django.test import LiveServerTestCase, SimpleTestCase
from django.utils import six
-from django.utils import unittest
from django.utils._os import upath
from django.test.utils import override_settings
@@ -364,6 +364,14 @@ class FileStorageTests(unittest.TestCase):
with self.assertRaises(IOError):
self.storage.save('error.file', f1)
+ def test_delete_no_name(self):
+ """
+ Calling delete with an empty name should not try to remove the base
+ storage directory, but fail loudly (#20660).
+ """
+ with self.assertRaises(AssertionError):
+ self.storage.delete('')
+
class CustomStorage(FileSystemStorage):
def get_available_name(self, name):
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py
index 45e7342abd..66bc4465a2 100644
--- a/tests/file_uploads/tests.py
+++ b/tests/file_uploads/tests.py
@@ -8,6 +8,7 @@ import json
import os
import shutil
import tempfile as sys_tempfile
+import unittest
from django.core.files import temp as tempfile
from django.core.files.uploadedfile import SimpleUploadedFile
@@ -16,7 +17,6 @@ from django.test import TestCase, client
from django.test.utils import override_settings
from django.utils.encoding import force_bytes
from django.utils.six import StringIO
-from django.utils import unittest
from . import uploadhandler
from .models import FileModel
diff --git a/tests/files/tests.py b/tests/files/tests.py
index f1e3d5b14b..54eeee13e4 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -4,6 +4,7 @@ import os
import gzip
import shutil
import tempfile
+import unittest
from django.core.cache import cache
from django.core.files import File
@@ -11,7 +12,6 @@ from django.core.files.move import file_move_safe
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
-from django.utils import unittest
from django.utils.six import StringIO
from .models import Storage, temp_storage, temp_storage_location
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index d0942afdb7..6f2218b19e 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -56,7 +56,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_loading_and_dumping(self):
Site.objects.all().delete()
# Load fixture 1. Single JSON file, with two objects.
- management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture1.json', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: Time to reform copyright>',
'<Article: Poker has no place on ESPN>',
@@ -87,7 +87,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
self._dumpdata_assert(['fixtures.Category', 'sites'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]')
# Load fixture 2. JSON file imported by default. Overwrites some existing objects
- management.call_command('loaddata', 'fixture2.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture2.json', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: Django conquers world!>',
'<Article: Copyright is fine the way it is>',
@@ -95,7 +95,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
])
# Load fixture 3, XML format.
- management.call_command('loaddata', 'fixture3.xml', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture3.xml', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: XML identified as leading cause of cancer>',
'<Article: Django conquers world!>',
@@ -104,14 +104,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
])
# Load fixture 6, JSON file with dynamic ContentType fields. Testing ManyToOne.
- management.call_command('loaddata', 'fixture6.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture6.json', verbosity=0)
self.assertQuerysetEqual(Tag.objects.all(), [
'<Tag: <Article: Copyright is fine the way it is> tagged "copyright">',
'<Tag: <Article: Copyright is fine the way it is> tagged "law">',
], ordered=False)
# Load fixture 7, XML file with dynamic ContentType fields. Testing ManyToOne.
- management.call_command('loaddata', 'fixture7.xml', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture7.xml', verbosity=0)
self.assertQuerysetEqual(Tag.objects.all(), [
'<Tag: <Article: Copyright is fine the way it is> tagged "copyright">',
'<Tag: <Article: Copyright is fine the way it is> tagged "legal">',
@@ -120,7 +120,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
], ordered=False)
# Load fixture 8, JSON file with dynamic Permission fields. Testing ManyToMany.
- management.call_command('loaddata', 'fixture8.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture8.json', verbosity=0)
self.assertQuerysetEqual(Visa.objects.all(), [
'<Visa: Django Reinhardt Can add user, Can change user, Can delete user>',
'<Visa: Stephane Grappelli Can add user>',
@@ -128,7 +128,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
], ordered=False)
# Load fixture 9, XML file with dynamic Permission fields. Testing ManyToMany.
- management.call_command('loaddata', 'fixture9.xml', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture9.xml', verbosity=0)
self.assertQuerysetEqual(Visa.objects.all(), [
'<Visa: Django Reinhardt Can add user, Can change user, Can delete user>',
'<Visa: Stephane Grappelli Can add user, Can delete user>',
@@ -143,15 +143,13 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# Loading a fixture that doesn't exist emits a warning
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
- management.call_command('loaddata', 'unknown.json', verbosity=0,
- commit=False)
+ management.call_command('loaddata', 'unknown.json', verbosity=0)
self.assertEqual(len(w), 1)
self.assertTrue(w[0].message, "No fixture named 'unknown' found.")
# An attempt to load a nonexistent 'initial_data' fixture isn't an error
with warnings.catch_warnings(record=True) as w:
- management.call_command('loaddata', 'initial_data.json', verbosity=0,
- commit=False)
+ management.call_command('loaddata', 'initial_data.json', verbosity=0)
self.assertEqual(len(w), 0)
# object list is unaffected
@@ -178,7 +176,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_dumpdata_with_excludes(self):
# Load fixture1 which has a site, two articles, and a category
Site.objects.all().delete()
- management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture1.json', verbosity=0)
# Excluding fixtures app should only leave sites
self._dumpdata_assert(
@@ -226,8 +224,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % (spy2.pk, spy1.pk), use_base_manager=True)
def test_dumpdata_with_pks(self):
- management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
- management.call_command('loaddata', 'fixture2.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture1.json', verbosity=0)
+ management.call_command('loaddata', 'fixture2.json', verbosity=0)
self._dumpdata_assert(
['fixtures.Article'],
'[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
@@ -266,21 +264,21 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_compress_format_loading(self):
# Load fixture 4 (compressed), using format specification
- management.call_command('loaddata', 'fixture4.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture4.json', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: Django pets kitten>',
])
def test_compressed_specified_loading(self):
# Load fixture 5 (compressed), using format *and* compression specification
- management.call_command('loaddata', 'fixture5.json.zip', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture5.json.zip', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: WoW subscribers now outnumber readers>',
])
def test_compressed_loading(self):
# Load fixture 5 (compressed), only compression specification
- management.call_command('loaddata', 'fixture5.zip', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture5.zip', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: WoW subscribers now outnumber readers>',
])
@@ -288,13 +286,13 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_ambiguous_compressed_fixture(self):
# The name "fixture5" is ambigous, so loading it will raise an error
with self.assertRaises(management.CommandError) as cm:
- management.call_command('loaddata', 'fixture5', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture5', verbosity=0)
self.assertIn("Multiple fixtures named 'fixture5'", cm.exception.args[0])
def test_db_loading(self):
# Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly
- management.call_command('loaddata', 'db_fixture_1', verbosity=0, commit=False)
- management.call_command('loaddata', 'db_fixture_2', verbosity=0, commit=False)
+ management.call_command('loaddata', 'db_fixture_1', verbosity=0)
+ management.call_command('loaddata', 'db_fixture_2', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: Who needs more than one database?>',
'<Article: Who needs to use compressed data?>',
@@ -312,13 +310,13 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
if connection.vendor == 'mysql':
connection.cursor().execute("SET sql_mode = 'TRADITIONAL'")
with self.assertRaises(IntegrityError) as cm:
- management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'invalid.json', verbosity=0)
self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0])
def test_loading_using(self):
# Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
- management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default', commit=False)
- management.call_command('loaddata', 'db_fixture_2', verbosity=0, using='default', commit=False)
+ management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default')
+ management.call_command('loaddata', 'db_fixture_2', verbosity=0, using='default')
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: Who needs more than one database?>',
'<Article: Who needs to use compressed data?>',
@@ -327,18 +325,18 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_unmatched_identifier_loading(self):
# Try to load db fixture 3. This won't load because the database identifier doesn't match
with warnings.catch_warnings(record=True):
- management.call_command('loaddata', 'db_fixture_3', verbosity=0, commit=False)
+ management.call_command('loaddata', 'db_fixture_3', verbosity=0)
with warnings.catch_warnings(record=True):
- management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default', commit=False)
+ management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default')
self.assertQuerysetEqual(Article.objects.all(), [])
def test_output_formats(self):
# Load back in fixture 1, we need the articles from it
- management.call_command('loaddata', 'fixture1', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture1', verbosity=0)
# Try to load fixture 6 using format discovery
- management.call_command('loaddata', 'fixture6', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture6', verbosity=0)
self.assertQuerysetEqual(Tag.objects.all(), [
'<Tag: <Article: Time to reform copyright> tagged "copyright">',
'<Tag: <Article: Time to reform copyright> tagged "law">'
@@ -364,7 +362,7 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
@skipUnlessDBFeature('supports_forward_references')
def test_format_discovery(self):
# Load fixture 1 again, using format discovery
- management.call_command('loaddata', 'fixture1', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture1', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: Time to reform copyright>',
'<Article: Poker has no place on ESPN>',
@@ -386,7 +384,7 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]')
# Load fixture 4 (compressed), using format discovery
- management.call_command('loaddata', 'fixture4', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture4', verbosity=0)
self.assertQuerysetEqual(Article.objects.all(), [
'<Article: Django pets kitten>',
'<Article: Time to reform copyright>',
diff --git a/tests/fixtures_model_package/tests.py b/tests/fixtures_model_package/tests.py
index dbcc721d8f..4b00e6dfb9 100644
--- a/tests/fixtures_model_package/tests.py
+++ b/tests/fixtures_model_package/tests.py
@@ -60,7 +60,6 @@ class TestNoInitialDataLoading(TransactionTestCase):
'flush',
verbosity=0,
interactive=False,
- commit=False,
load_initial_data=False
)
self.assertQuerysetEqual(Book.objects.all(), [])
@@ -83,7 +82,7 @@ class FixtureTestCase(TestCase):
def test_loaddata(self):
"Fixtures can load data into models defined in packages"
# Load fixture 1. Single JSON file, with two objects
- management.call_command("loaddata", "fixture1.json", verbosity=0, commit=False)
+ management.call_command("loaddata", "fixture1.json", verbosity=0)
self.assertQuerysetEqual(
Article.objects.all(), [
"Time to reform copyright",
@@ -94,7 +93,7 @@ class FixtureTestCase(TestCase):
# Load fixture 2. JSON file imported by default. Overwrites some
# existing objects
- management.call_command("loaddata", "fixture2.json", verbosity=0, commit=False)
+ management.call_command("loaddata", "fixture2.json", verbosity=0)
self.assertQuerysetEqual(
Article.objects.all(), [
"Django conquers world!",
@@ -107,7 +106,7 @@ class FixtureTestCase(TestCase):
# Load a fixture that doesn't exist
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
- management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
+ management.call_command("loaddata", "unknown.json", verbosity=0)
self.assertEqual(len(w), 1)
self.assertTrue(w[0].message, "No fixture named 'unknown' found.")
diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py
index 0f6ac65976..a9d67ec9a2 100644
--- a/tests/fixtures_regress/tests.py
+++ b/tests/fixtures_regress/tests.py
@@ -45,7 +45,6 @@ class TestFixtures(TestCase):
'loaddata',
'sequence',
verbosity=0,
- commit=False
)
# Create a new animal. Without a sequence reset, this new object
@@ -84,7 +83,6 @@ class TestFixtures(TestCase):
'sequence_extra',
ignore=True,
verbosity=0,
- commit=False
)
self.assertEqual(Animal.specimens.all()[0].name, 'Lion')
@@ -98,7 +96,6 @@ class TestFixtures(TestCase):
'sequence_extra_xml',
ignore=True,
verbosity=0,
- commit=False
)
self.assertEqual(Animal.specimens.all()[0].name, 'Wolf')
@@ -113,7 +110,6 @@ class TestFixtures(TestCase):
'loaddata',
'pretty.xml',
verbosity=0,
- commit=False
)
self.assertEqual(Stuff.objects.all()[0].name, None)
self.assertEqual(Stuff.objects.all()[0].owner, None)
@@ -129,7 +125,6 @@ class TestFixtures(TestCase):
'loaddata',
'pretty.xml',
verbosity=0,
- commit=False
)
self.assertEqual(Stuff.objects.all()[0].name, '')
self.assertEqual(Stuff.objects.all()[0].owner, None)
@@ -152,7 +147,6 @@ class TestFixtures(TestCase):
'loaddata',
load_absolute_path,
verbosity=0,
- commit=False
)
self.assertEqual(Absolute.load_count, 1)
@@ -168,7 +162,6 @@ class TestFixtures(TestCase):
'loaddata',
'bad_fixture1.unkn',
verbosity=0,
- commit=False,
)
@override_settings(SERIALIZATION_MODULES={'unkn': 'unexistent.path'})
@@ -182,7 +175,6 @@ class TestFixtures(TestCase):
'loaddata',
'bad_fixture1.unkn',
verbosity=0,
- commit=False,
)
def test_invalid_data(self):
@@ -197,7 +189,6 @@ class TestFixtures(TestCase):
'loaddata',
'bad_fixture2.xml',
verbosity=0,
- commit=False,
)
def test_invalid_data_no_ext(self):
@@ -212,7 +203,6 @@ class TestFixtures(TestCase):
'loaddata',
'bad_fixture2',
verbosity=0,
- commit=False,
)
def test_empty(self):
@@ -226,7 +216,6 @@ class TestFixtures(TestCase):
'loaddata',
'empty',
verbosity=0,
- commit=False,
)
def test_error_message(self):
@@ -240,7 +229,6 @@ class TestFixtures(TestCase):
'bad_fixture2',
'animal',
verbosity=0,
- commit=False,
)
def test_pg_sequence_resetting_checks(self):
@@ -253,7 +241,6 @@ class TestFixtures(TestCase):
'loaddata',
'model-inheritance.json',
verbosity=0,
- commit=False
)
self.assertEqual(Parent.objects.all()[0].id, 1)
self.assertEqual(Child.objects.all()[0].id, 1)
@@ -270,7 +257,6 @@ class TestFixtures(TestCase):
'loaddata',
'big-fixture.json',
verbosity=0,
- commit=False
)
articles = Article.objects.exclude(id=9)
self.assertEqual(
@@ -297,7 +283,6 @@ class TestFixtures(TestCase):
'loaddata',
'animal.xml',
verbosity=0,
- commit=False,
)
self.assertEqual(
self.pre_save_checks,
@@ -319,13 +304,11 @@ class TestFixtures(TestCase):
'loaddata',
'animal.xml',
verbosity=0,
- commit=False,
)
management.call_command(
'loaddata',
'sequence.json',
verbosity=0,
- commit=False,
)
animal = Animal(
name='Platypus',
@@ -390,7 +373,6 @@ class TestFixtures(TestCase):
'loaddata',
'forward_ref.json',
verbosity=0,
- commit=False
)
self.assertEqual(Book.objects.all()[0].id, 1)
self.assertEqual(Person.objects.all()[0].id, 4)
@@ -405,7 +387,6 @@ class TestFixtures(TestCase):
'loaddata',
'forward_ref_bad_data.json',
verbosity=0,
- commit=False,
)
_cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
@@ -422,7 +403,6 @@ class TestFixtures(TestCase):
'forward_ref_1.json',
'forward_ref_2.json',
verbosity=0,
- commit=False
)
self.assertEqual(Book.objects.all()[0].id, 1)
self.assertEqual(Person.objects.all()[0].id, 4)
@@ -437,7 +417,6 @@ class TestFixtures(TestCase):
management.call_command(
'loaddata',
verbosity=0,
- commit=False,
)
def test_loaddata_not_existant_fixture_file(self):
@@ -447,7 +426,6 @@ class TestFixtures(TestCase):
'loaddata',
'this_fixture_doesnt_exist',
verbosity=2,
- commit=False,
stdout=stdout_output,
)
self.assertTrue("No fixture 'this_fixture_doesnt_exist' in" in
@@ -465,13 +443,11 @@ class NaturalKeyFixtureTests(TestCase):
'loaddata',
'model-inheritance.json',
verbosity=0,
- commit=False
)
management.call_command(
'loaddata',
'nk-inheritance.json',
verbosity=0,
- commit=False
)
self.assertEqual(
NKChild.objects.get(pk=1).data,
@@ -492,19 +468,16 @@ class NaturalKeyFixtureTests(TestCase):
'loaddata',
'model-inheritance.json',
verbosity=0,
- commit=False
)
management.call_command(
'loaddata',
'nk-inheritance.json',
verbosity=0,
- commit=False
)
management.call_command(
'loaddata',
'nk-inheritance2.xml',
verbosity=0,
- commit=False
)
self.assertEqual(
NKChild.objects.get(pk=2).data,
@@ -524,7 +497,6 @@ class NaturalKeyFixtureTests(TestCase):
'loaddata',
'forward_ref_lookup.json',
verbosity=0,
- commit=False
)
stdout = StringIO()
@@ -662,19 +634,16 @@ class NaturalKeyFixtureTests(TestCase):
'loaddata',
'non_natural_1.json',
verbosity=0,
- commit=False
)
management.call_command(
'loaddata',
'forward_ref_lookup.json',
verbosity=0,
- commit=False
)
management.call_command(
'loaddata',
'non_natural_2.xml',
verbosity=0,
- commit=False
)
books = Book.objects.all()
self.assertEqual(
@@ -696,7 +665,6 @@ class TestTicket11101(TransactionTestCase):
'loaddata',
'thingy.json',
verbosity=0,
- commit=False
)
self.assertEqual(Thingy.objects.count(), 1)
transaction.rollback()
diff --git a/tests/forms_tests/tests/test_validators.py b/tests/forms_tests/tests/test_validators.py
index 0598835cff..08fb96618c 100644
--- a/tests/forms_tests/tests/test_validators.py
+++ b/tests/forms_tests/tests/test_validators.py
@@ -1,9 +1,10 @@
from __future__ import unicode_literals
+from unittest import TestCase
+
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
-from django.utils.unittest import TestCase
class UserForm(forms.Form):
diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py
index f95732f8b5..013a8f282c 100644
--- a/tests/generic_views/test_base.py
+++ b/tests/generic_views/test_base.py
@@ -1,11 +1,11 @@
from __future__ import absolute_import
import time
+import unittest
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponse
from django.test import TestCase, RequestFactory
-from django.utils import unittest
from django.views.generic import View, TemplateView, RedirectView
from . import views
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py
index 263326322e..bff909f7d0 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -2,12 +2,12 @@ from __future__ import absolute_import
import time
import datetime
+from unittest import skipUnless
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, skipUnlessDBFeature
from django.test.utils import override_settings
from django.utils import timezone
-from django.utils.unittest import skipUnless
from .models import Book, BookSigning
diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py
index 84d18ebcb2..9ed18833e4 100644
--- a/tests/generic_views/test_edit.py
+++ b/tests/generic_views/test_edit.py
@@ -1,12 +1,12 @@
from __future__ import absolute_import
import warnings
+from unittest import expectedFailure
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django import forms
from django.test import TestCase
-from django.utils.unittest import expectedFailure
from django.test.client import RequestFactory
from django.views.generic.base import View
from django.views.generic.edit import FormMixin, CreateView
@@ -146,7 +146,7 @@ class CreateViewTests(TestCase):
def test_create_view_all_fields(self):
with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always", PendingDeprecationWarning)
+ warnings.simplefilter("always", DeprecationWarning)
class MyCreateView(CreateView):
model = Author
@@ -160,7 +160,7 @@ class CreateViewTests(TestCase):
def test_create_view_without_explicit_fields(self):
with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always", PendingDeprecationWarning)
+ warnings.simplefilter("always", DeprecationWarning)
class MyCreateView(CreateView):
model = Author
@@ -171,7 +171,7 @@ class CreateViewTests(TestCase):
['name', 'slug'])
# but with a warning:
- self.assertEqual(w[0].category, PendingDeprecationWarning)
+ self.assertEqual(w[0].category, DeprecationWarning)
class UpdateViewTests(TestCase):
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index 194232e92f..3a2ec23864 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
import copy
import os
import pickle
+import unittest
import warnings
from django.core.exceptions import SuspiciousOperation
@@ -18,7 +19,6 @@ from django.test import TestCase
from django.utils.encoding import smart_str
from django.utils._os import upath
from django.utils import six
-from django.utils import unittest
class QueryDictTests(unittest.TestCase):
@@ -324,19 +324,10 @@ class HttpResponseTests(unittest.TestCase):
r.content = [1, 2, 3]
self.assertEqual(r.content, b'123')
- #test retrieval explicitly using iter (deprecated) and odd inputs
+ #test odd inputs
r = HttpResponse()
r.content = ['1', '2', 3, '\u079e']
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always", DeprecationWarning)
- my_iter = iter(r)
- self.assertEqual(w[0].category, DeprecationWarning)
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always", DeprecationWarning)
- result = list(my_iter)
- self.assertEqual(w[0].category, DeprecationWarning)
#'\xde\x9e' == unichr(1950).encode('utf-8')
- self.assertEqual(result, [b'1', b'2', b'3', b'\xde\x9e'])
self.assertEqual(r.content, b'123\xde\x9e')
#with Content-Encoding header
@@ -344,9 +335,8 @@ class HttpResponseTests(unittest.TestCase):
r['Content-Encoding'] = 'winning'
r.content = [b'abc', b'def']
self.assertEqual(r.content, b'abcdef')
- r.content = ['\u079e']
self.assertRaises(TypeError if six.PY3 else UnicodeEncodeError,
- getattr, r, 'content')
+ setattr, r, 'content', ['\u079e'])
# .content can safely be accessed multiple times.
r = HttpResponse(iter(['hello', 'world']))
@@ -358,15 +348,12 @@ class HttpResponseTests(unittest.TestCase):
# accessing .content still works
self.assertEqual(r.content, b'helloworld')
- # XXX accessing .content doesn't work if the response was iterated first
- # XXX change this when the deprecation completes in HttpResponse
+ # Accessing .content also works if the response was iterated first.
r = HttpResponse(iter(['hello', 'world']))
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- self.assertEqual(b''.join(r), b'helloworld')
- self.assertEqual(r.content, b'') # not the expected result!
+ self.assertEqual(b''.join(r), b'helloworld')
+ self.assertEqual(r.content, b'helloworld')
- # additional content can be written to the response.
+ # Additional content can be written to the response.
r = HttpResponse(iter(['hello', 'world']))
self.assertEqual(r.content, b'helloworld')
r.write('!')
diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py
index 672e35d286..605fe9037c 100644
--- a/tests/indexes/tests.py
+++ b/tests/indexes/tests.py
@@ -1,7 +1,8 @@
+from unittest import skipUnless
+
from django.core.management.color import no_style
from django.db import connections, DEFAULT_DB_ALIAS
from django.test import TestCase
-from django.utils.unittest import skipUnless
from .models import Article
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index 79cbbfa3f2..c9093b9e9e 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -2,11 +2,11 @@
from __future__ import unicode_literals
import re
+from unittest import expectedFailure
from django.core.management import call_command
from django.db import connection
from django.test import TestCase, skipUnlessDBFeature
-from django.utils.unittest import expectedFailure
from django.utils.six import PY3, StringIO
if connection.vendor == 'oracle':
diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py
index 67e0266a66..f1c87bbf14 100644
--- a/tests/introspection/tests.py
+++ b/tests/introspection/tests.py
@@ -1,8 +1,9 @@
from __future__ import absolute_import, unicode_literals
+import unittest
+
from django.db import connection
from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature
-from django.utils import unittest
from .models import Reporter, Article
diff --git a/tests/invalid_models/tests.py b/tests/invalid_models/tests.py
index f878525b3b..9c9db91da9 100644
--- a/tests/invalid_models/tests.py
+++ b/tests/invalid_models/tests.py
@@ -1,11 +1,10 @@
import copy
import sys
+import unittest
from django.core.management.validation import get_validation_errors
from django.db.models.loading import cache, load_app
-
from django.test.utils import override_settings
-from django.utils import unittest
from django.utils.six import StringIO
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py
index 0c2d269464..cae2860306 100644
--- a/tests/logging_tests/tests.py
+++ b/tests/logging_tests/tests.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
import copy
import logging
import sys
+from unittest import skipUnless
import warnings
from django.conf import LazySettings
@@ -13,7 +14,6 @@ from django.utils.encoding import force_text
from django.utils.log import (CallbackFilter, RequireDebugFalse,
RequireDebugTrue)
from django.utils.six import StringIO
-from django.utils.unittest import skipUnless
from admin_scripts.tests import AdminScriptTestCase
diff --git a/tests/max_lengths/tests.py b/tests/max_lengths/tests.py
index 9dfcabff45..0f525864d5 100644
--- a/tests/max_lengths/tests.py
+++ b/tests/max_lengths/tests.py
@@ -1,6 +1,6 @@
from __future__ import absolute_import
-from django.utils import unittest
+import unittest
from .models import PersonWithDefaultMaxLengths, PersonWithCustomMaxLengths
@@ -36,4 +36,4 @@ class MaxLengthORMTests(unittest.TestCase):
new_args = args.copy()
new_args[field] = "X" * 250 # a value longer than any of the default fields could hold.
p = PersonWithCustomMaxLengths.objects.create(**new_args)
- self.assertEqual(getattr(p, field), ("X" * 250)) \ No newline at end of file
+ self.assertEqual(getattr(p, field), ("X" * 250))
diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py
index 20645cf91f..5ceab2e594 100644
--- a/tests/middleware/tests.py
+++ b/tests/middleware/tests.py
@@ -5,6 +5,7 @@ import gzip
from io import BytesIO
import random
import re
+from unittest import expectedFailure, skipIf
import warnings
from django.conf import settings
@@ -18,11 +19,10 @@ from django.middleware.http import ConditionalGetMiddleware
from django.middleware.gzip import GZipMiddleware
from django.middleware.transaction import TransactionMiddleware
from django.test import TransactionTestCase, TestCase, RequestFactory
-from django.test.utils import override_settings, IgnorePendingDeprecationWarningsMixin
+from django.test.utils import override_settings, IgnoreDeprecationWarningsMixin
from django.utils import six
from django.utils.encoding import force_str
from django.utils.six.moves import xrange
-from django.utils.unittest import expectedFailure, skipIf
from .models import Band
@@ -249,7 +249,7 @@ class CommonMiddlewareTest(TestCase):
request = self._get_request('regular_url/that/does/not/exist')
request.META['HTTP_REFERER'] = '/another/url/'
with warnings.catch_warnings():
- warnings.simplefilter("ignore", PendingDeprecationWarning)
+ warnings.simplefilter("ignore", DeprecationWarning)
response = self.client.get(request.path)
CommonMiddleware().process_response(request, response)
self.assertEqual(len(mail.outbox), 1)
@@ -261,7 +261,7 @@ class CommonMiddlewareTest(TestCase):
def test_404_error_reporting_no_referer(self):
request = self._get_request('regular_url/that/does/not/exist')
with warnings.catch_warnings():
- warnings.simplefilter("ignore", PendingDeprecationWarning)
+ warnings.simplefilter("ignore", DeprecationWarning)
response = self.client.get(request.path)
CommonMiddleware().process_response(request, response)
self.assertEqual(len(mail.outbox), 0)
@@ -273,7 +273,7 @@ class CommonMiddlewareTest(TestCase):
request = self._get_request('foo_url/that/does/not/exist/either')
request.META['HTTP_REFERER'] = '/another/url/'
with warnings.catch_warnings():
- warnings.simplefilter("ignore", PendingDeprecationWarning)
+ warnings.simplefilter("ignore", DeprecationWarning)
response = self.client.get(request.path)
CommonMiddleware().process_response(request, response)
self.assertEqual(len(mail.outbox), 0)
@@ -703,7 +703,7 @@ class ETagGZipMiddlewareTest(TestCase):
self.assertNotEqual(gzip_etag, nogzip_etag)
-class TransactionMiddlewareTest(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TransactionMiddlewareTest(IgnoreDeprecationWarningsMixin, TransactionTestCase):
"""
Test the transaction middleware.
"""
diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py
index 457892ddb8..f6019bd77f 100644
--- a/tests/model_fields/test_imagefield.py
+++ b/tests/model_fields/test_imagefield.py
@@ -2,13 +2,13 @@ from __future__ import absolute_import
import os
import shutil
+from unittest import skipIf
from django.core.exceptions import ImproperlyConfigured
from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
from django.utils._os import upath
-from django.utils.unittest import skipIf
try:
from .models import Image
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index ccff8b8cfa..6546c49ec7 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
import datetime
from decimal import Decimal
+import unittest
from django import test
from django import forms
@@ -9,7 +10,6 @@ from django.core.exceptions import ValidationError
from django.db import connection, models, IntegrityError
from django.db.models.fields.files import FieldFile
from django.utils import six
-from django.utils import unittest
from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post,
NullBooleanModel, BooleanModel, DataModel, Document, RenamedField,
@@ -432,6 +432,17 @@ class FileFieldTests(unittest.TestCase):
field.save_form_data(d, 'else.txt')
self.assertEqual(d.myfile, 'else.txt')
+ def test_delete_when_file_unset(self):
+ """
+ Calling delete on an unset FileField should not call the file deletion
+ process, but fail silently (#20660).
+ """
+ d = Document()
+ try:
+ d.myfile.delete()
+ except OSError:
+ self.fail("Deleting an unset FileField should not raise OSError.")
+
class BinaryFieldTests(test.TestCase):
binary_data = b'\x00\x46\xFE'
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index 39be824798..09c62c5205 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
import datetime
import os
from decimal import Decimal
+from unittest import skipUnless
import warnings
from django import forms
@@ -13,7 +14,6 @@ from django.db import connection
from django.db.models.query import EmptyQuerySet
from django.forms.models import model_to_dict
from django.utils._os import upath
-from django.utils.unittest import skipUnless
from django.test import TestCase
from django.utils import six
@@ -252,10 +252,12 @@ class StatusNoteCBM2mForm(forms.ModelForm):
fields = '__all__'
widgets = {'status': forms.CheckboxSelectMultiple}
+
class CustomErrorMessageForm(forms.ModelForm):
name1 = forms.CharField(error_messages={'invalid': 'Form custom error message.'})
class Meta:
+ fields = '__all__'
model = CustomErrorMessage
@@ -266,7 +268,7 @@ class ModelFormBaseTest(TestCase):
def test_missing_fields_attribute(self):
with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always", PendingDeprecationWarning)
+ warnings.simplefilter("always", DeprecationWarning)
class MissingFieldsForm(forms.ModelForm):
class Meta:
@@ -276,7 +278,7 @@ class ModelFormBaseTest(TestCase):
# if a warning has been seen already, the catch_warnings won't
# have recorded it. The following line therefore will not work reliably:
- # self.assertEqual(w[0].category, PendingDeprecationWarning)
+ # self.assertEqual(w[0].category, DeprecationWarning)
# Until end of the deprecation cycle, should still create the
# form as before:
diff --git a/tests/model_forms_regress/tests.py b/tests/model_forms_regress/tests.py
index 39ae857219..35e706ac4c 100644
--- a/tests/model_forms_regress/tests.py
+++ b/tests/model_forms_regress/tests.py
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals
from datetime import date
+import unittest
import warnings
from django import forms
@@ -9,7 +10,6 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms.models import (modelform_factory, ModelChoiceField,
fields_for_model, construct_instance, ModelFormMetaclass)
from django.utils import six
-from django.utils import unittest
from django.test import TestCase
from .models import (Person, RealPerson, Triple, FilePathModel, Article,
@@ -566,10 +566,10 @@ class CustomMetaclassTestCase(TestCase):
class TestTicket19733(TestCase):
def test_modelform_factory_without_fields(self):
with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always", PendingDeprecationWarning)
+ warnings.simplefilter("always", DeprecationWarning)
# This should become an error once deprecation cycle is complete.
form = modelform_factory(Person)
- self.assertEqual(w[0].category, PendingDeprecationWarning)
+ self.assertEqual(w[0].category, DeprecationWarning)
def test_modelform_factory_with_all_fields(self):
form = modelform_factory(Person, fields="__all__")
diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py
index 43509c471f..09a3ba1778 100644
--- a/tests/model_formsets/tests.py
+++ b/tests/model_formsets/tests.py
@@ -399,7 +399,7 @@ class ModelFormsetTest(TestCase):
super(BaseAuthorFormSet, self).__init__(*args, **kwargs)
self.queryset = Author.objects.filter(name__startswith='Charles')
- AuthorFormSet = modelformset_factory(Author, formset=BaseAuthorFormSet)
+ AuthorFormSet = modelformset_factory(Author, fields='__all__', formset=BaseAuthorFormSet)
formset = AuthorFormSet()
self.assertEqual(len(formset.get_queryset()), 1)
diff --git a/tests/model_inheritance_regress/tests.py b/tests/model_inheritance_regress/tests.py
index 28635a29a9..7ca16647fa 100644
--- a/tests/model_inheritance_regress/tests.py
+++ b/tests/model_inheritance_regress/tests.py
@@ -5,10 +5,10 @@ from __future__ import absolute_import, unicode_literals
import datetime
from operator import attrgetter
-from django import forms
+from unittest import expectedFailure
+from django import forms
from django.test import TestCase
-from django.utils.unittest import expectedFailure
from .models import (Place, Restaurant, ItalianRestaurant, ParkingLot,
ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
diff --git a/tests/model_regress/tests.py b/tests/model_regress/tests.py
index 71ccb071d2..2924b220e6 100644
--- a/tests/model_regress/tests.py
+++ b/tests/model_regress/tests.py
@@ -3,12 +3,12 @@ from __future__ import absolute_import, unicode_literals
import datetime
from operator import attrgetter
import sys
+import unittest
from django.core.exceptions import ValidationError
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six
from django.utils import tzinfo
-from django.utils import unittest
from django.db import connection, router
from django.db.models.sql import InsertQuery
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
index 805b57c070..0d0fed394a 100644
--- a/tests/modeladmin/tests.py
+++ b/tests/modeladmin/tests.py
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals
from datetime import date
+import unittest
from django import forms
from django.conf import settings
@@ -15,7 +16,7 @@ from django.forms.models import BaseModelFormSet
from django.forms.widgets import Select
from django.test import TestCase
from django.test.utils import str_prefix
-from django.utils import unittest, six
+from django.utils import six
from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel
diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py
index a0d937ce81..12a6379ca0 100644
--- a/tests/multiple_database/tests.py
+++ b/tests/multiple_database/tests.py
@@ -3,9 +3,7 @@ from __future__ import absolute_import, unicode_literals
import datetime
import pickle
from operator import attrgetter
-import warnings
-from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core import management
@@ -1626,25 +1624,6 @@ class AuthTestCase(TestCase):
command_output = new_io.getvalue().strip()
self.assertTrue('"email": "alice@example.com"' in command_output)
-
-@override_settings(AUTH_PROFILE_MODULE='multiple_database.UserProfile')
-class UserProfileTestCase(TestCase):
-
- def test_user_profiles(self):
- alice = User.objects.create_user('alice', 'alice@example.com')
- bob = User.objects.db_manager('other').create_user('bob', 'bob@example.com')
-
- alice_profile = UserProfile(user=alice, flavor='chocolate')
- alice_profile.save()
-
- bob_profile = UserProfile(user=bob, flavor='crunchy frog')
- bob_profile.save()
-
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- self.assertEqual(alice.get_profile().flavor, 'chocolate')
- self.assertEqual(bob.get_profile().flavor, 'crunchy frog')
-
class AntiPetRouter(object):
# A router that only expresses an opinion on syncdb,
# passing pets to the 'other' database
diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py
index 1dea4526e3..76799bec46 100644
--- a/tests/pagination/tests.py
+++ b/tests/pagination/tests.py
@@ -1,12 +1,12 @@
from __future__ import absolute_import, unicode_literals
from datetime import datetime
+import unittest
from django.core.paginator import (Paginator, EmptyPage, InvalidPage,
PageNotAnInteger)
from django.test import TestCase
from django.utils import six
-from django.utils import unittest
from .models import Article
from .custom import ValidAdjacentNumsPaginator
diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
index 77d2ba9a74..5cc5ef5478 100644
--- a/tests/proxy_models/tests.py
+++ b/tests/proxy_models/tests.py
@@ -358,7 +358,7 @@ class ProxyModelTests(TestCase):
)
def test_proxy_load_from_fixture(self):
- management.call_command('loaddata', 'mypeople.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'mypeople.json', verbosity=0)
p = MyPerson.objects.get(pk=100)
self.assertEqual(p.name, 'Elvis Presley')
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 352e87a634..6520eb0176 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -4,6 +4,7 @@ import datetime
from operator import attrgetter
import pickle
import sys
+import unittest
from django.conf import settings
from django.core.exceptions import FieldError
@@ -13,7 +14,6 @@ from django.db.models.sql.where import WhereNode, EverythingNode, NothingNode
from django.db.models.sql.datastructures import EmptyResultSet
from django.test import TestCase, skipUnlessDBFeature
from django.test.utils import str_prefix
-from django.utils import unittest
from django.utils.datastructures import SortedDict
from .models import (
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index d9120db4e7..b00eec87a9 100644
--- a/tests/requests/tests.py
+++ b/tests/requests/tests.py
@@ -1,10 +1,11 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
-import time
-import warnings
from datetime import datetime, timedelta
from io import BytesIO
+import time
+from unittest import skipIf
+import warnings
from django.db import connection, connections, DEFAULT_DB_ALIAS
from django.core import signals
@@ -15,7 +16,6 @@ from django.test import SimpleTestCase, TransactionTestCase
from django.test.client import FakePayload
from django.test.utils import override_settings, str_prefix
from django.utils import six
-from django.utils.unittest import skipIf
from django.utils.http import cookie_date, urlencode
from django.utils.timezone import utc
diff --git a/tests/resolve_url/tests.py b/tests/resolve_url/tests.py
index d0bf44abde..70f9e51781 100644
--- a/tests/resolve_url/tests.py
+++ b/tests/resolve_url/tests.py
@@ -1,8 +1,9 @@
from __future__ import unicode_literals
+from unittest import TestCase
+
from django.core.urlresolvers import NoReverseMatch
from django.contrib.auth.views import logout
-from django.utils.unittest import TestCase
from django.shortcuts import resolve_url
from .models import UnimportantThing
diff --git a/tests/runtests.py b/tests/runtests.py
index da4592ecc0..b604155190 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -109,7 +109,7 @@ def setup(verbosity, test_labels):
# Load all the ALWAYS_INSTALLED_APPS.
with warnings.catch_warnings():
- warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', PendingDeprecationWarning)
+ warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', DeprecationWarning)
get_apps()
# Load all the test model apps.
diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py
index f087ca123a..b8a8ad19bf 100644
--- a/tests/select_for_update/tests.py
+++ b/tests/select_for_update/tests.py
@@ -2,13 +2,13 @@ from __future__ import absolute_import
import sys
import time
+import unittest
from django.conf import settings
from django.db import transaction, connection
from django.db.utils import ConnectionHandler, DEFAULT_DB_ALIAS, DatabaseError
from django.test import (TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature)
-from django.utils import unittest
from .models import Person
diff --git a/tests/select_related/tests.py b/tests/select_related/tests.py
index baa141d123..e6723eac9b 100644
--- a/tests/select_related/tests.py
+++ b/tests/select_related/tests.py
@@ -1,7 +1,5 @@
from __future__ import absolute_import, unicode_literals
-import warnings
-
from django.test import TestCase
from .models import Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species
@@ -55,9 +53,7 @@ class SelectRelatedTests(TestCase):
extra queries
"""
with self.assertNumQueries(1):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- person = Species.objects.select_related(depth=10).get(name="sapiens")
+ person = Species.objects.select_related('genus__family__order__klass__phylum__kingdom__domain').get(name="sapiens")
domain = person.genus.family.order.klass.phylum.kingdom.domain
self.assertEqual(domain.name, 'Eukaryota')
@@ -91,53 +87,27 @@ class SelectRelatedTests(TestCase):
'Hominidae',
])
- def test_depth(self, depth=1, expected=7):
- """
- The "depth" argument to select_related() will stop the descent at a
- particular level.
- """
- # Notice: one fewer queries than above because of depth=1
- with self.assertNumQueries(expected):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- pea = Species.objects.select_related(depth=depth).get(name="sativum")
- self.assertEqual(
- pea.genus.family.order.klass.phylum.kingdom.domain.name,
- 'Eukaryota'
- )
-
- def test_larger_depth(self):
- """
- The "depth" argument to select_related() will stop the descent at a
- particular level. This tests a larger depth value.
- """
- self.test_depth(depth=5, expected=3)
-
def test_list_with_depth(self):
"""
- The "depth" argument to select_related() will stop the descent at a
- particular level. This can be used on lists as well.
+ Passing a relationship field lookup specifier to select_related() will
+ stop the descent at a particular level. This can be used on lists as
+ well.
"""
with self.assertNumQueries(5):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- world = Species.objects.all().select_related(depth=2)
- orders = [o.genus.family.order.name for o in world]
+ world = Species.objects.all().select_related('genus__family')
+ orders = [o.genus.family.order.name for o in world]
self.assertEqual(sorted(orders),
['Agaricales', 'Diptera', 'Fabales', 'Primates'])
def test_select_related_with_extra(self):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- s = Species.objects.all().select_related(depth=1)\
- .extra(select={'a': 'select_related_species.id + 10'})[0]
+ s = Species.objects.all().select_related()\
+ .extra(select={'a': 'select_related_species.id + 10'})[0]
self.assertEqual(s.id + 10, s.a)
def test_certain_fields(self):
"""
The optional fields passed to select_related() control which related
- models we pull in. This allows for smaller queries and can act as an
- alternative (or, in addition to) the depth parameter.
+ models we pull in. This allows for smaller queries.
In this case, we explicitly say to select the 'genus' and
'genus.family' models, leading to the same number of queries as before.
@@ -166,12 +136,10 @@ class SelectRelatedTests(TestCase):
self.assertEqual(s, 'Diptera')
def test_depth_fields_fails(self):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
- self.assertRaises(TypeError,
- Species.objects.select_related,
- 'genus__family__order', depth=4
- )
+ self.assertRaises(TypeError,
+ Species.objects.select_related,
+ 'genus__family__order', depth=4
+ )
def test_none_clears_list(self):
queryset = Species.objects.select_related('genus').select_related(None)
diff --git a/tests/select_related_onetoone/tests.py b/tests/select_related_onetoone/tests.py
index fce8fc4e73..d8ba4d0484 100644
--- a/tests/select_related_onetoone/tests.py
+++ b/tests/select_related_onetoone/tests.py
@@ -1,7 +1,8 @@
from __future__ import absolute_import
+import unittest
+
from django.test import TestCase
-from django.utils import unittest
from .models import (User, UserProfile, UserStat, UserStatResult, StatDetails,
AdvancedUserStat, Image, Product, Parent1, Parent2, Child1, Child2, Child3,
diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py
index 038276ca21..bff7c53249 100644
--- a/tests/serializers/tests.py
+++ b/tests/serializers/tests.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
# -*- coding: utf-8 -*-
import json
from datetime import datetime
+import unittest
from xml.dom import minidom
from django.conf import settings
@@ -11,7 +12,6 @@ from django.db import transaction, connection
from django.test import TestCase, TransactionTestCase, Approximate
from django.utils import six
from django.utils.six import StringIO
-from django.utils import unittest
from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,
Score, Player, Team)
diff --git a/tests/serializers_regress/tests.py b/tests/serializers_regress/tests.py
index 04b4d4c839..1751816cee 100644
--- a/tests/serializers_regress/tests.py
+++ b/tests/serializers_regress/tests.py
@@ -10,7 +10,7 @@ from __future__ import absolute_import, unicode_literals
import datetime
import decimal
-from django.core.serializers.xml_serializer import DTDForbidden
+from unittest import expectedFailure, skipUnless
try:
import yaml
@@ -20,13 +20,13 @@ except ImportError:
from django.core import serializers
from django.core.serializers import SerializerDoesNotExist
from django.core.serializers.base import DeserializationError
+from django.core.serializers.xml_serializer import DTDForbidden
from django.db import connection, models
from django.http import HttpResponse
from django.test import TestCase
from django.utils import six
from django.utils.encoding import force_text
from django.utils.functional import curry
-from django.utils.unittest import expectedFailure, skipUnless
from .models import (BinaryData, BooleanData, CharData, DateData, DateTimeData, EmailData,
FileData, FilePathData, DecimalData, FloatData, IntegerData, IPAddressData,
diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
index 625c4f31df..bfd8d607a9 100644
--- a/tests/settings_tests/tests.py
+++ b/tests/settings_tests/tests.py
@@ -1,4 +1,5 @@
import os
+import unittest
import warnings
from django.conf import settings, global_settings
@@ -6,7 +7,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.http import HttpRequest
from django.test import SimpleTestCase, TransactionTestCase, TestCase, signals
from django.test.utils import override_settings
-from django.utils import unittest, six
+from django.utils import six
@override_settings(TEST='override', TEST_OUTER='outer')
diff --git a/tests/str/tests.py b/tests/str/tests.py
index bd85c48d05..d82908a0ee 100644
--- a/tests/str/tests.py
+++ b/tests/str/tests.py
@@ -2,10 +2,10 @@
from __future__ import absolute_import, unicode_literals
import datetime
+from unittest import skipIf
from django.test import TestCase
from django.utils import six
-from django.utils.unittest import skipIf
from .models import Article, BrokenArticle, InternationalArticle
diff --git a/tests/template_tests/loaders.py b/tests/template_tests/loaders.py
index b77965203f..497b422e7f 100644
--- a/tests/template_tests/loaders.py
+++ b/tests/template_tests/loaders.py
@@ -9,15 +9,16 @@ from django.conf import settings
if __name__ == '__main__':
settings.configure()
-import sys
-import pkg_resources
import imp
import os.path
+import pkg_resources
+import sys
+import unittest
from django.template import TemplateDoesNotExist, Context
from django.template.loaders.eggs import Loader as EggLoader
from django.template import loader
-from django.utils import unittest, six
+from django.utils import six
from django.utils._os import upath
from django.utils.six import StringIO
diff --git a/tests/template_tests/test_callables.py b/tests/template_tests/test_callables.py
index 882a8c6e06..718b7740d9 100644
--- a/tests/template_tests/test_callables.py
+++ b/tests/template_tests/test_callables.py
@@ -1,7 +1,8 @@
from __future__ import unicode_literals
+from unittest import TestCase
+
from django import template
-from django.utils.unittest import TestCase
class CallableVariablesTests(TestCase):
diff --git a/tests/template_tests/test_context.py b/tests/template_tests/test_context.py
index 05c1dd57b9..224b94d060 100644
--- a/tests/template_tests/test_context.py
+++ b/tests/template_tests/test_context.py
@@ -1,6 +1,8 @@
# coding: utf-8
+
+from unittest import TestCase
+
from django.template import Context
-from django.utils.unittest import TestCase
class ContextTests(TestCase):
diff --git a/tests/template_tests/test_custom.py b/tests/template_tests/test_custom.py
index 4aea08237d..e941bc223e 100644
--- a/tests/template_tests/test_custom.py
+++ b/tests/template_tests/test_custom.py
@@ -1,8 +1,9 @@
from __future__ import absolute_import, unicode_literals
+from unittest import TestCase
+
from django import template
from django.utils import six
-from django.utils.unittest import TestCase
from .templatetags import custom
diff --git a/tests/template_tests/test_nodelist.py b/tests/template_tests/test_nodelist.py
index 97aa5af6a7..755c0c3bea 100644
--- a/tests/template_tests/test_nodelist.py
+++ b/tests/template_tests/test_nodelist.py
@@ -1,6 +1,7 @@
+from unittest import TestCase
+
from django.template import VariableNode, Context
from django.template.loader import get_template_from_string
-from django.utils.unittest import TestCase
from django.test.utils import override_settings
class NodelistTest(TestCase):
diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py
index 9422da80d7..e626bfd34f 100644
--- a/tests/template_tests/test_parser.py
+++ b/tests/template_tests/test_parser.py
@@ -3,10 +3,11 @@ Testing some internals of the template processing. These are *not* examples to b
"""
from __future__ import unicode_literals
+from unittest import TestCase
+
from django.template import (TokenParser, FilterExpression, Parser, Variable,
Template, TemplateSyntaxError)
from django.test.utils import override_settings
-from django.utils.unittest import TestCase
from django.utils import six
diff --git a/tests/template_tests/test_smartif.py b/tests/template_tests/test_smartif.py
index 3a705ca663..4345e04126 100644
--- a/tests/template_tests/test_smartif.py
+++ b/tests/template_tests/test_smartif.py
@@ -1,5 +1,6 @@
+import unittest
+
from django.template.smartif import IfParser
-from django.utils import unittest
class SmartIfTests(unittest.TestCase):
diff --git a/tests/template_tests/test_unicode.py b/tests/template_tests/test_unicode.py
index 7cb2a28d15..773dd543b7 100644
--- a/tests/template_tests/test_unicode.py
+++ b/tests/template_tests/test_unicode.py
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+from unittest import TestCase
+
from django.template import Template, TemplateEncodingError, Context
from django.utils.safestring import SafeData
from django.utils import six
-from django.utils.unittest import TestCase
class UnicodeTests(TestCase):
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index 76712a09a6..6b8a106623 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -13,6 +13,7 @@ import time
import os
import sys
import traceback
+import unittest
try:
from urllib.parse import urljoin
except ImportError: # Python 2
@@ -27,7 +28,6 @@ from django.template.loaders import app_directories, filesystem, cached
from django.test import RequestFactory, TestCase
from django.test.utils import (setup_test_template_loader,
restore_template_loaders, override_settings)
-from django.utils import unittest
from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import date_format
from django.utils._os import upath
@@ -534,7 +534,7 @@ class TemplateTests(TransRealMixin, TestCase):
try:
with warnings.catch_warnings():
# Ignore pending deprecations of the old syntax of the 'cycle' and 'firstof' tags.
- warnings.filterwarnings("ignore", category=PendingDeprecationWarning, module='django.template.base')
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module='django.template.base')
test_template = loader.get_template(name)
except ShouldNotExecuteException:
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
diff --git a/tests/test_discovery_sample/tests_sample.py b/tests/test_discovery_sample/tests_sample.py
index c541bc4cd6..fb1e14c715 100644
--- a/tests/test_discovery_sample/tests_sample.py
+++ b/tests/test_discovery_sample/tests_sample.py
@@ -1,16 +1,9 @@
-from unittest import TestCase as UnitTestCase
+from unittest import TestCase
from django.test import TestCase as DjangoTestCase
-from django.utils.unittest import TestCase as UT2TestCase
-class TestVanillaUnittest(UnitTestCase):
-
- def test_sample(self):
- self.assertEqual(1, 1)
-
-
-class TestUnittest2(UT2TestCase):
+class TestVanillaUnittest(TestCase):
def test_sample(self):
self.assertEqual(1, 1)
diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
index 1a0fb88367..4494b2bd3b 100644
--- a/tests/test_runner/test_discover_runner.py
+++ b/tests/test_runner/test_discover_runner.py
@@ -1,15 +1,10 @@
from contextlib import contextmanager
import os
import sys
+from unittest import expectedFailure
from django.test import TestCase
from django.test.runner import DiscoverRunner
-from django.utils.unittest import expectedFailure
-
-try:
- import unittest2
-except ImportError:
- unittest2 = None
def expectedFailureIf(condition):
@@ -26,7 +21,7 @@ class DiscoverRunnerTest(TestCase):
["test_discovery_sample.tests_sample"],
).countTestCases()
- self.assertEqual(count, 3)
+ self.assertEqual(count, 2)
def test_dotted_test_class_vanilla_unittest(self):
count = DiscoverRunner().build_suite(
@@ -35,13 +30,6 @@ class DiscoverRunnerTest(TestCase):
self.assertEqual(count, 1)
- def test_dotted_test_class_unittest2(self):
- count = DiscoverRunner().build_suite(
- ["test_discovery_sample.tests_sample.TestUnittest2"],
- ).countTestCases()
-
- self.assertEqual(count, 1)
-
def test_dotted_test_class_django_testcase(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample.TestDjangoTestCase"],
@@ -49,23 +37,6 @@ class DiscoverRunnerTest(TestCase):
self.assertEqual(count, 1)
- # this test fails if unittest2 is installed from PyPI on Python 2.6
- # refs https://code.djangoproject.com/ticket/20437
- @expectedFailureIf(sys.version_info < (2, 7) and unittest2)
- def test_dotted_test_method_vanilla_unittest(self):
- count = DiscoverRunner().build_suite(
- ["test_discovery_sample.tests_sample.TestVanillaUnittest.test_sample"],
- ).countTestCases()
-
- self.assertEqual(count, 1)
-
- def test_dotted_test_method_unittest2(self):
- count = DiscoverRunner().build_suite(
- ["test_discovery_sample.tests_sample.TestUnittest2.test_sample"],
- ).countTestCases()
-
- self.assertEqual(count, 1)
-
def test_dotted_test_method_django_testcase(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample.TestDjangoTestCase.test_sample"],
@@ -96,4 +67,4 @@ class DiscoverRunnerTest(TestCase):
["test_discovery_sample/"],
).countTestCases()
- self.assertEqual(count, 4)
+ self.assertEqual(count, 3)
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
index 0dc7a0155a..4e9e44bc12 100644
--- a/tests/test_runner/tests.py
+++ b/tests/test_runner/tests.py
@@ -3,16 +3,16 @@ Tests for django test runner
"""
from __future__ import absolute_import, unicode_literals
-import sys
from optparse import make_option
+import sys
+import unittest
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django import db
from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature
from django.test.testcases import connections_support_transactions
-from django.test.utils import IgnorePendingDeprecationWarningsMixin
-from django.utils import unittest
+from django.test.utils import IgnoreAllDeprecationWarningsMixin
from django.utils.importlib import import_module
from admin_scripts.tests import AdminScriptTestCase
@@ -225,7 +225,8 @@ class Ticket17477RegressionTests(AdminScriptTestCase):
self.assertNoOutput(err)
-class ModulesTestsPackages(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
+class ModulesTestsPackages(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
+
def test_get_tests(self):
"Check that the get_tests helper function can find tests in a directory"
from django.test.simple import get_tests
diff --git a/tests/test_suite_override/tests.py b/tests/test_suite_override/tests.py
index 35ca2b060b..e69dab12bf 100644
--- a/tests/test_suite_override/tests.py
+++ b/tests/test_suite_override/tests.py
@@ -1,6 +1,7 @@
+import unittest
+
from django.db.models import get_app
-from django.test.utils import IgnorePendingDeprecationWarningsMixin
-from django.utils import unittest
+from django.test.utils import IgnoreAllDeprecationWarningsMixin
def suite():
@@ -9,7 +10,8 @@ def suite():
return testSuite
-class SuiteOverrideTest(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
+class SuiteOverrideTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
+
def test_suite_override(self):
"""
Validate that you can define a custom suite when running tests with
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 5f7fb05eb4..2c2bc24d72 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
-import warnings
+
+import unittest
+from unittest import skip
from django.db import connection
from django.forms import EmailField, IntegerField
@@ -8,10 +10,8 @@ from django.http import HttpResponse
from django.template.loader import render_to_string
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.test.html import HTMLParseError, parse_html
-from django.test.utils import CaptureQueriesContext, IgnorePendingDeprecationWarningsMixin
+from django.test.utils import CaptureQueriesContext, IgnoreAllDeprecationWarningsMixin
from django.utils import six
-from django.utils import unittest
-from django.utils.unittest import skip
from .models import Person
@@ -270,37 +270,6 @@ class AssertTemplateUsedContextManagerTests(TestCase):
render_to_string('template_used/alternative.html')
-class SaveRestoreWarningState(TestCase):
- def test_save_restore_warnings_state(self):
- """
- Ensure save_warnings_state/restore_warnings_state work correctly.
- """
- # In reality this test could be satisfied by many broken implementations
- # of save_warnings_state/restore_warnings_state (e.g. just
- # warnings.resetwarnings()) , but it is difficult to test more.
- with warnings.catch_warnings():
- warnings.simplefilter("ignore", DeprecationWarning)
-
- self.save_warnings_state()
-
- class MyWarning(Warning):
- pass
-
- # Add a filter that causes an exception to be thrown, so we can catch it
- warnings.simplefilter("error", MyWarning)
- self.assertRaises(Warning, lambda: warnings.warn("warn", MyWarning))
-
- # Now restore.
- self.restore_warnings_state()
- # After restoring, we shouldn't get an exception. But we don't want a
- # warning printed either, so we have to silence the warning.
- warnings.simplefilter("ignore", MyWarning)
- warnings.warn("warn", MyWarning)
-
- # Remove the filter we just added.
- self.restore_warnings_state()
-
-
class HTMLEqualTests(TestCase):
def test_html_parser(self):
element = parse_html('<div><p>Hello</p></div>')
@@ -623,7 +592,7 @@ class AssertFieldOutputTests(SimpleTestCase):
self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None)
-class DoctestNormalizerTest(IgnorePendingDeprecationWarningsMixin, SimpleTestCase):
+class DoctestNormalizerTest(IgnoreAllDeprecationWarningsMixin, SimpleTestCase):
def test_normalizer(self):
from django.test.simple import make_doctest
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index dce5c3041d..49169f90f2 100644
--- a/tests/timezones/tests.py
+++ b/tests/timezones/tests.py
@@ -5,6 +5,7 @@ import os
import re
import sys
import time
+from unittest import skipIf, skipUnless
import warnings
from xml.dom.minidom import parseString
@@ -25,7 +26,6 @@ from django.test.utils import override_settings
from django.utils import six
from django.utils import timezone
from django.utils.tzinfo import FixedOffset
-from django.utils.unittest import skipIf, skipUnless
from .forms import EventForm, EventSplitForm, EventModelForm
from .models import Event, MaybeEvent, Session, SessionEvent, Timestamp, AllDayEvent
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 756fa40abd..afb573f366 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -1,12 +1,12 @@
from __future__ import absolute_import
import sys
+from unittest import skipIf, skipUnless
from django.db import connection, transaction, DatabaseError, IntegrityError
from django.test import TransactionTestCase, skipUnlessDBFeature
-from django.test.utils import IgnorePendingDeprecationWarningsMixin
+from django.test.utils import IgnoreDeprecationWarningsMixin
from django.utils import six
-from django.utils.unittest import skipIf, skipUnless
from .models import Reporter
@@ -350,7 +350,7 @@ class AtomicMiscTests(TransactionTestCase):
transaction.atomic(Callable())
-class TransactionTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
available_apps = ['transactions']
@@ -508,7 +508,7 @@ class TransactionTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCas
)
-class TransactionRollbackTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TransactionRollbackTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
available_apps = ['transactions']
@@ -528,7 +528,7 @@ class TransactionRollbackTests(IgnorePendingDeprecationWarningsMixin, Transactio
self.assertRaises(IntegrityError, execute_bad_sql)
transaction.rollback()
-class TransactionContextManagerTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TransactionContextManagerTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
available_apps = ['transactions']
diff --git a/tests/transactions_regress/tests.py b/tests/transactions_regress/tests.py
index 8078f1d128..bd9e78b033 100644
--- a/tests/transactions_regress/tests.py
+++ b/tests/transactions_regress/tests.py
@@ -1,11 +1,12 @@
from __future__ import absolute_import
+from unittest import skipIf, skipUnless
+
from django.db import (connection, connections, transaction, DEFAULT_DB_ALIAS, DatabaseError,
IntegrityError)
from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
from django.test import TransactionTestCase, skipUnlessDBFeature
-from django.test.utils import override_settings, IgnorePendingDeprecationWarningsMixin
-from django.utils.unittest import skipIf, skipUnless
+from django.test.utils import override_settings, IgnoreDeprecationWarningsMixin
from .models import Mod, M2mA, M2mB, SubMod
@@ -30,7 +31,7 @@ class ModelInheritanceTests(TransactionTestCase):
self.assertEqual(SubMod.objects.count(), 1)
self.assertEqual(Mod.objects.count(), 1)
-class TestTransactionClosing(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TestTransactionClosing(IgnoreDeprecationWarningsMixin, TransactionTestCase):
"""
Tests to make sure that transactions are properly closed
when they should be, and aren't left pending after operations
@@ -194,7 +195,7 @@ class TestTransactionClosing(IgnorePendingDeprecationWarningsMixin, TransactionT
(connection.settings_dict['NAME'] == ':memory:' or
not connection.settings_dict['NAME']),
'Test uses multiple connections, but in-memory sqlite does not support this')
-class TestNewConnection(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TestNewConnection(IgnoreDeprecationWarningsMixin, TransactionTestCase):
"""
Check that new connections don't have special behaviour.
"""
@@ -242,7 +243,7 @@ class TestNewConnection(IgnorePendingDeprecationWarningsMixin, TransactionTestCa
@skipUnless(connection.vendor == 'postgresql',
"This test only valid for PostgreSQL")
-class TestPostgresAutocommitAndIsolation(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TestPostgresAutocommitAndIsolation(IgnoreDeprecationWarningsMixin, TransactionTestCase):
"""
Tests to make sure psycopg2's autocommit mode and isolation level
is restored after entering and leaving transaction management.
@@ -326,7 +327,7 @@ class TestPostgresAutocommitAndIsolation(IgnorePendingDeprecationWarningsMixin,
self.assertTrue(connection.autocommit)
-class TestManyToManyAddTransaction(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class TestManyToManyAddTransaction(IgnoreDeprecationWarningsMixin, TransactionTestCase):
available_apps = ['transactions_regress']
@@ -344,7 +345,7 @@ class TestManyToManyAddTransaction(IgnorePendingDeprecationWarningsMixin, Transa
self.assertEqual(a.others.count(), 1)
-class SavepointTest(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+class SavepointTest(IgnoreDeprecationWarningsMixin, TransactionTestCase):
available_apps = ['transactions_regress']
diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py
index 3962f69288..222ebe053b 100644
--- a/tests/urlpatterns_reverse/tests.py
+++ b/tests/urlpatterns_reverse/tests.py
@@ -3,6 +3,8 @@ Unit tests for reverse URL lookups.
"""
from __future__ import absolute_import, unicode_literals
+import unittest
+
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
@@ -12,7 +14,7 @@ from django.core.urlresolvers import (reverse, resolve, get_callable,
from django.http import HttpRequest, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import redirect
from django.test import TestCase
-from django.utils import unittest, six
+from django.utils import six
from . import urlconf_outer, middleware, views
diff --git a/tests/utils_tests/test_archive.py b/tests/utils_tests/test_archive.py
index 8861b4a577..f00f25e855 100644
--- a/tests/utils_tests/test_archive.py
+++ b/tests/utils_tests/test_archive.py
@@ -1,7 +1,7 @@
import os
import shutil
import tempfile
-from django.utils import unittest
+import unittest
from django.utils.archive import Archive, extract
from django.utils._os import upath
diff --git a/tests/utils_tests/test_baseconv.py b/tests/utils_tests/test_baseconv.py
index d69a3a6412..d49dde1092 100644
--- a/tests/utils_tests/test_baseconv.py
+++ b/tests/utils_tests/test_baseconv.py
@@ -1,4 +1,5 @@
-from django.utils.unittest import TestCase
+from unittest import TestCase
+
from django.utils.baseconv import base2, base16, base36, base56, base62, base64, BaseConverter
from django.utils.six.moves import xrange
diff --git a/tests/utils_tests/test_crypto.py b/tests/utils_tests/test_crypto.py
index 5cf2934ab0..4c1d10bb5f 100644
--- a/tests/utils_tests/test_crypto.py
+++ b/tests/utils_tests/test_crypto.py
@@ -1,11 +1,11 @@
from __future__ import unicode_literals
import binascii
+import hashlib
import math
import timeit
-import hashlib
+import unittest
-from django.utils import unittest
from django.utils.crypto import constant_time_compare, pbkdf2
diff --git a/tests/utils_tests/test_datastructures.py b/tests/utils_tests/test_datastructures.py
index 5829e7c2d7..5563a0fc4f 100644
--- a/tests/utils_tests/test_datastructures.py
+++ b/tests/utils_tests/test_datastructures.py
@@ -4,7 +4,6 @@ Tests for stuff in django.utils.datastructures.
import copy
import pickle
-import warnings
from django.test import SimpleTestCase
from django.utils.datastructures import (DictWrapper, ImmutableList,
@@ -134,20 +133,6 @@ class SortedDictTests(SimpleTestCase):
self.assertEqual(list(reversed(self.d1)), [9, 1, 7])
self.assertEqual(list(reversed(self.d2)), [7, 0, 9, 1])
- def test_insert(self):
- d = SortedDict()
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always")
- d.insert(0, "hello", "world")
- assert w[0].category is DeprecationWarning
-
- def test_value_for_index(self):
- d = SortedDict({"a": 3})
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always")
- self.assertEqual(d.value_for_index(0), 3)
- assert w[0].category is DeprecationWarning
-
class MergeDictTests(SimpleTestCase):
diff --git a/tests/utils_tests/test_dateformat.py b/tests/utils_tests/test_dateformat.py
index 78cedaf764..15262121a0 100644
--- a/tests/utils_tests/test_dateformat.py
+++ b/tests/utils_tests/test_dateformat.py
@@ -3,9 +3,11 @@ from __future__ import unicode_literals
from datetime import datetime, date
import os
import time
+import unittest
from django.utils.dateformat import format
-from django.utils import dateformat, translation, unittest
+from django.utils import dateformat
+from django.utils import translation
from django.utils.timezone import utc
from django.utils.tzinfo import FixedOffset, LocalTimezone
diff --git a/tests/utils_tests/test_dateparse.py b/tests/utils_tests/test_dateparse.py
index 1a6ca646b8..836c26c573 100644
--- a/tests/utils_tests/test_dateparse.py
+++ b/tests/utils_tests/test_dateparse.py
@@ -1,9 +1,9 @@
from __future__ import unicode_literals
from datetime import date, time, datetime
+import unittest
from django.utils.dateparse import parse_date, parse_time, parse_datetime
-from django.utils import unittest
from django.utils.tzinfo import FixedOffset
diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py
index 7aaba25a7a..72c35adec6 100644
--- a/tests/utils_tests/test_encoding.py
+++ b/tests/utils_tests/test_encoding.py
@@ -1,7 +1,8 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
-from django.utils import unittest
+import unittest
+
from django.utils.encoding import force_bytes, filepath_to_uri
diff --git a/tests/utils_tests/test_feedgenerator.py b/tests/utils_tests/test_feedgenerator.py
index bcd53bb2a0..a801305f17 100644
--- a/tests/utils_tests/test_feedgenerator.py
+++ b/tests/utils_tests/test_feedgenerator.py
@@ -1,8 +1,11 @@
from __future__ import unicode_literals
import datetime
+import unittest
+
+from django.utils import feedgenerator
+from django.utils import tzinfo
-from django.utils import feedgenerator, tzinfo, unittest
class FeedgeneratorTest(unittest.TestCase):
"""
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py
index fc2256a1f2..66e051033e 100644
--- a/tests/utils_tests/test_functional.py
+++ b/tests/utils_tests/test_functional.py
@@ -1,4 +1,5 @@
-from django.utils import unittest
+import unittest
+
from django.utils.functional import lazy, lazy_property, cached_property
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index b973f1c64f..1f2e19d8d5 100644
--- a/tests/utils_tests/test_html.py
+++ b/tests/utils_tests/test_html.py
@@ -2,11 +2,11 @@ from __future__ import unicode_literals
from datetime import datetime
import os
+from unittest import TestCase
from django.utils import html
from django.utils._os import upath
from django.utils.encoding import force_text
-from django.utils.unittest import TestCase
class TestUtilsHtml(TestCase):
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py
index 6d3bc025af..581eb1dcd7 100644
--- a/tests/utils_tests/test_http.py
+++ b/tests/utils_tests/test_http.py
@@ -1,12 +1,12 @@
from datetime import datetime
import sys
+import unittest
from django.http import HttpResponse, utils
from django.test import RequestFactory
from django.utils.datastructures import MultiValueDict
from django.utils import http
from django.utils import six
-from django.utils import unittest
class TestUtilsHttp(unittest.TestCase):
diff --git a/tests/utils_tests/test_ipv6.py b/tests/utils_tests/test_ipv6.py
index 1713de82b8..662e8b4135 100644
--- a/tests/utils_tests/test_ipv6.py
+++ b/tests/utils_tests/test_ipv6.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
-from django.utils import unittest
+import unittest
+
from django.utils.ipv6 import is_valid_ipv6_address, clean_ipv6_address
class TestUtilsIPv6(unittest.TestCase):
diff --git a/tests/utils_tests/test_module_loading.py b/tests/utils_tests/test_module_loading.py
index 0a905ef2f1..5a43a927bf 100644
--- a/tests/utils_tests/test_module_loading.py
+++ b/tests/utils_tests/test_module_loading.py
@@ -1,10 +1,10 @@
+import imp
import os
import sys
-import imp
+import unittest
from zipimport import zipimporter
from django.core.exceptions import ImproperlyConfigured
-from django.utils import unittest
from django.utils.importlib import import_module
from django.utils.module_loading import import_by_path, module_has_submodule
from django.utils._os import upath
diff --git a/tests/utils_tests/test_os_utils.py b/tests/utils_tests/test_os_utils.py
index a205d67431..da54e93ac0 100644
--- a/tests/utils_tests/test_os_utils.py
+++ b/tests/utils_tests/test_os_utils.py
@@ -1,6 +1,6 @@
import os
+import unittest
-from django.utils import unittest
from django.utils._os import safe_join
diff --git a/tests/utils_tests/test_regex_helper.py b/tests/utils_tests/test_regex_helper.py
index 41f4a4f85d..055da89ee0 100644
--- a/tests/utils_tests/test_regex_helper.py
+++ b/tests/utils_tests/test_regex_helper.py
@@ -1,7 +1,8 @@
from __future__ import unicode_literals
+import unittest
+
from django.utils import regex_helper
-from django.utils import unittest
class NormalizeTests(unittest.TestCase):
diff --git a/tests/utils_tests/test_simplelazyobject.py b/tests/utils_tests/test_simplelazyobject.py
index 4c01bd3adf..7b681d9290 100644
--- a/tests/utils_tests/test_simplelazyobject.py
+++ b/tests/utils_tests/test_simplelazyobject.py
@@ -3,9 +3,9 @@ from __future__ import unicode_literals
import copy
import pickle
import sys
+from unittest import TestCase
from django.utils import six
-from django.utils.unittest import TestCase
from django.utils.functional import SimpleLazyObject, empty
diff --git a/tests/utils_tests/test_termcolors.py b/tests/utils_tests/test_termcolors.py
index 8cc28009cd..3a74244c09 100644
--- a/tests/utils_tests/test_termcolors.py
+++ b/tests/utils_tests/test_termcolors.py
@@ -1,4 +1,5 @@
-from django.utils import unittest
+import unittest
+
from django.utils.termcolors import (parse_color_setting, PALETTES,
DEFAULT_PALETTE, LIGHT_PALETTE, DARK_PALETTE, NOCOLOR_PALETTE, colorize)
diff --git a/tests/utils_tests/test_timezone.py b/tests/utils_tests/test_timezone.py
index 650198e8ff..2a13c10d7c 100644
--- a/tests/utils_tests/test_timezone.py
+++ b/tests/utils_tests/test_timezone.py
@@ -1,10 +1,11 @@
import copy
import datetime
import pickle
+import unittest
+
from django.test.utils import override_settings
from django.utils import timezone
from django.utils.tzinfo import FixedOffset
-from django.utils import unittest
EAT = FixedOffset(180) # Africa/Nairobi
diff --git a/tests/utils_tests/test_tzinfo.py b/tests/utils_tests/test_tzinfo.py
index cec92652cd..1867743fef 100644
--- a/tests/utils_tests/test_tzinfo.py
+++ b/tests/utils_tests/test_tzinfo.py
@@ -3,8 +3,9 @@ import datetime
import os
import pickle
import time
+import unittest
+
from django.utils.tzinfo import FixedOffset, LocalTimezone
-from django.utils import unittest
class TzinfoTests(unittest.TestCase):
diff --git a/tests/validation/test_error_messages.py b/tests/validation/test_error_messages.py
index 63c033a750..aa01db6007 100644
--- a/tests/validation/test_error_messages.py
+++ b/tests/validation/test_error_messages.py
@@ -1,10 +1,11 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
+from unittest import TestCase
+
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import six
-from django.utils.unittest import TestCase
class ValidationMessagesTest(TestCase):
diff --git a/tests/validation/test_unique.py b/tests/validation/test_unique.py
index 038da16494..a481fcb1c4 100644
--- a/tests/validation/test_unique.py
+++ b/tests/validation/test_unique.py
@@ -1,10 +1,10 @@
from __future__ import absolute_import, unicode_literals
import datetime
+import unittest
from django.core.exceptions import ValidationError
from django.test import TestCase
-from django.utils import unittest
from .models import (CustomPKModel, UniqueTogetherModel, UniqueFieldsModel,
UniqueForDateModel, ModelToValidate, Post, FlexibleDatePost,
diff --git a/tests/validators/tests.py b/tests/validators/tests.py
index a1555d8e91..ec3e2dc8c1 100644
--- a/tests/validators/tests.py
+++ b/tests/validators/tests.py
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+from datetime import datetime, timedelta
import re
import types
-from datetime import datetime, timedelta
+from unittest import TestCase
from django.core.exceptions import ValidationError
from django.core.validators import *
from django.test.utils import str_prefix
-from django.utils.unittest import TestCase
NOW = datetime.now()
diff --git a/tests/version/tests.py b/tests/version/tests.py
index 64621a5cb6..a5d49fc450 100644
--- a/tests/version/tests.py
+++ b/tests/version/tests.py
@@ -1,8 +1,8 @@
import re
+from unittest import TestCase
from django import get_version
from django.utils import six
-from django.utils.unittest import TestCase
class VersionTests(TestCase):
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index f686eee0e0..bc77fc351a 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -8,6 +8,7 @@ import os
import shutil
import sys
from tempfile import NamedTemporaryFile, mkdtemp, mkstemp
+from unittest import skipIf
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
@@ -22,7 +23,6 @@ from .. import BrokenException, except_args
from ..views import (sensitive_view, non_sensitive_view, paranoid_view,
custom_exception_reporter_filter_view, sensitive_method_view,
sensitive_args_function_caller, sensitive_kwargs_function_caller)
-from django.utils.unittest import skipIf
@override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py
index b35b192fd0..c1852ee71f 100644
--- a/tests/view_tests/tests/test_i18n.py
+++ b/tests/view_tests/tests/test_i18n.py
@@ -4,12 +4,13 @@ from __future__ import absolute_import
import gettext
import os
from os import path
+import unittest
from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import LiveServerTestCase, TestCase
from django.test.utils import override_settings
-from django.utils import six, unittest
+from django.utils import six
from django.utils._os import upath
from django.utils.translation import override
from django.utils.text import javascript_quote
diff --git a/tests/wsgi/tests.py b/tests/wsgi/tests.py
index a66258d4eb..afd59a6e1f 100644
--- a/tests/wsgi/tests.py
+++ b/tests/wsgi/tests.py
@@ -1,5 +1,7 @@
from __future__ import unicode_literals
+import unittest
+
from django.core.exceptions import ImproperlyConfigured
from django.core.servers.basehttp import get_internal_wsgi_application
from django.core.signals import request_started
@@ -8,7 +10,7 @@ from django.db import close_old_connections
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
-from django.utils import six, unittest
+from django.utils import six
class WSGITest(TestCase):