Repository: cookiecutter/cookiecutter-django

Issue:
Write tests for the DRF setup
## Description

A new option has been added to bring support for DRF in #2224.
However, this is currently not tested. We should write tests covering various components of the DRF option and remove them when the user opts out.


Discussion:
May I try this issue? @browniebroke 
Yes of course! 

Resolving patch:
diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py
--- a/hooks/post_gen_project.py
+++ b/hooks/post_gen_project.py
@@ -299,6 +299,16 @@ def remove_aws_dockerfile():
 def remove_drf_starter_files():
     os.remove(os.path.join("config", "api_router.py"))
     shutil.rmtree(os.path.join("{{cookiecutter.project_slug}}", "users", "api"))
+    os.remove(
+        os.path.join(
+            "{{cookiecutter.project_slug}}", "users", "tests", "test_drf_urls.py"
+        )
+    )
+    os.remove(
+        os.path.join(
+            "{{cookiecutter.project_slug}}", "users", "tests", "test_drf_views.py"
+        )
+    )
 
 
 def remove_storages_module():


Test patch:
diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_drf_urls.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_drf_urls.py
new file mode 100644
--- /dev/null
+++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_drf_urls.py
@@ -0,0 +1,24 @@
+import pytest
+from django.urls import resolve, reverse
+
+from {{ cookiecutter.project_slug }}.users.models import User
+
+pytestmark = pytest.mark.django_db
+
+
+def test_user_detail(user: User):
+    assert (
+        reverse("api:user-detail", kwargs={"username": user.username})
+        == f"/api/users/{user.username}/"
+    )
+    assert resolve(f"/api/users/{user.username}/").view_name == "api:user-detail"
+
+
+def test_user_list():
+    assert reverse("api:user-list") == "/api/users/"
+    assert resolve("/api/users/").view_name == "api:user-list"
+
+
+def test_user_me():
+    assert reverse("api:user-me") == "/api/users/me/"
+    assert resolve("/api/users/me/").view_name == "api:user-me"
diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_drf_views.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_drf_views.py
new file mode 100644
--- /dev/null
+++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_drf_views.py
@@ -0,0 +1,34 @@
+import pytest
+from django.test import RequestFactory
+
+from {{ cookiecutter.project_slug }}.users.api.views import UserViewSet
+from {{ cookiecutter.project_slug }}.users.models import User
+
+pytestmark = pytest.mark.django_db
+
+
+class TestUserViewSet:
+    def test_get_queryset(self, user: User, rf: RequestFactory):
+        view = UserViewSet()
+        request = rf.get("/fake-url/")
+        request.user = user
+
+        view.request = request
+
+        assert user in view.get_queryset()
+
+    def test_me(self, user: User, rf: RequestFactory):
+        view = UserViewSet()
+        request = rf.get("/fake-url/")
+        request.user = user
+
+        view.request = request
+
+        response = view.me(request)
+
+        assert response.data == {
+            "username": user.username,
+            "email": user.email,
+            "name": user.name,
+            "url": f"/api/users/{user.username}/",
+        }