diff --git a/.flake8 b/.flake8 deleted file mode 100644 index ef305e59..00000000 --- a/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b9fbcfab..a0bcf601 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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' @@ -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: | diff --git a/README.md b/README.md index 554a0a39..838d112a 100644 --- a/README.md +++ b/README.md @@ -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/), diff --git a/demo/requirements.pip b/demo/requirements.pip deleted file mode 100644 index 038b616e..00000000 --- a/demo/requirements.pip +++ /dev/null @@ -1,8 +0,0 @@ -django>=2.2,<4.0 -dj-rest-auth @ git+https://github.com/iMerica/dj-rest-auth.git@master -djangorestframework>=3.11.0 -djangorestframework-simplejwt==4.7.1 -django-allauth>=0.24.1 -drf-yasg==1.21.4 -django-cors-headers==3.2.1 -coreapi==2.3.3 diff --git a/demo/requirements.txt b/demo/requirements.txt new file mode 100644 index 00000000..f03b1bf0 --- /dev/null +++ b/demo/requirements.txt @@ -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 ./.. diff --git a/dj_rest_auth/tests/requirements.pip b/dj_rest_auth/tests/requirements.txt similarity index 66% rename from dj_rest_auth/tests/requirements.pip rename to dj_rest_auth/tests/requirements.txt index 89970b18..3b6f6e98 100644 --- a/dj_rest_auth/tests/requirements.pip +++ b/dj_rest_auth/tests/requirements.txt @@ -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 diff --git a/dj_rest_auth/tests/test_api.py b/dj_rest_auth/tests/test_api.py index 62bd9092..520050dc 100644 --- a/dj_rest_auth/tests/test_api.py +++ b/dj_rest_auth/tests/test_api.py @@ -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 @@ -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' diff --git a/dj_rest_auth/tests/test_serializers.py b/dj_rest_auth/tests/test_serializers.py index 74f9281c..8c3fa140 100644 --- a/dj_rest_auth/tests/test_serializers.py +++ b/dj_rest_auth/tests/test_serializers.py @@ -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 @@ -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 diff --git a/dj_rest_auth/tests/test_social.py b/dj_rest_auth/tests/test_social.py index 492b7b01..de721ead 100644 --- a/dj_rest_auth/tests/test_social.py +++ b/dj_rest_auth/tests/test_social.py @@ -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') diff --git a/docs/demo.rst b/docs/demo.rst index c44b4514..5c35ba93 100644 --- a/docs/demo.rst +++ b/docs/demo.rst @@ -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 diff --git a/setup.cfg b/setup.cfg index 8d915a7a..07562395 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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__.: diff --git a/setup.py b/setup.py index b7f2d706..89684390 100644 --- a/setup.py +++ b/setup.py @@ -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, diff --git a/tox.ini b/tox.ini index 4e295737..ebf2bf78 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ [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 = @@ -18,13 +18,14 @@ python = 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` @@ -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