feat(API): change to jwt authentication.
This commit is contained in:
@@ -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}')
|
||||
|
||||
Reference in New Issue
Block a user