52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from django.test import TestCase
|
|
from django.contrib.gis.geos import Point
|
|
from django.urls import reverse
|
|
from rest_framework import status
|
|
from rest_framework.test import APITestCase
|
|
from plovidba_aplikacija.models import ObjektSigurnosti
|
|
|
|
|
|
# Testiranje listanja objekata
|
|
class ObjektSigurnostiListTest(APITestCase):
|
|
def test_list_objekti_sigurnosti(self):
|
|
url = reverse('objektisigurnosti-list')
|
|
response = self.client.get(url)
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
# Testiranje stvaranja objekata
|
|
class ObjektSigurnostiCreateTest(APITestCase):
|
|
def setUp(self):
|
|
self.url = reverse('objektisigurnosti-list')
|
|
|
|
def test_create_objekt_sigurnosti(self):
|
|
data = {
|
|
'lokacija': '{"lat": 45.123, "lon": 18.456}',
|
|
'naziv': 'test-naziv',
|
|
}
|
|
response = self.client.post(self.url, data, format='json')
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
self.assertTrue(ObjektSigurnosti.objects.filter(naziv='test-naziv').exists())
|
|
|
|
|
|
# Testiranje dohvaćanja pojedinog objekata
|
|
class ObjektSigurnostiDetailTest(APITestCase):
|
|
def setUp(self):
|
|
self.objekt = ObjektSigurnosti.objects.create(
|
|
lokacija=Point(18.456, 45.123),
|
|
naziv='test-naziv',
|
|
)
|
|
self.url = reverse('objektisigurnosti-detail', args=[self.objekt.pk])
|
|
|
|
|
|
def test_get_objekt_sigurnosti(self):
|
|
response = self.client.get(self.url)
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
def test_update_objekt_sigurnosti(self):
|
|
data = {
|
|
'lokacija': '{"lat": 45.123, "lon": 18.456}',
|
|
'naziv': 'test-naziv',
|
|
}
|
|
response = self.client.patch(self.url, data, format='json')
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |