backend/image_markuper/users/tests/test_drf_views.py

31 lines
806 B
Python
Raw Normal View History

2022-10-25 23:29:13 +03:00
from django.test import RequestFactory
from image_markuper.users.api.views import UserViewSet
from image_markuper.users.models import User
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,
"name": user.name,
"url": f"http://testserver/api/users/{user.username}/",
}