Merge branch 'feature/endpoint_evento' into 'develop'
Feature/endpoint evento Feature: -Se crea endpoint de evento Test resultado: ======================================================================================================== 3 passed in 2.28s ======================================================================================================== See merge request !3
Showing
8 changed files
with
78 additions
and
5 deletions
project/apps/evento/api.py
0 → 100644
1 | +from rest_framework import viewsets | ||
2 | +from rest_framework.permissions import IsAuthenticated | ||
3 | + | ||
4 | +from .models import Evento | ||
5 | +from .serializers import EventoSerializer | ||
6 | + | ||
7 | + | ||
8 | +class EventoViewSets(viewsets.ReadOnlyModelViewSet): | ||
9 | + queryset = Evento.objects.all().order_by('id') | ||
10 | + serializer_class = EventoSerializer | ||
11 | + permission_classes = [IsAuthenticated,] | ||
12 | + lookup_field = 'id' | ||
13 | + |
project/apps/evento/serializers.py
0 → 100644
1 | +from rest_framework_json_api import serializers | ||
2 | + | ||
3 | +from .models import Evento | ||
4 | + | ||
5 | + | ||
6 | +class EventoSerializer(serializers.ModelSerializer): | ||
7 | + class Meta: | ||
8 | + model = Evento | ||
9 | + fields = ( | ||
10 | + 'titulo', | ||
11 | + 'categoria', | ||
12 | + 'fecha_inicio', | ||
13 | + 'hora_inicio', | ||
14 | + 'fecha_final', | ||
15 | + 'hora_fin', | ||
16 | + 'fechas', | ||
17 | + 'descripcion', | ||
18 | + 'direccion', | ||
19 | + 'url', | ||
20 | + 'organismo', | ||
21 | + 'dependencia', | ||
22 | + 'imagen', | ||
23 | + ) |
project/apps/evento/tests/__init__.py
0 → 100644
project/apps/evento/tests/factories.py
0 → 100644
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 | from rest_framework import routers | 1 | from rest_framework import routers |
2 | 2 | ||
3 | from organismo import api as organismo_api | 3 | from organismo import api as organismo_api |
4 | +from evento import api as evento_api | ||
4 | 5 | ||
5 | # Define routes | 6 | # Define routes |
6 | router = routers.DefaultRouter() | 7 | router = routers.DefaultRouter() |
7 | 8 | ||
8 | router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSets) | 9 | router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSets) |
9 | -router.register(prefix='dependencia', viewset=organismo_api.DependenciaViewSets) | ||
10 | +router.register(prefix='dependencia', viewset=organismo_api.DependenciaViewSets) | ||
11 | +router.register(prefix='evento', viewset=evento_api.EventoViewSets) |
@@ -85,10 +85,9 @@ ROOT_URLCONF = 'project.urls' | @@ -85,10 +85,9 @@ ROOT_URLCONF = 'project.urls' | ||
85 | # Python dotted path to the WSGI application used by Django's runserver. | 85 | # Python dotted path to the WSGI application used by Django's runserver. |
86 | WSGI_APPLICATION = 'project.wsgi.application' | 86 | WSGI_APPLICATION = 'project.wsgi.application' |
87 | 87 | ||
88 | -LANGUAGE_CODE = 'es-ar' | 88 | +LANGUAGE_CODE = 'es-AR' |
89 | TIME_ZONE = 'America/Argentina/Catamarca' | 89 | TIME_ZONE = 'America/Argentina/Catamarca' |
90 | USE_I18N = True | 90 | USE_I18N = True |
91 | -USE_L10N = True | ||
92 | USE_TZ = True | 91 | USE_TZ = True |
93 | 92 | ||
94 | LANGUAGES = [ | 93 | LANGUAGES = [ |
-
Please register or login to post a comment