Enzo Yair

finaliza app organismo

@@ -6,15 +6,16 @@ from .serializers import OrganismoSerializer, DependenciaSerializer @@ -6,15 +6,16 @@ from .serializers import OrganismoSerializer, DependenciaSerializer
6 6
7 7
8 class OrganismoViewSets(viewsets.ReadOnlyModelViewSet): 8 class OrganismoViewSets(viewsets.ReadOnlyModelViewSet):
9 - queryset = Organismo.objects.all() 9 + queryset = Organismo.objects.all().order_by('id')
10 serializer_class = OrganismoSerializer 10 serializer_class = OrganismoSerializer
11 permission_classes = [IsAuthenticated, ] 11 permission_classes = [IsAuthenticated, ]
12 lookup_field = 'id' 12 lookup_field = 'id'
13 13
14 14
15 class DependenciaViewSets(viewsets.ReadOnlyModelViewSet): 15 class DependenciaViewSets(viewsets.ReadOnlyModelViewSet):
16 - queryset = Dependencia.objects.all() 16 + queryset = Dependencia.objects.all().order_by('id')
17 serializer_class = DependenciaSerializer 17 serializer_class = DependenciaSerializer
18 permission_classes = [IsAuthenticated, ] 18 permission_classes = [IsAuthenticated, ]
19 lookup_field = 'id' 19 lookup_field = 'id'
20 20
  21 +
@@ -2,3 +2,19 @@ import factory @@ -2,3 +2,19 @@ import factory
2 2
3 from factory import SubFactory, faker, django 3 from factory import SubFactory, faker, django
4 4
  5 +from organismo.models import Organismo, Dependencia
  6 +
  7 +
  8 +class OrganimsoFactory(django.DjangoModelFactory):
  9 + class Meta:
  10 + model = Organismo
  11 +
  12 + short_name = faker.Faker(provider='sentence', nb_words=30)
  13 +
  14 +
  15 +class DependenciaFactory(django.DjangoModelFactory):
  16 + class Meta:
  17 + model = Dependencia
  18 +
  19 + organismo = SubFactory(factory=OrganimsoFactory)
  20 + short_name = faker.Faker(provider='sentence', nb_words=30)
  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 organismo.tests.factories import OrganimsoFactory, DependenciaFactory
  8 +
  9 +
  10 +@pytest.mark.django_db
  11 +def test_organismo_listado():
  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 + OrganimsoFactory.create_batch(size=4)
  17 +
  18 + endpoint = reverse('organismo-list')
  19 + response = cliente.get(path=endpoint)
  20 +
  21 + assert response.status_code == status.HTTP_200_OK
  22 +
  23 +
  24 +@pytest.mark.django_db
  25 +def test_dependencia_listado():
  26 + cliente = APIClient()
  27 + user = User.objects.create_user(username='admin', email='admin@example.com', password='password123')
  28 + cliente.force_authenticate(user=user)
  29 +
  30 + DependenciaFactory.create_batch(size=2)
  31 +
  32 + endpoint = reverse('dependencia-list')
  33 + response = cliente.get(path=endpoint)
  34 +
  35 + assert response.status_code == status.HTTP_200_OK
@@ -6,4 +6,4 @@ from organismo import api as organismo_api @@ -6,4 +6,4 @@ from organismo import api as organismo_api
6 router = routers.DefaultRouter() 6 router = routers.DefaultRouter()
7 7
8 router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSets) 8 router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSets)
9 -router.register(prefix='dependencia', viewset=organismo_api.OrganismoViewSets)  
  9 +router.register(prefix='dependencia', viewset=organismo_api.DependenciaViewSets)
@@ -55,6 +55,9 @@ THIRD_PARTY_APPS = ( @@ -55,6 +55,9 @@ THIRD_PARTY_APPS = (
55 'rest_framework', 55 'rest_framework',
56 'django_filters', 56 'django_filters',
57 'corsheaders', 57 'corsheaders',
  58 + 'oauth2_provider',
  59 + 'mozilla_django_oidc',
  60 +
58 ) 61 )
59 62
60 PROJECT_APPS = ( 63 PROJECT_APPS = (
1 [pytest] 1 [pytest]
2 -DJANGO_SETTINGS_MODULE=PROJECTproject-NAME.settings.testing 2 +DJANGO_SETTINGS_MODULE=project.settings.testing
3 norecursedirs = requirements deployment 3 norecursedirs = requirements deployment
4 -testpaths = tests 4 +testpaths = test
5 addopts = --capture=fd --nomigrations 5 addopts = --capture=fd --nomigrations
@@ -2,3 +2,4 @@ @@ -2,3 +2,4 @@
2 2
3 pytest==6.2.5 3 pytest==6.2.5
4 pytest-django==4.4.0 4 pytest-django==4.4.0
  5 +factory_boy==3.3.1