summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2017-01-11 23:17:25 +0100
committerClaude Paroz <claude@2xlibre.net>2017-01-20 08:44:31 +0100
commitdc8834cad41aa407f402dc54788df3cd37ab3e22 (patch)
treef44864ba7a64c614f00a3d2ad8548ce479e59e1e /tests
parentbf1c9570270b46e9e92b256fb9be394258029bbf (diff)
Refs #23919 -- Removed unneeded force_str calls
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_scripts/tests.py2
-rw-r--r--tests/admin_utils/tests.py6
-rw-r--r--tests/auth_tests/test_management.py3
-rw-r--r--tests/contenttypes_tests/tests.py4
-rw-r--r--tests/dbshell/test_postgresql_psycopg2.py30
-rw-r--r--tests/file_uploads/views.py6
-rw-r--r--tests/generic_views/test_list.py3
-rw-r--r--tests/handlers/tests.py6
-rw-r--r--tests/httpwrappers/tests.py10
-rw-r--r--tests/middleware/tests.py3
-rw-r--r--tests/migrations/test_writer.py3
-rw-r--r--tests/or_lookups/tests.py5
-rw-r--r--tests/requests/tests.py3
-rw-r--r--tests/signing/tests.py3
14 files changed, 27 insertions, 60 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 868d04196f..50e034e03e 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -1397,7 +1397,7 @@ class ManageRunserverEmptyAllowedHosts(AdminScriptTestCase):
class ManageTestserver(AdminScriptTestCase):
from django.core.management.commands.testserver import Command as TestserverCommand
- @mock.patch.object(TestserverCommand, 'handle')
+ @mock.patch.object(TestserverCommand, 'handle', return_value='')
def test_testserver_handle_params(self, mock_handle):
out = StringIO()
call_command('testserver', 'blah.json', stdout=out)
diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py
index 1c14615e71..09136ea72a 100644
--- a/tests/admin_utils/tests.py
+++ b/tests/admin_utils/tests.py
@@ -218,12 +218,8 @@ class UtilsTests(SimpleTestCase):
)
self.assertEqual(
- label_for_field("__unicode__", Article),
- "article"
- )
- self.assertEqual(
label_for_field("__str__", Article),
- str("article")
+ "article"
)
with self.assertRaises(AttributeError):
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index 12d029ffcd..00864be47a 100644
--- a/tests/auth_tests/test_management.py
+++ b/tests/auth_tests/test_management.py
@@ -15,7 +15,6 @@ from django.core.management import call_command
from django.core.management.base import CommandError
from django.db import migrations
from django.test import TestCase, mock, override_settings
-from django.utils.encoding import force_str
from django.utils.translation import ugettext_lazy as _
from .models import (
@@ -44,7 +43,7 @@ def mock_inputs(inputs):
assert str('__proxy__') not in prompt
response = ''
for key, val in inputs.items():
- if force_str(key) in prompt.lower():
+ if key in prompt.lower():
response = val
break
return response
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index 0ae2ddbb64..7fedcb7abd 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -15,7 +15,7 @@ from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings,
)
from django.test.utils import captured_stdout, isolate_apps
-from django.utils.encoding import force_str, force_text
+from django.utils.encoding import force_text
from .models import (
Article, Author, ModelWithNullFKToSite, Post, SchemeIncludedURL,
@@ -144,7 +144,7 @@ class GenericForeignKeyTests(SimpleTestCase):
class Model(models.Model):
field = GenericForeignKey()
expected = "contenttypes_tests.Model.field"
- actual = force_str(Model.field)
+ actual = force_text(Model.field)
self.assertEqual(expected, actual)
def test_missing_content_type_field(self):
diff --git a/tests/dbshell/test_postgresql_psycopg2.py b/tests/dbshell/test_postgresql_psycopg2.py
index 755464b3bb..f0848ac7b8 100644
--- a/tests/dbshell/test_postgresql_psycopg2.py
+++ b/tests/dbshell/test_postgresql_psycopg2.py
@@ -1,9 +1,7 @@
-import locale
import os
from django.db.backends.postgresql.client import DatabaseClient
from django.test import SimpleTestCase, mock
-from django.utils.encoding import force_bytes, force_str
class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
@@ -13,13 +11,12 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
That function invokes the runshell command, while mocking
subprocess.call. It returns a 2-tuple with:
- The command line list
- - The binary content of file pointed by environment PGPASSFILE, or
- None.
+ - The content of the file pointed by environment PGPASSFILE, or None.
"""
def _mock_subprocess_call(*args):
self.subprocess_args = list(*args)
if 'PGPASSFILE' in os.environ:
- with open(os.environ['PGPASSFILE'], 'rb') as f:
+ with open(os.environ['PGPASSFILE'], 'r') as f:
self.pgpass = f.read().strip() # ignore line endings
else:
self.pgpass = None
@@ -40,7 +37,7 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
'port': '444',
}), (
['psql', '-U', 'someuser', '-h', 'somehost', '-p', '444', 'dbname'],
- b'somehost:444:dbname:someuser:somepassword',
+ 'somehost:444:dbname:someuser:somepassword',
)
)
@@ -67,7 +64,7 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
'port': '444',
}), (
['psql', '-U', 'some:user', '-h', '::1', '-p', '444', 'dbname'],
- b'\\:\\:1:444:dbname:some\\:user:some\\:password',
+ '\\:\\:1:444:dbname:some\\:user:some\\:password',
)
)
@@ -81,30 +78,23 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
'port': '444',
}), (
['psql', '-U', 'some\\user', '-h', 'somehost', '-p', '444', 'dbname'],
- b'somehost:444:dbname:some\\\\user:some\\\\password',
+ 'somehost:444:dbname:some\\\\user:some\\\\password',
)
)
def test_accent(self):
- # The pgpass temporary file needs to be encoded using the system locale.
- encoding = locale.getpreferredencoding()
username = 'rôle'
password = 'sésame'
- username_str = force_str(username, encoding)
- password_str = force_str(password, encoding)
- pgpass_bytes = force_bytes(
- 'somehost:444:dbname:%s:%s' % (username, password),
- encoding=encoding,
- )
+ pgpass_string = 'somehost:444:dbname:%s:%s' % (username, password)
self.assertEqual(
self._run_it({
'database': 'dbname',
- 'user': username_str,
- 'password': password_str,
+ 'user': username,
+ 'password': password,
'host': 'somehost',
'port': '444',
}), (
- ['psql', '-U', username_str, '-h', 'somehost', '-p', '444', 'dbname'],
- pgpass_bytes,
+ ['psql', '-U', username, '-h', 'somehost', '-p', '444', 'dbname'],
+ pgpass_string,
)
)
diff --git a/tests/file_uploads/views.py b/tests/file_uploads/views.py
index 789cc2a365..3eca47fe35 100644
--- a/tests/file_uploads/views.py
+++ b/tests/file_uploads/views.py
@@ -4,7 +4,7 @@ import os
from django.core.files.uploadedfile import UploadedFile
from django.http import HttpResponse, HttpResponseServerError
-from django.utils.encoding import force_bytes, force_str
+from django.utils.encoding import force_bytes, force_text
from .models import FileModel
from .tests import UNICODE_FILENAME, UPLOAD_TO
@@ -152,9 +152,7 @@ def file_upload_content_type_extra(request):
"""
params = {}
for file_name, uploadedfile in request.FILES.items():
- params[file_name] = {
- k: force_str(v) for k, v in uploadedfile.content_type_extra.items()
- }
+ params[file_name] = {k: force_text(v) for k, v in uploadedfile.content_type_extra.items()}
return HttpResponse(json.dumps(params))
diff --git a/tests/generic_views/test_list.py b/tests/generic_views/test_list.py
index d5851d4ff8..429d46f50c 100644
--- a/tests/generic_views/test_list.py
+++ b/tests/generic_views/test_list.py
@@ -2,7 +2,6 @@ import datetime
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, override_settings
-from django.utils.encoding import force_str
from django.views.generic.base import View
from .models import Artist, Author, Book, Page
@@ -235,7 +234,7 @@ class ListViewTests(TestCase):
self._make_authors(1)
res = self.client.get('/list/authors/paginated/2/')
self.assertEqual(res.status_code, 404)
- self.assertEqual(force_str(res.context.get('reason')), "Invalid page (2): That page contains no results")
+ self.assertEqual(res.context.get('reason'), "Invalid page (2): That page contains no results")
def _make_authors(self, n):
Author.objects.all().delete()
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index d7cfaadf62..ffb8a1f145 100644
--- a/tests/handlers/tests.py
+++ b/tests/handlers/tests.py
@@ -7,7 +7,6 @@ from django.db import close_old_connections, connection
from django.test import (
RequestFactory, SimpleTestCase, TransactionTestCase, override_settings,
)
-from django.utils.encoding import force_str
try:
from http import HTTPStatus
@@ -65,10 +64,7 @@ class HandlerTests(SimpleTestCase):
raw_cookie = 'want="café"'.encode('utf-8').decode('iso-8859-1')
environ['HTTP_COOKIE'] = raw_cookie
request = WSGIRequest(environ)
- # If would be nicer if request.COOKIES returned unicode values.
- # However the current cookie parser doesn't do this and fixing it is
- # much more work than fixing #20557. Feel free to remove force_str()!
- self.assertEqual(request.COOKIES['want'], force_str("café"))
+ self.assertEqual(request.COOKIES['want'], "café")
def test_invalid_unicode_cookie(self):
"""
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index a4ea614175..fe2ad1a216 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -17,7 +17,6 @@ from django.http import (
)
from django.test import SimpleTestCase
from django.utils._os import upath
-from django.utils.encoding import force_str
from django.utils.functional import lazystr
@@ -294,13 +293,8 @@ class HttpResponseTests(unittest.TestCase):
self.assertIsInstance(r['key'], str)
self.assertIn(b'test', r.serialize_headers())
- # Latin-1 unicode or bytes values are also converted to native strings.
+ # Non-ASCII values are serialized to Latin-1.
r['key'] = 'café'
- self.assertEqual(r['key'], force_str('café', 'latin-1'))
- self.assertIsInstance(r['key'], str)
- r['key'] = 'café'.encode('latin-1')
- self.assertEqual(r['key'], force_str('café', 'latin-1'))
- self.assertIsInstance(r['key'], str)
self.assertIn('café'.encode('latin-1'), r.serialize_headers())
# Other unicode values are MIME-encoded (there's no way to pass them as bytes).
@@ -759,7 +753,7 @@ class CookieTests(unittest.TestCase):
# More characters the spec forbids.
self.assertEqual(parse_cookie('a b,c<>@:/[]?{}=d " =e,f g'), {'a b,c<>@:/[]?{}': 'd " =e,f g'})
# Unicode characters. The spec only allows ASCII.
- self.assertEqual(parse_cookie('saint=André Bessette'), {'saint': force_str('André Bessette')})
+ self.assertEqual(parse_cookie('saint=André Bessette'), {'saint': 'André Bessette'})
# Browsers don't send extra whitespace or semicolons in Cookie headers,
# but parse_cookie() should parse whitespace the same way
# document.cookie parses whitespace.
diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py
index 8749a9ee50..bd2ba89848 100644
--- a/tests/middleware/tests.py
+++ b/tests/middleware/tests.py
@@ -22,7 +22,6 @@ from django.test import (
RequestFactory, SimpleTestCase, ignore_warnings, override_settings,
)
from django.utils.deprecation import RemovedInDjango21Warning
-from django.utils.encoding import force_str
int2byte = struct.Struct(">B").pack
@@ -350,7 +349,7 @@ class CommonMiddlewareTest(SimpleTestCase):
def test_non_ascii_query_string_does_not_crash(self):
"""Regression test for #15152"""
request = self.rf.get('/slash')
- request.META['QUERY_STRING'] = force_str('drink=café')
+ request.META['QUERY_STRING'] = 'drink=café'
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
index a51842e02d..46126bb760 100644
--- a/tests/migrations/test_writer.py
+++ b/tests/migrations/test_writer.py
@@ -24,7 +24,6 @@ from django.test import SimpleTestCase, ignore_warnings, mock
from django.utils import datetime_safe
from django.utils._os import upath
from django.utils.deconstruct import deconstructible
-from django.utils.encoding import force_str
from django.utils.functional import SimpleLazyObject
from django.utils.timezone import FixedOffset, get_default_timezone, utc
from django.utils.translation import ugettext_lazy as _
@@ -170,7 +169,7 @@ class WriterTests(SimpleTestCase):
def safe_exec(self, string, value=None):
d = {}
try:
- exec(force_str(string), globals(), d)
+ exec(string, globals(), d)
except Exception as e:
if value:
self.fail("Could not exec %r (from value %r): %s" % (string.strip(), value, e))
diff --git a/tests/or_lookups/tests.py b/tests/or_lookups/tests.py
index dd93ed7efc..fd4cc3369b 100644
--- a/tests/or_lookups/tests.py
+++ b/tests/or_lookups/tests.py
@@ -3,7 +3,6 @@ from operator import attrgetter
from django.db.models import Q
from django.test import TestCase
-from django.utils.encoding import force_str
from .models import Article
@@ -124,9 +123,9 @@ class OrLookupsTests(TestCase):
def test_q_repr(self):
or_expr = Q(baz=Article(headline="Foö"))
- self.assertEqual(repr(or_expr), force_str("<Q: (AND: ('baz', <Article: Foö>))>"))
+ self.assertEqual(repr(or_expr), "<Q: (AND: ('baz', <Article: Foö>))>")
negated_or = ~Q(baz=Article(headline="Foö"))
- self.assertEqual(repr(negated_or), force_str("<Q: (NOT (AND: ('baz', <Article: Foö>)))>"))
+ self.assertEqual(repr(negated_or), "<Q: (NOT (AND: ('baz', <Article: Foö>)))>")
def test_q_negated(self):
# Q objects can be negated
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index 54fe797728..0dcaebbca5 100644
--- a/tests/requests/tests.py
+++ b/tests/requests/tests.py
@@ -14,7 +14,6 @@ from django.http.request import split_domain_port
from django.test import RequestFactory, SimpleTestCase, override_settings
from django.test.client import FakePayload
from django.test.utils import freeze_time, str_prefix
-from django.utils.encoding import force_str
from django.utils.http import cookie_date, urlencode
from django.utils.timezone import utc
@@ -270,7 +269,7 @@ class RequestsTests(SimpleTestCase):
response = HttpResponse()
cookie_value = '清風'
response.set_cookie('test', cookie_value)
- self.assertEqual(force_str(cookie_value), response.cookies['test'].value)
+ self.assertEqual(cookie_value, response.cookies['test'].value)
def test_limited_stream(self):
# Read all of a limited stream
diff --git a/tests/signing/tests.py b/tests/signing/tests.py
index bc838d015f..a55457efdd 100644
--- a/tests/signing/tests.py
+++ b/tests/signing/tests.py
@@ -3,7 +3,6 @@ import datetime
from django.core import signing
from django.test import SimpleTestCase
from django.test.utils import freeze_time
-from django.utils.encoding import force_str
class TestSigner(SimpleTestCase):
@@ -47,7 +46,7 @@ class TestSigner(SimpleTestCase):
for example in examples:
signed = signer.sign(example)
self.assertIsInstance(signed, str)
- self.assertNotEqual(force_str(example), signed)
+ self.assertNotEqual(example, signed)
self.assertEqual(example, signer.unsign(signed))
def test_unsign_detects_tampering(self):