feat(API): change to jwt authentication.

This commit is contained in:
2026-02-14 15:12:32 -05:00
parent 4812160ea2
commit 7a9034943a
18 changed files with 130 additions and 82 deletions

View File

@@ -1,10 +1,19 @@
from django.contrib.auth.models import User
from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework.test import APIClient
class LoginMixin:
def login(self):
username = 'nombre_usuario'
password = 'contraseña'
email = 'correo@example.com'
self.user = User.objects.create_user(username, email, password)
self.client.login(username=username, password=password)
self.user = User.objects.create_superuser(
username='admin',
email='admin@example.com',
password='adminpass'
)
refresh = RefreshToken.for_user(self.user)
self.access_token = str(refresh.access_token)
self.client = APIClient()
self.client.credentials(
HTTP_AUTHORIZATION=f'Bearer {self.access_token}')