Merge branch 'master' into fix_django_31

This commit is contained in:
Areski Belaid 2021-02-21 17:56:24 +01:00 committed by GitHub
commit 26540f4cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 52 deletions

View File

@ -26,7 +26,7 @@ jobs:
run: pre-commit autoupdate run: pre-commit autoupdate
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3.8.0 uses: peter-evans/create-pull-request@v3.8.2
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-autoupdate branch: update/pre-commit-autoupdate

View File

@ -3,6 +3,37 @@ All enhancements and patches to Cookiecutter Django will be documented in this f
<!-- GENERATOR_PLACEHOLDER --> <!-- GENERATOR_PLACEHOLDER -->
## [2021-02-16]
### Updated
- Update sentry-sdk to 0.20.2 ([#3054](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3054))
- Update sphinx to 3.5.0 ([#3053](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3053))
## [2021-02-13]
### Updated
- Update sentry-sdk to 0.20.1 ([#3052](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3052))
## [2021-02-12]
### Updated
- Update pre-commit to 2.10.1 ([#3045](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3045))
- Update sentry-sdk to 0.20.0 ([#3051](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3051))
## [2021-02-10]
### Updated
- Bump peter-evans/create-pull-request from v3.8.1 to v3.8.2 ([#3049](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3049))
## [2021-02-08]
### Updated
- Update django-extensions to 3.1.1 ([#3047](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3047))
- Bump peter-evans/create-pull-request from v3.8.0 to v3.8.1 ([#3046](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3046))
## [2021-02-06]
### Changed
- Removed Redundant test_case_sensitivity() and made test_not_authenticated() get the LOGIN_URL dynamically. ([#3041](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3041))
- Refactored users.forms to make the code more readeable ([#3029](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3029))
- Update django to 3.0.12 ([#3037](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3037))
### Updated
- Update tox to 3.21.4 ([#3044](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3044))
## [2021-02-01] ## [2021-02-01]
### Updated ### Updated
- Update pytz to 2021.1 ([#3035](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3035)) - Update pytz to 2021.1 ([#3035](https://api.github.com/repos/pydanny/cookiecutter-django/pulls/3035))

View File

@ -11,7 +11,7 @@ flake8-isort==4.0.0
# Testing # Testing
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
tox==3.21.3 tox==3.21.4
pytest==5.4.3 # pyup: <6 # https://github.com/hackebrot/pytest-cookies/issues/51 pytest==5.4.3 # pyup: <6 # https://github.com/hackebrot/pytest-cookies/issues/51
pytest-cookies==0.5.1 pytest-cookies==0.5.1
pytest-instafail==0.4.2 pytest-instafail==0.4.2

View File

@ -10,7 +10,7 @@ except ImportError:
# Our version ALWAYS matches the version of Django we support # Our version ALWAYS matches the version of Django we support
# If Django has a new release, we branch, tag, then update this setting after the tag. # If Django has a new release, we branch, tag, then update this setting after the tag.
version = "3.0.11" version = "3.0.12"
if sys.argv[-1] == "tag": if sys.argv[-1] == "tag":
os.system(f'git tag -a {version} -m "version {version}"') os.system(f'git tag -a {version} -m "version {version}"')

View File

@ -20,7 +20,7 @@ pytest-sugar==0.9.4 # https://github.com/Frozenball/pytest-sugar
# Documentation # Documentation
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
sphinx==3.4.3 # https://github.com/sphinx-doc/sphinx sphinx==3.5.0 # https://github.com/sphinx-doc/sphinx
sphinx-autobuild==2020.9.1 # https://github.com/GaretJax/sphinx-autobuild sphinx-autobuild==2020.9.1 # https://github.com/GaretJax/sphinx-autobuild
# Code quality # Code quality
@ -33,13 +33,13 @@ pylint-django==2.4.2 # https://github.com/PyCQA/pylint-django
{%- if cookiecutter.use_celery == 'y' %} {%- if cookiecutter.use_celery == 'y' %}
pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
{%- endif %} {%- endif %}
pre-commit==2.10.0 # https://github.com/pre-commit/pre-commit pre-commit==2.10.1 # https://github.com/pre-commit/pre-commit
# Django # Django
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
factory-boy==3.2.0 # https://github.com/FactoryBoy/factory_boy factory-boy==3.2.0 # https://github.com/FactoryBoy/factory_boy
django-debug-toolbar==3.2 # https://github.com/jazzband/django-debug-toolbar django-debug-toolbar==3.2 # https://github.com/jazzband/django-debug-toolbar
django-extensions==3.1.0 # https://github.com/django-extensions/django-extensions django-extensions==3.1.1 # https://github.com/django-extensions/django-extensions
django-coverage-plugin==1.8.0 # https://github.com/nedbat/django_coverage_plugin django-coverage-plugin==1.8.0 # https://github.com/nedbat/django_coverage_plugin
pytest-django==4.1.0 # https://github.com/pytest-dev/pytest-django pytest-django==4.1.0 # https://github.com/pytest-dev/pytest-django

View File

@ -8,7 +8,7 @@ psycopg2==2.8.6 # https://github.com/psycopg/psycopg2
Collectfast==2.2.0 # https://github.com/antonagestam/collectfast Collectfast==2.2.0 # https://github.com/antonagestam/collectfast
{%- endif %} {%- endif %}
{%- if cookiecutter.use_sentry == "y" %} {%- if cookiecutter.use_sentry == "y" %}
sentry-sdk==0.19.5 # https://github.com/getsentry/sentry-python sentry-sdk==0.20.2 # https://github.com/getsentry/sentry-python
{%- endif %} {%- endif %}
{%- if cookiecutter.use_docker == "n" and cookiecutter.windows == "y" %} {%- if cookiecutter.use_docker == "n" and cookiecutter.windows == "y" %}
hiredis==1.1.0 # https://github.com/redis/hiredis-py hiredis==1.1.0 # https://github.com/redis/hiredis-py

View File

@ -1,6 +1,5 @@
from django.contrib.auth import forms as admin_forms from django.contrib.auth import forms as admin_forms
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
User = get_user_model() User = get_user_model()
@ -12,20 +11,9 @@ class UserChangeForm(admin_forms.UserChangeForm):
class UserCreationForm(admin_forms.UserCreationForm): class UserCreationForm(admin_forms.UserCreationForm):
error_message = admin_forms.UserCreationForm.error_messages.update(
{"duplicate_username": _("This username has already been taken.")}
)
class Meta(admin_forms.UserCreationForm.Meta): class Meta(admin_forms.UserCreationForm.Meta):
model = User model = User
def clean_username(self): error_messages = {
username = self.cleaned_data["username"] "username": {"unique": _("This username has already been taken.")}
}
try:
User.objects.get(username=username)
except User.DoesNotExist:
return username
raise ValidationError(self.error_messages["duplicate_username"])

View File

@ -1,40 +1,39 @@
"""
Module for all Form Tests.
"""
import pytest import pytest
from django.utils.translation import ugettext_lazy as _
from {{ cookiecutter.project_slug }}.users.forms import UserCreationForm from {{ cookiecutter.project_slug }}.users.forms import UserCreationForm
from {{ cookiecutter.project_slug }}.users.tests.factories import UserFactory from {{ cookiecutter.project_slug }}.users.models import User
pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
class TestUserCreationForm: class TestUserCreationForm:
def test_clean_username(self): """
# A user with proto_user params does not exist yet. Test class for all tests related to the UserCreationForm
proto_user = UserFactory.build() """
form = UserCreationForm( def test_username_validation_error_msg(self, user: User):
{ """
"username": proto_user.username, Tests UserCreation Form's unique validator functions correctly by testing:
"password1": proto_user._password, 1) A new user with an existing username cannot be added.
"password2": proto_user._password, 2) Only 1 error is raised by the UserCreation Form
} 3) The desired error message is raised
) """
assert form.is_valid() # The user already exists,
assert form.clean_username() == proto_user.username
# Creating a user.
form.save()
# The user with proto_user params already exists,
# hence cannot be created. # hence cannot be created.
form = UserCreationForm( form = UserCreationForm(
{ {
"username": proto_user.username, "username": user.username,
"password1": proto_user._password, "password1": user.password,
"password2": proto_user._password, "password2": user.password,
} }
) )
assert not form.is_valid() assert not form.is_valid()
assert len(form.errors) == 1 assert len(form.errors) == 1
assert "username" in form.errors assert "username" in form.errors
assert form.errors["username"][0] == _("This username has already been taken.")

View File

@ -1,10 +1,11 @@
import pytest import pytest
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.contrib.messages.middleware import MessageMiddleware from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from django.http.response import Http404
from django.test import RequestFactory from django.test import RequestFactory
from django.urls import reverse
from {{ cookiecutter.project_slug }}.users.forms import UserChangeForm from {{ cookiecutter.project_slug }}.users.forms import UserChangeForm
from {{ cookiecutter.project_slug }}.users.models import User from {{ cookiecutter.project_slug }}.users.models import User
@ -90,13 +91,7 @@ class TestUserDetailView:
request.user = AnonymousUser() request.user = AnonymousUser()
response = user_detail_view(request, username=user.username) response = user_detail_view(request, username=user.username)
login_url = reverse(settings.LOGIN_URL)
assert response.status_code == 302 assert response.status_code == 302
assert response.url == "/accounts/login/?next=/fake-url/" assert response.url == f"{login_url}?next=/fake-url/"
def test_case_sensitivity(self, rf: RequestFactory):
request = rf.get("/fake-url/")
request.user = UserFactory(username="UserName")
with pytest.raises(Http404):
user_detail_view(request, username="username")