Skip to content

Commit

Permalink
Merge pull request #527 from dekoza/feature/poetry_support
Browse files Browse the repository at this point in the history
Drop support for old Python, Django and DRF versions
  • Loading branch information
dekoza committed Oct 4, 2020
2 parents 35e5a5e + d51f0cd commit a300b65
Show file tree
Hide file tree
Showing 34 changed files with 98 additions and 112 deletions.
37 changes: 20 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-json

- repo: https://github.com/asottile/seed-isort-config
rev: v1.9.2
hooks:
- id: seed-isort-config
- repo: https://github.com/pycqa/isort
rev: 5.5.2
hooks:
- id: isort

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
additional_dependencies: [toml]

- repo: https://github.com/ambv/black
rev: stable
hooks:
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
language_version: python3.7

- repo: https://github.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dist: xenial
language: python

python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ migrate:

runserver:
pipenv run python testproject/manage.py runserver

1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ djangorestframework-simplejwt = "*"
docutils = "==0.15"
wheel = "*"
six = "*"

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ List of projects related to Django, REST and authentication:
- `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_ (not maintained)

Please, keep in mind that while using custom authentication and TokenCreateSerializer
validation, there is a path that **ignores intentional return of None** from authenticate()
and try to find User using parameters. Probably, that will be changed in the future.
validation, there is a path that **ignores intentional return of None** from authenticate()
and try to find User using parameters. Probably, that will be changed in the future.
7 changes: 6 additions & 1 deletion djoser/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
__version__ = "2.0.5"
try:
import importlib.metadata as importlib_metadata
except ModuleNotFoundError:
import importlib_metadata

__version__ = importlib_metadata.version(__name__)
2 changes: 1 addition & 1 deletion djoser/locale/ka/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"PO-Revision-Date: 2019-01-29 14:25+0100\n"
"Last-Translator: Szymon Pyżalski <s.pyzalski@sunscrapers.com>\n"
"Language-Team: http://sunscrapers.com\n"
"Language: ka_GE\n"
"Language: ka_GE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
10 changes: 6 additions & 4 deletions djoser/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def __init__(self, *args, **kwargs):
def validate(self, attrs):
password = attrs.get("password")
params = {settings.LOGIN_FIELD: attrs.get(settings.LOGIN_FIELD)}
self.user = authenticate(request=self.context.get("request"), **params, password=password)
self.user = authenticate(
request=self.context.get("request"), **params, password=password
)
if not self.user:
self.user = User.objects.filter(**params).first()
if self.user and not self.user.check_password(password):
Expand All @@ -136,8 +138,8 @@ def get_user(self, is_active=True):
except User.DoesNotExist:
pass
if (
settings.PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND
or settings.USERNAME_RESET_SHOW_EMAIL_NOT_FOUND
settings.PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND
or settings.USERNAME_RESET_SHOW_EMAIL_NOT_FOUND
):
self.fail("email_not_found")

Expand Down Expand Up @@ -330,7 +332,7 @@ class UserDeleteSerializer(CurrentPasswordSerializer):
class SetUsernameSerializer(UsernameSerializer, CurrentPasswordSerializer):
class Meta:
model = User
fields = (settings.LOGIN_FIELD, 'current_password')
fields = (settings.LOGIN_FIELD, "current_password")


class SetUsernameRetypeSerializer(SetUsernameSerializer, UsernameRetypeSerializer):
Expand Down
5 changes: 1 addition & 4 deletions djoser/urls/authtoken.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try: # pragma: no cover
from django.urls import re_path
except ImportError:
from django.conf.urls import url as re_path
from django.urls import re_path

from djoser import views

Expand Down
6 changes: 1 addition & 5 deletions djoser/urls/jwt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
try: # pragma: no cover
from django.urls import re_path
except ImportError:
from django.conf.urls import url as re_path

from django.urls import re_path
from rest_framework_simplejwt import views

urlpatterns = [
Expand Down
1 change: 0 additions & 1 deletion djoser/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.contrib.auth import get_user_model, update_session_auth_hash
from django.contrib.auth.tokens import default_token_generator

from django.utils.timezone import now
from rest_framework import generics, status, views, viewsets
from rest_framework.decorators import action
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2 changes: 1 addition & 1 deletion docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ actually resetting the password it is possible to approach the problem like so:
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_200_OK, headers=headers)
return Response(serializer.data, status=status.HTTP_200_OK, headers=headers)
2 changes: 1 addition & 1 deletion docs/source/social_endpoints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The workflow should look like this:
to the endpoint with the ``code`` and ``state`` arguments. You should use
``application/x-www-form-urlencoded`` not JSON. The user should be now
authenticated in your application.

The list of providers is available at
`social backend docs <https://python-social-auth.readthedocs.io/en/latest/backends/index.html#social-backends>`_.
please follow the instructions provided there to configure your backend.
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[compile_catalog]
domain = django
directory = djoser/locale

