schon/engine/core/tests/test_drf.py
Egor fureunoir Gorbunov 1ecd784b4e Features: 1) Add setup for generating authorization tokens in DRFCoreViewsTests; 2) Simplify user handling in JWT mutations using validated serializer data.
Fixes: 1) Correct redundant user lookup in JWT mutations.

Extra: 1) Add TODO comments for HTTP method tests in both DRF and Graphene test modules; 2) Minor cleanup in test files.
2025-11-14 17:21:39 +03:00

33 lines
1.2 KiB
Python

from django.test import TestCase
from rest_framework.test import APIClient
from engine.vibes_auth.models import User
from engine.vibes_auth.serializers import TokenObtainPairSerializer
class DRFCoreViewsTests(TestCase):
def setUp(self):
super().setUp()
self.client = APIClient()
self.superuser_password = "Str0ngPass!word1"
self.superuser = User.objects.create(
email="test-superuser@email.com",
password=self.superuser_password,
is_active=True,
is_verified=True,
is_superuser=True,
is_staff=True,
)
self.user_password = "Str0ngPass!word2"
self.user = User.objects.create(
email="test-superuser@email.com", password=self.user_password, is_active=True, is_verified=True
)
def _get_authorization_token(self, user):
serializer = TokenObtainPairSerializer(
data={"email": user.email, "password": self.superuser_password if user.is_superuser else self.user_password}
)
serializer.is_valid(raise_exception=True)
return serializer.validated_data["access_token"]
# TODO: create tests for every possible HTTP method in core module with DRF stack