Repository: cookiecutter/cookiecutter-django

Issue:
Failing mypy tests in users app with django-stubs
## What happened?
After installing `django-stubs` (`pip install django-stubs`) the typing tests in the `users` app fail with `Name 'settings.AUTH_USER_MODEL' is not defined`.

`reveal_type(settings.AUTH_USER_MODEL)` returns `Any` which doesn't provide much value. Did this work differently at some stage in the past? If not, an easy fix would be to remove the annotations in the test function signatures.

Furthermore, the type of `settings.AUTH_USER_MODEL` is `str` and the `user` type should be a subclass of a django model. If that is correct, that might be another reason to remove the annotation.



## What should've happened instead?
No mypy errors



## Steps to reproduce
```
pip install django-stubs
mypy <project dir>
```

[//]: # (Any or all of the following:)
[//]: # (* Host system configuration: OS, Docker & friends' versions etc.)
[//]: # (* Replay file https://cookiecutter.readthedocs.io/en/latest/advanced/replay.html)
[//]: # (* Logs)



Discussion:
I don't think it worked differently in the past. We should fix this. PR welcome.

Resolving patch:
diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py
--- a/{{cookiecutter.project_slug}}/config/settings/production.py
+++ b/{{cookiecutter.project_slug}}/config/settings/production.py
@@ -154,7 +154,7 @@ class MediaRootGoogleCloudStorage(GoogleCloudStorage):
 # 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",
         [
diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/conftest.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/conftest.py
--- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/conftest.py
+++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/conftest.py
@@ -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()
 
 


Test patch:
diff --git a/{{cookiecutter.project_slug}}/config/settings/test.py b/{{cookiecutter.project_slug}}/config/settings/test.py
--- a/{{cookiecutter.project_slug}}/config/settings/test.py
+++ b/{{cookiecutter.project_slug}}/config/settings/test.py
@@ -32,7 +32,7 @@
 
 # TEMPLATES
 # ------------------------------------------------------------------------------
-TEMPLATES[0]["OPTIONS"]["loaders"] = [  # noqa F405
+TEMPLATES[0]["OPTIONS"]["loaders"] = [  # type: ignore[index] # noqa F405
     (
         "django.template.loaders.cached.Loader",
         [
diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_models.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_models.py
--- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_models.py
+++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_models.py
@@ -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}/"
diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_urls.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_urls.py
--- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_urls.py
+++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_urls.py
@@ -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}/"
diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_views.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_views.py
--- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_views.py
+++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_views.py
@@ -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 @@ def test_get_success_url(
 
         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 @@ def test_get_object(
 
 
 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