test_endpoint.py 1.04 KB
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