70 lines
2.5 KiB
Python
70 lines
2.5 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
|
|
from plovidba_aplikacija.serializers import PointSerializer
|
|
|
|
# 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)
|
|
self.assertIn('results', response.data)
|
|
|
|
# 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)
|
|
|
|
|
|
# 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': 15.17517, 'lon': 44.01113},
|
|
# 'naziv' : 'updated-naziv',
|
|
|
|
# }
|
|
# response = self.client.patch(self.url, data, format='json')
|
|
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
# # Reload the object from the database
|
|
# updated_objekt = ObjektSigurnosti.objects.get(pk=self.objekt.pk)
|
|
|
|
# # Check if the values are updated correctly
|
|
# self.assertEqual(updated_objekt.lokacija.x, 13.79758)
|
|
# self.assertEqual(updated_objekt.lokacija.y, 44.9254)
|
|
# self.assertEqual(updated_objekt.naziv, 'updated-naziv')
|
|
|
|
|
|
# def test_retrieve_objekt_sigurnosti(self):
|
|
# url = reverse('objektisigurnosti-detail', args=[self.objekt.id])
|
|
# response = self.client.get(url)
|
|
|
|
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
|