mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-26 03:24:01 +03:00
add use drf tests
This commit is contained in:
parent
04fea65333
commit
f13f3dc2bf
|
@ -299,6 +299,8 @@ 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():
|
||||
|
|
|
@ -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"
|
|
@ -0,0 +1,30 @@
|
|||
import pytest
|
||||
from django.test import RequestFactory
|
||||
|
||||
from {{ cookiecutter.project_slug }}.users.models import User
|
||||
from {{ cookiecutter.project_slug }}.users.api.views import UserViewSet
|
||||
from {{ cookiecutter.project_slug }}.users.api.serializers import UserSerializer
|
||||
|
||||
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 == UserSerializer(user, context={"request": request}).data
|
Loading…
Reference in New Issue
Block a user