mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-23 01:57:03 +03:00
Fix failing mypy tests in users app with django-stubs (#2395)
This commit is contained in:
commit
5cfed14b47
|
@ -154,7 +154,7 @@ MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/"
|
|||
# TEMPLATES
|
||||
# ------------------------------------------------------------------------------
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
||||
TEMPLATES[0]["OPTIONS"]["loaders"] = [ # noqa F405
|
||||
TEMPLATES[0]["OPTIONS"]["loaders"] = [ # type: ignore[index] # noqa F405
|
||||
(
|
||||
"django.template.loaders.cached.Loader",
|
||||
[
|
||||
|
|
|
@ -32,7 +32,7 @@ PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]
|
|||
|
||||
# TEMPLATES
|
||||
# ------------------------------------------------------------------------------
|
||||
TEMPLATES[0]["OPTIONS"]["loaders"] = [ # noqa F405
|
||||
TEMPLATES[0]["OPTIONS"]["loaders"] = [ # type: ignore[index] # noqa F405
|
||||
(
|
||||
"django.template.loaders.cached.Loader",
|
||||
[
|
||||
|
|
|
@ -12,6 +12,7 @@ psycopg2-binary==2.8.4 # https://github.com/psycopg/psycopg2
|
|||
# Testing
|
||||
# ------------------------------------------------------------------------------
|
||||
mypy==0.761 # https://github.com/python/mypy
|
||||
django-stubs==1.3.1 # https://github.com/typeddjango/django-stubs
|
||||
pytest==5.3.1 # https://github.com/pytest-dev/pytest
|
||||
pytest-sugar==0.9.2 # https://github.com/Frozenball/pytest-sugar
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ ignore_missing_imports = True
|
|||
warn_unused_ignores = True
|
||||
warn_redundant_casts = True
|
||||
warn_unused_configs = True
|
||||
plugins = mypy_django_plugin.main
|
||||
|
||||
[mypy.plugins.django-stubs]
|
||||
django_settings_module = config.settings.test
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
from django.conf import settings
|
||||
from django.test import RequestFactory
|
||||
|
||||
from {{ cookiecutter.project_slug }}.users.models import User
|
||||
from {{ cookiecutter.project_slug }}.users.tests.factories import UserFactory
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ def media_storage(settings, tmpdir):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def user() -> settings.AUTH_USER_MODEL:
|
||||
def user() -> User:
|
||||
return UserFactory()
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import pytest
|
||||
from django.conf import settings
|
||||
|
||||
from {{ cookiecutter.project_slug }}.users.models import User
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_user_get_absolute_url(user: settings.AUTH_USER_MODEL):
|
||||
def test_user_get_absolute_url(user: User):
|
||||
assert user.get_absolute_url() == f"/users/{user.username}/"
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import pytest
|
||||
from django.conf import settings
|
||||
from django.urls import reverse, resolve
|
||||
|
||||
from {{ cookiecutter.project_slug }}.users.models import User
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_detail(user: settings.AUTH_USER_MODEL):
|
||||
def test_detail(user: User):
|
||||
assert (
|
||||
reverse("users:detail", kwargs={"username": user.username})
|
||||
== f"/users/{user.username}/"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
from django.conf import settings
|
||||
from django.test import RequestFactory
|
||||
|
||||
from {{ cookiecutter.project_slug }}.users.models import User
|
||||
from {{ cookiecutter.project_slug }}.users.views import UserRedirectView, UserUpdateView
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
@ -16,9 +16,7 @@ class TestUserUpdateView:
|
|||
https://github.com/pytest-dev/pytest-django/pull/258
|
||||
"""
|
||||
|
||||
def test_get_success_url(
|
||||
self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory
|
||||
):
|
||||
def test_get_success_url(self, user: User, request_factory: RequestFactory):
|
||||
view = UserUpdateView()
|
||||
request = request_factory.get("/fake-url/")
|
||||
request.user = user
|
||||
|
@ -27,9 +25,7 @@ class TestUserUpdateView:
|
|||
|
||||
assert view.get_success_url() == f"/users/{user.username}/"
|
||||
|
||||
def test_get_object(
|
||||
self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory
|
||||
):
|
||||
def test_get_object(self, user: User, request_factory: RequestFactory):
|
||||
view = UserUpdateView()
|
||||
request = request_factory.get("/fake-url/")
|
||||
request.user = user
|
||||
|
@ -40,9 +36,7 @@ class TestUserUpdateView:
|
|||
|
||||
|
||||
class TestUserRedirectView:
|
||||
def test_get_redirect_url(
|
||||
self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory
|
||||
):
|
||||
def test_get_redirect_url(self, user: User, request_factory: RequestFactory):
|
||||
view = UserRedirectView()
|
||||
request = request_factory.get("/fake-url")
|
||||
request.user = user
|
||||
|
|
Loading…
Reference in New Issue
Block a user