Enzo Yair

feature/endpoint_evento

@@ -20,4 +20,4 @@ class EventoSerializer(serializers.ModelSerializer): @@ -20,4 +20,4 @@ class EventoSerializer(serializers.ModelSerializer):
20 'organismo', 20 'organismo',
21 'dependencia', 21 'dependencia',
22 'imagen', 22 'imagen',
23 - ) 23 + )
  1 +from factory import faker, django
  2 +from datetime import date
  3 +from evento.models import Evento
  4 +
  5 +
  6 +class EventoFactory(django.DjangoModelFactory):
  7 + class Meta:
  8 + model = Evento
  9 +
  10 + titulo = faker.Faker(provider='sentence', nb_words=50)
  11 + categoria = faker.Faker(provider='sentence', nb_words=30)
  12 + direccion = 'https://maps.app.goo.gl/CNwbHBx5zq1VDje57'
  13 + descripcion = faker.Faker(provider='sentence', nb_words=30)
  14 + fecha_inicio = date(2024, 1, 1)
  15 + hora_inicio = '10:00:00'
  16 + fecha_final = date(2024, 1, 2)
  17 + hora_fin = '11:20:47'
  1 +import pytest
  2 +from rest_framework import status
  3 +from django.contrib.auth.models import User
  4 +from django.urls import reverse
  5 +from rest_framework.test import APIClient
  6 +
  7 +from evento.tests.factories import EventoFactory
  8 +
  9 +
  10 +@pytest.mark.django_db
  11 +def test_evento_list():
  12 + cliente = APIClient()
  13 + user = User.objects.create_user(username='admin', email='admin@example.com', password='password123')
  14 + cliente.force_authenticate(user=user)
  15 +
  16 + EventoFactory.create_batch(size=4)
  17 +
  18 + endpoint = reverse('evento-list')
  19 + response = cliente.get(path=endpoint)
  20 +
  21 + assert response.status_code == status.HTTP_200_OK
1 -import factory  
2 -  
3 from factory import SubFactory, faker, django 1 from factory import SubFactory, faker, django
4 2
5 from organismo.models import Organismo, Dependencia 3 from organismo.models import Organismo, Dependencia
@@ -8,4 +8,4 @@ router = routers.DefaultRouter() @@ -8,4 +8,4 @@ router = routers.DefaultRouter()
8 8
9 router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSets) 9 router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSets)
10 router.register(prefix='dependencia', viewset=organismo_api.DependenciaViewSets) 10 router.register(prefix='dependencia', viewset=organismo_api.DependenciaViewSets)
11 -router.register(prefix='eventos', viewset=evento_api.EventoViewSets) 11 +router.register(prefix='evento', viewset=evento_api.EventoViewSets)