Enzo Yair

finaliza app organismo

... ... @@ -6,15 +6,16 @@ from .serializers import OrganismoSerializer, DependenciaSerializer
class OrganismoViewSets(viewsets.ReadOnlyModelViewSet):
queryset = Organismo.objects.all()
queryset = Organismo.objects.all().order_by('id')
serializer_class = OrganismoSerializer
permission_classes = [IsAuthenticated, ]
lookup_field = 'id'
class DependenciaViewSets(viewsets.ReadOnlyModelViewSet):
queryset = Dependencia.objects.all()
queryset = Dependencia.objects.all().order_by('id')
serializer_class = DependenciaSerializer
permission_classes = [IsAuthenticated, ]
lookup_field = 'id'
... ...
... ... @@ -2,3 +2,19 @@ import factory
from factory import SubFactory, faker, django
from organismo.models import Organismo, Dependencia
class OrganimsoFactory(django.DjangoModelFactory):
class Meta:
model = Organismo
short_name = faker.Faker(provider='sentence', nb_words=30)
class DependenciaFactory(django.DjangoModelFactory):
class Meta:
model = Dependencia
organismo = SubFactory(factory=OrganimsoFactory)
short_name = faker.Faker(provider='sentence', nb_words=30)
\ No newline at end of file
... ...
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 organismo.tests.factories import OrganimsoFactory, DependenciaFactory
@pytest.mark.django_db
def test_organismo_listado():
cliente = APIClient()
user = User.objects.create_user(username='admin', email='admin@example.com', password='password123')
cliente.force_authenticate(user=user)
OrganimsoFactory.create_batch(size=4)
endpoint = reverse('organismo-list')
response = cliente.get(path=endpoint)
assert response.status_code == status.HTTP_200_OK
@pytest.mark.django_db
def test_dependencia_listado():
cliente = APIClient()
user = User.objects.create_user(username='admin', email='admin@example.com', password='password123')
cliente.force_authenticate(user=user)
DependenciaFactory.create_batch(size=2)
endpoint = reverse('dependencia-list')
response = cliente.get(path=endpoint)
assert response.status_code == status.HTTP_200_OK
\ No newline at end of file
... ...
... ... @@ -6,4 +6,4 @@ from organismo import api as organismo_api
router = routers.DefaultRouter()
router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSets)
router.register(prefix='dependencia', viewset=organismo_api.OrganismoViewSets)
\ No newline at end of file
router.register(prefix='dependencia', viewset=organismo_api.DependenciaViewSets)
\ No newline at end of file
... ...
... ... @@ -55,6 +55,9 @@ THIRD_PARTY_APPS = (
'rest_framework',
'django_filters',
'corsheaders',
'oauth2_provider',
'mozilla_django_oidc',
)
PROJECT_APPS = (
... ...
[pytest]
DJANGO_SETTINGS_MODULE=PROJECTproject-NAME.settings.testing
DJANGO_SETTINGS_MODULE=project.settings.testing
norecursedirs = requirements deployment
testpaths = tests
testpaths = test
addopts = --capture=fd --nomigrations
... ...
... ... @@ -2,3 +2,4 @@
pytest==6.2.5
pytest-django==4.4.0
factory_boy==3.3.1
... ...