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

Add Compatibility for django-allauth v0.55.2 #539

Merged
merged 6 commits into from
Sep 8, 2023
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
10 changes: 5 additions & 5 deletions dj_rest_auth/registration/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from allauth.account.adapter import get_adapter
from allauth.account.utils import setup_user_email
from allauth.socialaccount.helpers import complete_social_login
from allauth.socialaccount.models import SocialAccount
from allauth.socialaccount.models import SocialAccount, EmailAddress
from allauth.socialaccount.providers.base import AuthProcess
from allauth.utils import email_address_exists, get_username_max_length
from allauth.utils import get_username_max_length
except ImportError:
raise ImportError('allauth needs to be added to INSTALLED_APPS.')

Expand Down Expand Up @@ -91,7 +91,7 @@ def validate(self, attrs):
raise serializers.ValidationError(_('Define adapter_class in view'))

adapter = adapter_class(request)
app = adapter.get_provider().get_app(request)
app = adapter.get_provider().app

# More info on code vs access_token
# http://stackoverflow.com/questions/8666316/facebook-oauth-2-0-code-and-token
Expand Down Expand Up @@ -232,7 +232,7 @@ def validate_username(self, username):
def validate_email(self, email):
email = get_adapter().clean_email(email)
if allauth_account_settings.UNIQUE_EMAIL:
if email and email_address_exists(email):
if email and EmailAddress.objects.is_verified(email):
raise serializers.ValidationError(
_('A user is already registered with this e-mail address.'),
)
Expand Down Expand Up @@ -267,7 +267,7 @@ def save(self, request):
except DjangoValidationError as exc:
raise serializers.ValidationError(
detail=serializers.as_serializer_error(exc)
)
)
user.save()
self.custom_signup(request, user)
setup_user_email(request, user, [])
Expand Down
6 changes: 3 additions & 3 deletions dj_rest_auth/social_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def validate(self, attrs):
raise serializers.ValidationError('Define adapter_class in view')

adapter = adapter_class(request)
app = adapter.get_provider().get_app(request)
app = adapter.get_provider().app

access_token = attrs.get('access_token')
token_secret = attrs.get('token_secret')
Expand Down Expand Up @@ -126,7 +126,7 @@ def validate(self, attrs):
raise serializers.ValidationError('Define adapter_class in view')

adapter = adapter_class(request)
app = adapter.get_provider().get_app(request)
app = adapter.get_provider().app

access_token = attrs.get('accessToken')

Expand All @@ -144,4 +144,4 @@ def validate(self, attrs):
login.save(request, connect=True)
attrs['user'] = login.account.user

return attrs
return attrs
2 changes: 1 addition & 1 deletion dj_rest_auth/tests/requirements.pip
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coveralls==1.11.1
django-allauth==0.54.0
django-allauth==0.55.2
djangorestframework-simplejwt==4.6.0
flake8==3.8.4
responses==0.12.1
Expand Down
5 changes: 2 additions & 3 deletions dj_rest_auth/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from dj_rest_auth.serializers import PasswordChangeSerializer, UserDetailsSerializer
from dj_rest_auth.registration.serializers import SocialLoginSerializer
from dj_rest_auth.registration.views import SocialLoginView
from allauth.socialaccount.models import SocialApp


User = get_user_model()
Expand Down Expand Up @@ -130,7 +129,7 @@ def setUpTestData(cls):
social_app.sites.add(site)

cls.fb_response = {
"id": 56527456,
"id": "56527456",
"first_name": "Alice",
"last_name": "Test",
"name": "Alcie Test",
Expand All @@ -155,7 +154,7 @@ def test_immediate_http_response_error(self, mock_pre_social_login, mock_fb_comp
dummy_view = SocialLoginView()
dummy_view.adapter_class = FacebookOAuth2Adapter
mock_pre_social_login.side_effect = lambda request, social_login: exec('raise ImmediateHttpResponse(HttpResponseBadRequest("Bad Request"))')
mock_fb_complete_login.return_value = FacebookProvider(self.request).sociallogin_from_response(self.request, self.fb_response)
mock_fb_complete_login.return_value = FacebookProvider(self.request, app=FacebookOAuth2Adapter).sociallogin_from_response(self.request, self.fb_response)
serializer = SocialLoginSerializer(data=self.request_data, context={'request': self.request, 'view': dummy_view})
serializer.is_valid()
self.assertDictEqual(serializer.errors, self.HTTP_BAD_REQUEST_MESSAGE)
Expand Down
2 changes: 1 addition & 1 deletion dj_rest_auth/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_csrf_cookie(request):
r'^socialaccounts/(?P<pk>\d+)/disconnect/$', SocialAccountDisconnectView.as_view(),
name='social_account_disconnect',
),
re_path(r'^accounts/', include('allauth.socialaccount.urls')),
re_path(r'^accounts/', include('allauth.urls')),
re_path(r'^getcsrf/', get_csrf_cookie, name='getcsrf'),
re_path('^token/verify/', TokenVerifyView.as_view(), name='token_verify'),
re_path('^token/refresh/', get_refresh_view().as_view(), name='token_refresh'),
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
keywords='django rest auth registration rest-framework django-registration api',
zip_safe=False,
install_requires=[
'Django>=2.0',
'djangorestframework>=3.7.0',
'Django>=3.2',
'djangorestframework>=3.13.0',
],
extras_require={
'with_social': ['django-allauth>=0.40.0,<0.55.0'],
'with_social': ['django-allauth>=0.55.0,<0.56.0'],
},
tests_require=[
'coveralls>=1.11.1',
'django-allauth==0.54.0',
'django-allauth==0.55.2',
'djangorestframework-simplejwt==4.6.0',
'responses==0.12.1',
'unittest-xml-reporting==3.0.4',
],
test_suite='runtests.runtests',
include_package_data=True,
python_requires='>=3.5',
python_requires='>=3.6',
classifiers=[
'Framework :: Django',
'Intended Audience :: Developers',
Expand Down
8 changes: 3 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

# Running this tox will test against all supported version
# Running this tox will test against all supported version
# combinations of python and django as described at the following
# https://docs.djangoproject.com/en/3.0/faq/install/#what-python-version-can-i-use-with-django
# https://endoflife.date/django
[tox]
skipsdist = true
envlist =
python{3.5,3.6,3.7,3.8,3.9}-django2
python{3.6,3.7,3.8,3.9}-django3
python{3.8,3.9,3.10,3.11}-django4

Expand All @@ -19,9 +18,8 @@ commands =
python ./runtests.py
deps =
-rdj_rest_auth/tests/requirements.pip
django2: Django>=2.2,<2.3
django3: Django>=3.1.3
django4: Django>=4.0,<4.1
django3: Django>=3.2
django4: Django>=4.0,<4.3

# Configuration for coverage and flake8 is being set in `./setup.cfg`
[testenv:coverage]
Expand Down