test_endpoint_evento.py
828 Bytes
import pytest
from rest_framework import status
from django.contrib.auth.models import User
from django.urls import reverse
from rest_framework.test import APIClient
from evento.tests.factories import EventoFactory, FechaEventoFactory
from evento.models import Evento
@pytest.mark.django_db
def test_evento_list():
cliente = APIClient()
user = User.objects.create_user(username='admin', email='admin@example.com', password='password123')
cliente.force_authenticate(user=user)
for _ in range(4):
evento = EventoFactory.create()
fechas = FechaEventoFactory.create_batch(size=2)
evento.fechas.set(fechas)
endpoint = reverse('evento-list')
response = cliente.get(path=endpoint)
assert response.status_code == status.HTTP_200_OK
assert len(response.data['results']) == 4