[flake8]
max-line-length = 88
exclude = .tox,.git,docs,testproject/*
extend-ignore = E203, W503
4 changes: 3 additions & 1 deletion testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@
}


SIMPLE_JWT = {} # https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html#settings
SIMPLE_JWT = (
{}
) # https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html#settings
2 changes: 1 addition & 1 deletion testproject/testapp/tests/social/test_provider_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.sessions.middleware import SessionMiddleware
import six
from django.contrib.sessions.middleware import SessionMiddleware
from djet import assertions, restframework
from rest_framework import status
from social_core.exceptions import AuthException
Expand Down
2 changes: 1 addition & 1 deletion testproject/testapp/tests/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from testapp.tests.common import create_user

import djoser.signals
import djoser.utils
import djoser.views
from djoser.conf import settings as default_settings
from testapp.tests.common import create_user


class ActivationViewTest(
Expand Down
8 changes: 4 additions & 4 deletions testproject/testapp/tests/test_password_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from testapp.models import CustomUser
from testapp.tests.common import create_user, mock

from djoser.compat import get_user_email
from djoser.conf import settings as default_settings
from testapp.models import CustomUser
from testapp.tests.common import create_user, mock


class PasswordResetViewTest(
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_post_should_return_bad_request_if_user_does_not_exist(self):
@mock.patch("djoser.views.User", CustomUser)
@override_settings(AUTH_USER_MODEL="testapp.CustomUser")
def test_post_should_send_email_to_custom_user_with_password_reset_link(
self
self,
): # noqa
user = create_user(use_custom_data=True)
data = {"custom_email": get_user_email(user)}
Expand All @@ -94,7 +94,7 @@ def test_post_should_send_email_to_custom_user_with_password_reset_link(
DJOSER=dict(settings.DJOSER, **{"PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND": True}),
)
def test_post_should_return_bad_request_with_custom_email_field_if_user_does_not_exist(
self
self,
): # noqa
data = {"custom_email": "john@beatles.com"}

Expand Down
2 changes: 1 addition & 1 deletion testproject/testapp/tests/test_password_reset_confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from testapp.tests.common import create_user

import djoser.utils
import djoser.views
from djoser.conf import settings as default_settings
from testapp.tests.common import create_user


class PasswordResetConfirmViewTest(
Expand Down
4 changes: 2 additions & 2 deletions testproject/testapp/tests/test_resend_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase

from djoser.compat import get_user_email
from testapp.models import CustomUser
from testapp.tests.common import create_user, mock

from djoser.compat import get_user_email


class TestResendActivationEmail(
APITestCase, assertions.EmailAssertionsMixin, assertions.StatusCodeAssertionsMixin
Expand Down
8 changes: 4 additions & 4 deletions testproject/testapp/tests/test_reset_username.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from testapp.models import CustomUser
from testapp.tests.common import create_user, mock

from djoser.compat import get_user_email
from djoser.conf import settings as default_settings
from testapp.models import CustomUser
from testapp.tests.common import create_user, mock

User = get_user_model()

Expand Down Expand Up @@ -75,7 +75,7 @@ def test_post_should_return_bad_request_if_user_does_not_exist(self):
@mock.patch("djoser.views.User", CustomUser)
@override_settings(AUTH_USER_MODEL="testapp.CustomUser")
def test_post_should_send_email_to_custom_user_with_username_reset_link(
self
self,
): # noqa
user = create_user(use_custom_data=True)
data = {"custom_email": get_user_email(user)}
Expand All @@ -97,7 +97,7 @@ def test_post_should_send_email_to_custom_user_with_username_reset_link(
DJOSER=dict(settings.DJOSER, **{"USERNAME_RESET_SHOW_EMAIL_NOT_FOUND": True}),
)
def test_post_should_return_bad_request_with_custom_email_field_if_user_does_not_exist(
self
self,
): # noqa
data = {"custom_email": "john@beatles.com"}

Expand Down
2 changes: 1 addition & 1 deletion testproject/testapp/tests/test_reset_username_confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from testapp.tests.common import create_user

import djoser.utils
import djoser.views
from djoser.conf import settings as default_settings
from testapp.tests.common import create_user

User = get_user_model()

Expand Down

0 comments on commit a300b65

Please sign in to comment.