import pytest from django.urls import reverse from rest_framework.test import APIClient @pytest.mark.django_db class TestLocationApi: url = reverse('locations_api') user = None @pytest.fixture(autouse=True) def setup_test(self, add_user_with_permissions): self.user = add_user_with_permissions(username='test_api_user', password='TestApiPass123', is_superuser=True) self.client = APIClient() self.client.force_authenticate(user=self.user) @pytest.mark.unit def test_get_location_list(self): """Test view return status 200 and data location list with code and id""" response = self.client.get(self.url) assert response.status_code == 200 data = response.json() assert isinstance(data, list) assert len(data) assert 'id' in data[0] assert 'code' in data[0]