Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 3.2 upgrade #28

Merged
merged 5 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ local_settings.py
.emacs*
env
env3
.idea
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django==2.2.15
Django==3.2.15
python-dateutil>=2.6.0
lxml
defusedxml
Expand All @@ -8,3 +8,4 @@ biplist
# Because the official 0.1.4 release (that added Py3 support) HAS NO FILES.
# mimeparse>=0.1.3
python-mimeparse>=0.1.4
six==1.16.0
2 changes: 1 addition & 1 deletion tastypie/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django import forms as djangoform
from django.utils import datetime_safe
from importlib import import_module
from django.utils import six
import six
from tastypie.bundle import Bundle
from tastypie.exceptions import ApiFieldError, NotFound
from tastypie.utils import dict_strip_unicode_keys, make_aware
Expand Down
2 changes: 1 addition & 1 deletion tastypie/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
standard_library.install_aliases()
from builtins import object
from django.conf import settings
from django.utils import six
import six

from tastypie.exceptions import BadRequest

Expand Down
2 changes: 1 addition & 1 deletion tastypie/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from django.http import HttpResponse, HttpResponseNotFound, Http404
from django.utils.cache import patch_cache_control, patch_vary_headers
from django.utils import six
import six

from tastypie.authentication import Authentication
from tastypie.authorization import ReadOnlyAuthorization
Expand Down
10 changes: 5 additions & 5 deletions tastypie/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import django
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import six
from django.utils.encoding import force_text, smart_bytes
import six
from django.utils.encoding import force_str, smart_bytes
from django.core.serializers import json as djangojson
import json

Expand Down Expand Up @@ -221,7 +221,7 @@ def deserialize(self, content, format='application/json'):
raise UnsupportedFormat("The format indicated '%s' had no available deserialization method. Please check your ``formats`` and ``content_types`` on your Serializer." % format)

if isinstance(content, six.binary_type):
content = force_text(content)
content = force_str(content)

deserialized = getattr(self, "from_%s" % desired_format)(content)
return deserialized
Expand Down Expand Up @@ -266,7 +266,7 @@ def to_simple(self, data, options):
elif data is None:
return None
else:
return force_text(data)
return force_str(data)

def to_etree(self, data, options=None, name=None, depth=0):
"""
Expand Down Expand Up @@ -326,7 +326,7 @@ def to_etree(self, data, options=None, name=None, depth=0):
if isinstance(simple_data, six.text_type):
element.text = simple_data
else:
element.text = force_text(simple_data)
element.text = force_str(simple_data)

return element

Expand Down
10 changes: 5 additions & 5 deletions tastypie/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf import settings
from django.test import TestCase
from django.test.client import FakePayload, Client
from django.utils.encoding import force_text
from django.utils.encoding import force_str

from tastypie.serializers import Serializer

Expand Down Expand Up @@ -460,7 +460,7 @@ def assertValidJSONResponse(self, resp):
"""
self.assertHttpOK(resp)
self.assertTrue(resp['Content-Type'].startswith('application/json'))
self.assertValidJSON(force_text(resp.content))
self.assertValidJSON(force_str(resp.content))

def assertValidXMLResponse(self, resp):
"""
Expand All @@ -473,7 +473,7 @@ def assertValidXMLResponse(self, resp):
"""
self.assertHttpOK(resp)
self.assertTrue(resp['Content-Type'].startswith('application/xml'))
self.assertValidXML(force_text(resp.content))
self.assertValidXML(force_str(resp.content))

def assertValidYAMLResponse(self, resp):
"""
Expand All @@ -486,7 +486,7 @@ def assertValidYAMLResponse(self, resp):
"""
self.assertHttpOK(resp)
self.assertTrue(resp['Content-Type'].startswith('text/yaml'))
self.assertValidYAML(force_text(resp.content))
self.assertValidYAML(force_str(resp.content))

