Skip to content

Commit

Permalink
Merge pull request #22 from beproud/dj32
Browse files Browse the repository at this point in the history
Django3.2対応
  • Loading branch information
imaxyz committed Aug 16, 2022
2 parents e7aa0a4 + a5341c4 commit 4ccb803
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 41 deletions.
10 changes: 9 additions & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
ChangeLog
=========

Release 0.41 (Unreleased)
Release 0.42 (Unreleased)
=========================

Release 0.41 (2022-08-16)
=========================

- Fixed: django.conf.urls.url() is deprecated. Also, path() is more concise than re_path(). Change to use path().
- Fixed: django.shortcuts.render_to_response() is deprecated, change to use django.shortcuts.render().
- Fixed: django.utils.translation.ugettext_lazy() is deprecated, change to use django.utils.translation.gettext_lazy().
- Fixed: django.utils.encoding.force_text() is deprecated, change to use django.utils.encoding.force_str().
- Fixed: Deprecated assertEquals() in unittest used by Django, changed to assertEqual().

Release 0.40 (2021-12-28)
=========================
Expand Down
2 changes: 1 addition & 1 deletion newauth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION_INFO = (0, 40)
VERSION_INFO = (0, 41)
VERSION = '.'.join(map(str, VERSION_INFO))
8 changes: 4 additions & 4 deletions newauth/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django import forms
from django.conf import settings
from django.conf.urls import url
from django.urls import path
from django.contrib import admin
from django.http import Http404
from django.shortcuts import redirect
Expand All @@ -15,7 +15,7 @@
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
from django.shortcuts import render_to_response, get_object_or_404
from django.shortcuts import render, get_object_or_404
from django.utils.decorators import method_decorator
from django.template import RequestContext
from django.db.transaction import atomic
Expand Down Expand Up @@ -126,7 +126,7 @@ def get_form(self, request, obj=None, **kwargs):

def get_urls(self):
return [
url(r'^(.+)/password/$', self.admin_site.admin_view(self.user_change_password))
path('<id>/password/', self.admin_site.admin_view(self.user_change_password))
] + super(BasicUserAdmin, self).get_urls()

@method_decorator(sensitive_post_parameters())
Expand Down Expand Up @@ -170,7 +170,7 @@ def user_change_password(self, request, id):
fieldsets = [(None, {'fields': form.base_fields.keys()})]
adminForm = AdminForm(form, fieldsets, {})

