42 lines
1.3 KiB
Python
42 lines
1.3 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
|