def assertValidPlistResponse(self, resp):
"""
Expand All @@ -499,7 +499,7 @@ def assertValidPlistResponse(self, resp):
"""
self.assertHttpOK(resp)
self.assertTrue(resp['Content-Type'].startswith('application/x-plist'))
self.assertValidPlist(force_text(resp.content))
self.assertValidPlist(force_str(resp.content))

def deserialize(self, resp):
"""
Expand Down
2 changes: 1 addition & 1 deletion tastypie/utils/dict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import OrderedDict
from django.utils.encoding import smart_bytes
from django.utils import six
import six


def dict_strip_unicode_keys(uni_dict):
Expand Down
2 changes: 1 addition & 1 deletion tastypie/utils/http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.utils.six.moves.urllib.parse import urlparse
from six.moves.urllib.parse import urlparse


PROTOCOL_TO_PORT = {
Expand Down
2 changes: 1 addition & 1 deletion tastypie/utils/validate_jsonp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from unicodedata import category

from django.utils import six
import six

# ------------------------------------------------------------------------------
# javascript identifier unicode categories and "exceptional" chars
Expand Down
2 changes: 1 addition & 1 deletion tests/alphanumeric/tests/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from future import standard_library
standard_library.install_aliases()
import json
from django.utils import six
import six
from testcases import TestServerTestCase

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/basic/tests/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
standard_library.install_aliases()
from testcases import TestServerTestCase
import json
from django.utils import six
import six

try:
from .http.client import HTTPConnection
Expand Down
26 changes: 13 additions & 13 deletions tests/core/tests/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from django import forms
from django.http import HttpRequest, QueryDict, Http404
from django.test import TestCase
from django.utils.encoding import force_text
from django.utils import six
from django.utils.encoding import force_str
import six

from tastypie.authentication import BasicAuthentication
from tastypie.authorization import Authorization
Expand Down Expand Up @@ -761,13 +761,13 @@ def test_create_response(self):
data = {'hello': 'world'}
output = basic.create_response(request, data)
self.assertEqual(output.status_code, 200)
self.assertEqual(force_text(output.content), '{"hello": "world"}')
self.assertEqual(force_str(output.content), '{"hello": "world"}')

request.GET = {'format': 'xml'}
data = {'objects': [{'hello': 'world', 'abc': 123}], 'meta': {'page': 1}}
output = basic.create_response(request, data)
self.assertEqual(output.status_code, 200)
self.assertEqual(force_text(output.content), '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<response><meta type="hash"><page type="integer">1</page></meta><objects type="list"><object type="hash"><abc type="integer">123</abc><hello>world</hello></object></objects></response>')
self.assertEqual(force_str(output.content), '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<response><meta type="hash"><page type="integer">1</page></meta><objects type="list"><object type="hash"><abc type="integer">123</abc><hello>world</hello></object></objects></response>')

def test_mangled(self):
mangled = MangledBasicResource()
Expand All @@ -790,7 +790,7 @@ def test_get_list_with_use_in(self):
request.GET = {'format': 'json'}
request.method = 'GET'

basic_resource_list = json.loads(force_text(basic.get_list(request).content))['objects']
basic_resource_list = json.loads(force_str(basic.get_list(request).content))['objects']
self.assertEquals(basic_resource_list[0]['name'], 'Daniel')
self.assertEquals(basic_resource_list[0]['date_joined'], u'2010-03-30T09:00:00')

Expand Down Expand Up @@ -3001,7 +3001,7 @@ def test_jsonp_validation(self):
# Try again with ``wrap_view`` for sanity.
resp = resource.wrap_view('dispatch_detail')(request, pk=1)
self.assertEqual(resp.status_code, 400)
self.assertEqual(force_text(resp.content), '{"error": "JSONP callback name is invalid."}')
self.assertEqual(force_str(resp.content), '{"error": "JSONP callback name is invalid."}')
self.assertEqual(resp['content-type'], 'application/json')

# valid JSONP callback should work
Expand Down Expand Up @@ -3819,23 +3819,23 @@ def test_per_user_authorization(self):
self.assertEqual(punr._pre_limits, 0)
# Shouldn't hit the DB yet.
self.assertEqual(punr._post_limits, 0)
self.assertEqual(len(json.loads(force_text(punr.get_list(request=empty_request).content))['objects']), 4)
self.assertEqual(len(json.loads(force_str(punr.get_list(request=empty_request).content))['objects']), 4)

# Requests with an Anonymous user get no objects.
anony_bundle = punr.build_bundle(request=anony_request)
self.assertEqual(punr.authorized_read_list(punr.get_object_list(anony_request), anony_bundle).count(), 0)
self.assertEqual(len(json.loads(force_text(punr.get_list(request=anony_request).content))['objects']), 0)
self.assertEqual(len(json.loads(force_str(punr.get_list(request=anony_request).content))['objects']), 0)

# Requests with an authenticated user get all objects for that user
# that are active.
authed_bundle = punr.build_bundle(request=authed_request)
self.assertEqual(punr.authorized_read_list(punr.get_object_list(authed_request), authed_bundle).count(), 2)
self.assertEqual(len(json.loads(force_text(punr.get_list(request=authed_request).content))['objects']), 2)
self.assertEqual(len(json.loads(force_str(punr.get_list(request=authed_request).content))['objects']), 2)

# Demonstrate that a different user gets different objects.
authed_bundle_2 = punr.build_bundle(request=authed_request_2)
self.assertEqual(punr.authorized_read_list(punr.get_object_list(authed_request_2), authed_bundle_2).count(), 2)
self.assertEqual(len(json.loads(force_text(punr.get_list(request=authed_request_2).content))['objects']), 2)
self.assertEqual(len(json.loads(force_str(punr.get_list(request=authed_request_2).content))['objects']), 2)
self.assertEqual(list(punr.authorized_read_list(punr.get_object_list(authed_request), authed_bundle).values_list('id', flat=True)), [1, 2])
self.assertEqual(list(punr.authorized_read_list(punr.get_object_list(authed_request_2), authed_bundle_2).values_list('id', flat=True)), [4, 6])

Expand All @@ -3855,13 +3855,13 @@ def test_per_object_authorization(self):
# Since the objects weren't filtered, we hit everything.
self.assertEqual(ponr._post_limits, 6)

self.assertEqual(len(json.loads(force_text(ponr.get_list(request=empty_request).content))['objects']), 2)
self.assertEqual(len(json.loads(force_str(ponr.get_list(request=empty_request).content))['objects']), 2)
self.assertEqual(ponr._pre_limits, 0)
# Since the objects weren't filtered, we again hit everything.
self.assertEqual(ponr._post_limits, 6)

empty_request.GET['is_active'] = True
self.assertEqual(len(json.loads(force_text(ponr.get_list(request=empty_request).content))['objects']), 2)
self.assertEqual(len(json.loads(force_str(ponr.get_list(request=empty_request).content))['objects']), 2)
self.assertEqual(ponr._pre_limits, 0)
# This time, the objects were filtered, so we should only iterate over
# a (hopefully much smaller) subset.
Expand Down Expand Up @@ -3989,7 +3989,7 @@ def test_collection_name(self):
resource = AlternativeCollectionNameNoteResource()
request = HttpRequest()
response = resource.get_list(request)
response_data = json.loads(force_text(response.content))
response_data = json.loads(force_str(response.content))
self.assertTrue('alt_objects' in response_data)


Expand Down
4 changes: 2 additions & 2 deletions tests/core/tests/throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.core.cache import cache
from django.test import TestCase
from django.utils.encoding import force_text
from django.utils.encoding import force_str

from tastypie.models import ApiAccess
from tastypie.throttle import BaseThrottle, CacheThrottle, CacheDBThrottle
Expand Down Expand Up @@ -137,5 +137,5 @@ def test_throttling(self):
class ModelTestCase(TestCase):
def test_unicode(self):
access = ApiAccess(identifier="testing", accessed=0)
self.assertEqual(force_text(access), 'testing @ 0')
self.assertEqual(force_str(access), 'testing @ 0')