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-allauth v64 migration #655

Merged
merged 13 commits into from
Dec 1, 2024
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
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
pip install -r dj_rest_auth/tests/requirements.txt
- name: Lint
run: flake8 dj_rest_auth/ --append-config ./.flake8
run: flake8 dj_rest_auth/
build:
runs-on: ubuntu-latest
name: Build
needs: [lint]
needs: [ lint ]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -48,11 +48,11 @@ jobs:
test:
runs-on: ubuntu-20.04
name: Test Python ${{ matrix.python-version }} + Django ~= ${{ matrix.django-version }}
needs: [build]
needs: [ build ]
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
django-version: ['4.2', '5.0']
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
django-version: [ '4.2', '5.0' ]
exclude:
- python-version: '3.8'
django-version: '5.0'
Expand All @@ -67,7 +67,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r dj_rest_auth/tests/requirements.pip
pip install -r dj_rest_auth/tests/requirements.txt
pip install "Django~=${{ matrix.django-version }}.0"
- name: Run Tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ REST_AUTH = {

### Testing

Install required modules with `pip install -r dj_rest_auth/tests/requirements.pip`
Install required modules with `pip install -r dj_rest_auth/tests/requirements.txt`

To run the tests within a virtualenv, run `python runtests.py` from the repository directory.
The easiest way to run test coverage is with [`coverage`](https://pypi.org/project/coverage/),
Expand Down
8 changes: 0 additions & 8 deletions demo/requirements.pip

This file was deleted.

9 changes: 9 additions & 0 deletions demo/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
django>=5.0.0
djangorestframework>=3.11.0
djangorestframework-simplejwt==5.3.1
django-allauth[socialaccount]>=64.0.0
drf-yasg==1.21.7
django-cors-headers==4.4.0
coreapi==2.3.3
setuptools==75.1.0
-e ./..
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coveralls==1.11.1
django-allauth==0.61.1
django-allauth[socialaccount]>=64.0.0
djangorestframework-simplejwt>=5.3.1
flake8==3.8.4
flake8==7.1.1
responses==0.12.1
unittest-xml-reporting==3.2.0
32 changes: 1 addition & 31 deletions dj_rest_auth/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
try:
from django.urls import reverse
except ImportError: # pragma: no cover
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse # noqa

from jwt import decode as decode_jwt
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
Expand Down Expand Up @@ -527,36 +527,6 @@ def test_registration_with_jwt(self):
self._login()
self._logout()

@override_api_settings(SESSION_LOGIN=True)
@override_api_settings(TOKEN_MODEL=None)
def test_registration_with_session(self):
import sys
from importlib import reload
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.messages.middleware import MessageMiddleware
reload(sys.modules['dj_rest_auth.models'])
reload(sys.modules['dj_rest_auth.registration.views'])
from dj_rest_auth.registration.views import RegisterView

user_count = get_user_model().objects.all().count()

self.post(self.register_url, data={}, status_code=400)

factory = APIRequestFactory()
request = factory.post(self.register_url, self.REGISTRATION_DATA)

for middleware_class in (SessionMiddleware, MessageMiddleware):
middleware = middleware_class(lambda request: None)
middleware.process_request(request)

response = RegisterView.as_view()(request)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(response.data, None)
self.assertEqual(get_user_model().objects.all().count(), user_count + 1)

self._login(status.HTTP_204_NO_CONTENT)
self._logout()

def test_registration_with_invalid_password(self):
data = self.REGISTRATION_DATA.copy()
data['password2'] = 'foobar'
Expand Down
18 changes: 2 additions & 16 deletions dj_rest_auth/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@

from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from allauth.socialaccount.providers.facebook.views import FacebookProvider
from allauth.socialaccount.models import SocialApp
from allauth.core.exceptions import ImmediateHttpResponse
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.core.exceptions import ValidationError
from django.test import TestCase, modify_settings, override_settings
from django.contrib.sites.models import Site
from django.http import HttpResponseBadRequest
from rest_framework.exceptions import ErrorDetail
from rest_framework.test import APIRequestFactory, force_authenticate
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock

from dj_rest_auth.serializers import PasswordChangeSerializer, UserDetailsSerializer
from dj_rest_auth.registration.serializers import SocialLoginSerializer
Expand Down Expand Up @@ -142,23 +139,12 @@ def test_validate_no_view_submit(self):
serializer.is_valid()
self.assertDictEqual(serializer.errors, self.NO_VIEW_SUBMIT_ERROR)

def test_validate_no_adpapter_class_present(self):
def test_validate_no_adapter_class_present(self):
dummy_view = SocialLoginView()
serializer = SocialLoginSerializer(data=self.request_data, context={'request': self.request, 'view': dummy_view})
serializer.is_valid()
self.assertDictEqual(serializer.errors, self.NO_ADAPTER_CLASS_PRESENT)

@patch('allauth.socialaccount.providers.facebook.views.fb_complete_login')
@patch('allauth.socialaccount.adapter.DefaultSocialAccountAdapter.pre_social_login')
def test_immediate_http_response_error(self, mock_pre_social_login, mock_fb_complete_login):
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, 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)

def test_http_error(self):
dummy_view = SocialLoginView()
dummy_view.adapter_class = FacebookOAuth2Adapter
Expand Down
2 changes: 1 addition & 1 deletion dj_rest_auth/tests/test_social.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
try:
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse # noqa


@override_settings(ROOT_URLCONF='tests.urls')
Expand Down
2 changes: 1 addition & 1 deletion docs/demo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To run this locally follow the steps below.
cd /tmp
git clone https://github.com/iMerica/dj-rest-auth.git
cd dj-rest-auth/demo/
pip install -r requirements.pip
pip install -r requirements.txt
python manage.py migrate --settings=demo.settings --noinput
python manage.py runserver --settings=demo.settings

Expand Down
15 changes: 9 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,29 @@ license_file = LICENSE
max-line-length = 120
exclude = docs/*,demo/*
ignore = F403

per-file-ignores =
dj_rest_auth/tests/test_serializers.py:E501,F401
dj_rest_auth/serializers.py:E501
dj_rest_auth/jwt_auth.py:E501

[coverage:run]
omit=*site-packages*,*distutils*,*migrations*
omit = *site-packages*,*distutils*,*migrations*

[coverage:report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
keywords='django rest auth registration rest-framework django-registration api',
zip_safe=False,
install_requires=[
'Django>=3.2,<6.0',
'Django>=4.2,<6.0',
'djangorestframework>=3.13.0',
],
extras_require={
'with-social': ['django-allauth>=0.56.0,<0.62.0'],
'with-social': ['django-allauth[socialaccount]>=64.0.0'],
},
tests_require=[
'coveralls>=1.11.1',
'django-allauth>=0.57.0',
'djangorestframework-simplejwt==4.6.0',
'django-allauth>=64.0.0',
'djangorestframework-simplejwt==5.3.1',
'responses==0.12.1',
'unittest-xml-reporting==3.0.4',
'unittest-xml-reporting==3.2.0',
'flake8==7.1.1',
],
test_suite='runtests.runtests',
include_package_data=True,
Expand Down
14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
[tox]
skipsdist = true
envlist =
python{3.8,3.9,3.10,3.11}-django{4,5}
python{3.8,3.9,3.10,3.11,3.12}-django{4,5}

[gh-actions]
python =
3.8: python3.8-django4
3.9: python3.9-django4
3.10: python3.10-django4, python3.10-django5
3.11: python3.11-django4, python3.11-django5
3.12: python3.12-django4, python3.12-django5

[testenv]
commands =
python ./runtests.py
deps =
-rdj_rest_auth/tests/requirements.pip
django4: Django>=4.0,<5.0
-r dj_rest_auth/tests/requirements.txt
django4: Django>=4.2,<5.0
django5: Django>=5.0,<6.0

# Configuration for coverage and flake8 is being set in `./setup.cfg`
Expand All @@ -33,11 +34,10 @@ commands =
coverage run ./runtests.py
coverage report
deps =
-rdj_rest_auth/tests/requirements.pip
-r dj_rest_auth/tests/requirements.txt

[testenv:flake8]
changedir = {toxinidir}/dj_rest_auth
commands =
flake8 .
flake8 {toxinidir}/dj_rest_auth
deps =
flake8==3.8.4
flake8==7.1.1