return render_to_response(self.change_user_password_template or 'admin/newauth/basicuser/change_password.html', {
return render(request, self.change_user_password_template or 'admin/newauth/basicuser/change_password.html', {
'title': _('Change password: %s') % escape(str(user)),
'adminForm': adminForm,
'form': form,
Expand Down
6 changes: 3 additions & 3 deletions newauth/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.utils.encoding import smart_str
from django.utils.module_loading import import_string
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.conf import settings

from newauth.signals import (
Expand Down Expand Up @@ -74,8 +74,8 @@ def get_display_name(self):
public pages. This method should return
a unicode object.
"""
from django.utils.encoding import force_text
return force_text(self.pk)
from django.utils.encoding import force_str
return force_str(self.pk)
get_display_name.short_description = _('display name')

def get_real_name(self):
Expand Down
2 changes: 1 addition & 1 deletion newauth/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:coding=utf-8:

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django import forms

from newauth.api import authenticate
Expand Down
6 changes: 3 additions & 3 deletions newauth/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#:coding=utf-8:

from django.conf.urls import url
from django.urls import path

from newauth.views import login, logout


urlpatterns = [
url(r'^login/$', login, name='newauth_login'),
url(r'^logout/$', logout, name='newauth_logout'),
path('login/', login, name='newauth_login'),
path('logout/', logout, name='newauth_logout'),
]
2 changes: 1 addition & 1 deletion newauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import django
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.shortcuts import redirect, render
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.cache import never_cache
from django.views.decorators.debug import sensitive_post_parameters
Expand Down
12 changes: 6 additions & 6 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def test_logout_when_logged_in(self, user_logged_out_send, user_logged_in_send):

session_key = getattr(settings, 'NEWAUTH_SESSION_KEY', DEFAULT_SESSION_KEY)
session_data = request.session.get(session_key) or {}
self.assertEquals(session_data.get('uid'), 1)
self.assertEquals(session_data.get('bn'), 'testapp3')
self.assertEqual(session_data.get('uid'), 1)
self.assertEqual(session_data.get('bn'), 'testapp3')
self.assertTrue(request.auth_user.is_authenticated(), "%s is not authenticated" % request.auth_user)
self.assertTrue(isinstance(request.auth_user, TestUser3), 'User "%s" is wrong User class "%s"' % (
request.auth_user,
Expand All @@ -155,8 +155,8 @@ def test_logout_when_logged_in(self, user_logged_out_send, user_logged_in_send):
logout(request)

session_data = request.session.get(session_key) or {}
self.assertEquals(session_data.get('uid'), None)
self.assertEquals(session_data.get('bn'), None)
self.assertEqual(session_data.get('uid'), None)
self.assertEqual(session_data.get('bn'), None)
self.assertTrue(hasattr(request, 'auth_user'), 'Request has no auth_user attribute')
self.assertTrue(request.auth_user.is_anonymous(), 'User "%s" is authenticated' % request.auth_user)
self.assertTrue(isinstance(request.auth_user, TestAnonymousUser3), 'User "%s" is wrong AnonymousUser class "%s"' % (
Expand Down Expand Up @@ -189,8 +189,8 @@ def test_logout_when_logged_out(self, user_logged_out_send):

session_key = getattr(settings, 'NEWAUTH_SESSION_KEY', DEFAULT_SESSION_KEY)
session_data = request.session.get(session_key) or {}
self.assertEquals(session_data.get('uid'), None)
self.assertEquals(session_data.get('bn'), None)
self.assertEqual(session_data.get('uid'), None)
self.assertEqual(session_data.get('bn'), None)
self.assertTrue(hasattr(request, 'auth_user'), 'Request has no auth_user attribute')
self.assertTrue(request.auth_user.is_anonymous(), 'User "%s" is authenticated' % request.auth_user)
self.assertTrue(request.auth_user is old_anon_user, 'Anonymous User object was changed')
Expand Down
8 changes: 4 additions & 4 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class DecoratorTest(DjangoTestCase):

def test_login_required_failed(self):
response = self.client.get("/testapp/login_required/")
self.assertEquals(response.status_code, 302)
self.assertEquals(urlparse(response.get("Location", ""))[2], settings.LOGIN_URL)
self.assertEqual(response.status_code, 302)
self.assertEqual(urlparse(response.get("Location", ""))[2], settings.LOGIN_URL)

def test_login_required_testapp_failed(self):
response = self.client.get("/testapp/testapp_login_required/")
self.assertEquals(response.status_code, 302)
self.assertEquals(urlparse(response.get("Location", ""))[2], settings.LOGIN_URL)
self.assertEqual(response.status_code, 302)
self.assertEqual(urlparse(response.get("Location", ""))[2], settings.LOGIN_URL)
24 changes: 12 additions & 12 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_login(self):
'username': 'testuser',
'password': 'password',
})
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))

def test_login_override_redirect_url(self):
Expand All @@ -36,15 +36,15 @@ def test_login_override_redirect_url(self):
'username': 'testuser',
'password': 'password',
})
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(redirect_url))

def test_fail_login(self):
response = self.client.post('/account/login/', {
'username': 'testclient',
'password': 'bad_password',
})
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
self.assertFormError(response, 'form', None, "Please enter a correct username and password. Note that both fields may be case-sensitive.")

def test_fail_login_blank_fields(self):
Expand All @@ -53,15 +53,15 @@ def test_fail_login_blank_fields(self):
'username': '',
'password': 'password',
})
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
self.assertFormError(response, 'form', 'username', u'This field is required.')

# blank password
response = self.client.post('/account/login/', {
'username': 'testuser',
'password': '',
})
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
self.assertFormError(response, 'form', 'password', u'This field is required.')

def test_bad_redirect_space(self):
Expand All @@ -72,7 +72,7 @@ def test_bad_redirect_space(self):
'password': 'password',
REDIRECT_FIELD_NAME: bad_next_url,
})
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))

def test_bad_redirect_empty(self):
Expand All @@ -83,7 +83,7 @@ def test_bad_redirect_empty(self):
'password': 'password',
REDIRECT_FIELD_NAME: bad_next_url,
})
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))

def test_bad_redirect_domain(self):
Expand All @@ -95,7 +95,7 @@ def test_bad_redirect_domain(self):
'password': 'password',
REDIRECT_FIELD_NAME: bad_next_url,
}, HTTP_HOST='django-newauth.com')
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))

def test_bad_redirect_domain_other_case(self):
Expand All @@ -107,7 +107,7 @@ def test_bad_redirect_domain_other_case(self):
'password': 'password',
REDIRECT_FIELD_NAME: bad_next_url,
}, HTTP_HOST='example.com')
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))

def test_ok_redirect_domain(self):
Expand All @@ -120,7 +120,7 @@ def test_ok_redirect_domain(self):
'password': 'password',
REDIRECT_FIELD_NAME: next_url,
}, HTTP_HOST='django-newauth.com')
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(next_url))

def test_ok_redirect_domain_as_parameter(self):
Expand All @@ -132,7 +132,7 @@ def test_ok_redirect_domain_as_parameter(self):
'password': 'password',
REDIRECT_FIELD_NAME: ok_url,
}, HTTP_HOST='django-newauth.com')
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith('/some/url?param=http://example.com/'))

def test_ok_redirect(self):
Expand All @@ -143,7 +143,7 @@ def test_ok_redirect(self):
'password': 'password',
REDIRECT_FIELD_NAME: ok_url,
})
self.assertEquals(response.status_code, 302)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['Location'].endswith(ok_url))


Expand Down
9 changes: 4 additions & 5 deletions tests/testapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#:coding=utf-8:
from django.conf.urls import url, include
from django.urls import path, include
from django.http import HttpResponse

from newauth.decorators import login_required


Expand All @@ -10,7 +9,7 @@ def testview(request):


urlpatterns = [
url(r'^account/', include('newauth.urls')),
url(r'^testapp/login_required/', login_required(testview)),
url(r'^testapp/testapp_login_required', login_required(["testapp"])(testview)),
path('account/', include('newauth.urls')),
path('testapp/login_required/', login_required(testview)),
path('testapp/testapp_login_required/', login_required(["testapp"])(testview)),
]

0 comments on commit 4ccb803

Please sign in to comment.