prosli testovi nakon dodavanja user-a
This commit is contained in:
parent
bc9afd396b
commit
279c7df84a
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.9 on 2024-01-22 12:45
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('plovidba_aplikacija', '0009_objektsigurnosti_operater'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='objektsigurnosti',
|
||||
name='operater',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='imenovana_mjesta', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.9 on 2024-01-22 14:29
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('plovidba_aplikacija', '0010_alter_objektsigurnosti_operater'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='objektsigurnosti',
|
||||
name='operater',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
@ -13,7 +13,8 @@ class ObjektSigurnosti(models.Model):
|
||||
fotografija = models.CharField(max_length=255, null=True, blank=True)
|
||||
id_ais = models.CharField(max_length=255, null=True, blank=True)
|
||||
simbol_oznaka = models.CharField(max_length=255, null=True, blank=True)
|
||||
operater = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
operater = models.ForeignKey("user.User", on_delete=models.SET_NULL, null=True, blank=True)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.naziv
|
||||
|
||||
@ -27,7 +27,7 @@ class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
||||
objekt = ObjektSigurnosti.objects.create(lokacija=lokacija, **validated_data)
|
||||
return objekt
|
||||
|
||||
raise ValidationError("Invalid 'lon' or 'lat' vrijednosti za 'lokacija'.")
|
||||
raise ValidationError("Nevaljani 'lon' i 'lat' vrijednosti za 'lokacija'.")
|
||||
|
||||
|
||||
def to_representation(self, instance): #u sklopu ovog definiran i update
|
||||
@ -35,3 +35,29 @@ class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
||||
representation['lon'] = instance.lokacija.x
|
||||
representation['lat'] = instance.lokacija.y
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
lokacija_data = validated_data.get('lokacija', None)
|
||||
|
||||
if lokacija_data:
|
||||
try:
|
||||
lokacija_data = json.loads(lokacija_data)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
raise ValidationError("Nevaljan format za 'lokacija'. Mora biti JSON.")
|
||||
|
||||
if isinstance(lokacija_data, dict):
|
||||
lon = lokacija_data.get('lon')
|
||||
lat = lokacija_data.get('lat')
|
||||
|
||||
if lon is not None and lat is not None:
|
||||
lokacija = Point(lon, lat, srid=3765)
|
||||
instance.lokacija = lokacija
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
raise ValidationError("Nevaljani 'lon' i 'lat' vrijednosti za 'lokacija'.")
|
||||
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,3 +1,60 @@
|
||||
# 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': {'type': 'Point', 'coordinates': [45.123,18.456]},
|
||||
# 'naziv' : 'updated-naziv',
|
||||
|
||||
# }
|
||||
# response = self.client.patch(self.url, data, format='json')
|
||||
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
|
||||
from django.test import TestCase
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.urls import reverse
|
||||
@ -21,7 +78,7 @@ class ObjektSigurnostiCreateTest(APITestCase):
|
||||
|
||||
def test_create_objekt_sigurnosti(self):
|
||||
data = {
|
||||
'lokacija': {'lat': 45.123, 'lon': 18.456},
|
||||
'lokacija': '{"lat": 45.123, "lon": 18.456}',
|
||||
'naziv': 'test-naziv',
|
||||
}
|
||||
response = self.client.post(self.url, data, format='json')
|
||||
@ -45,13 +102,8 @@ class ObjektSigurnostiDetailTest(APITestCase):
|
||||
|
||||
def test_update_objekt_sigurnosti(self):
|
||||
data = {
|
||||
'lokacija': {'lat': 45.123, 'lon': 18.456},
|
||||
'naziv' : 'updated-naziv',
|
||||
|
||||
}
|
||||
'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)
|
||||
|
||||
|
||||
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
Binary file not shown.
@ -1,3 +1,65 @@
|
||||
from django.test import TestCase
|
||||
# from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
# from django.urls import reverse
|
||||
# from rest_framework import status
|
||||
# from rest_framework.test import APITestCase
|
||||
# from user.models import Organization, User
|
||||
# from user.views import user_delete, change_password
|
||||
|
||||
|
||||
|
||||
# class UserApiTestCase(APITestCase):
|
||||
|
||||
# def setUp(self):
|
||||
|
||||
# self.organization = Organization.objects.create(name="test organization")
|
||||
|
||||
# self.user01 = User.objects.create(
|
||||
# username="user01",
|
||||
# email="test@example.com",
|
||||
# first_name="User",
|
||||
# last_name="01",
|
||||
# organization=self.organization
|
||||
# )
|
||||
# self.user01.set_password('test1234')
|
||||
|
||||
# self.user02 = User.objects.create(
|
||||
# username="user02",
|
||||
# email="test02@example.com",
|
||||
# first_name="User",
|
||||
# last_name="02",
|
||||
# organization=self.organization
|
||||
# )
|
||||
|
||||
# def test_user_delete_forbidden(self):
|
||||
# self.client.force_authenticate(self.user02)
|
||||
# url = reverse("user_delete", kwargs={"pk": self.user01.id})
|
||||
# response = self.client.delete(url)
|
||||
# self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
# def test_user_delete_success(self):
|
||||
# self.client.force_authenticate(self.user01)
|
||||
# url = reverse("user_delete", kwargs={"pk": self.user01.id})
|
||||
# response = self.client.delete(url)
|
||||
# self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||
|
||||
# def test_user_password_change_bad_request(self):
|
||||
# self.client.force_authenticate(self.user01)
|
||||
# url = reverse("change_password")
|
||||
# data = {'old_password': 'wrong-paasword', 'new_password': 'pass1234'}
|
||||
# response = self.client.put(url, data=data)
|
||||
# self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# def test_user_password_change_too_comon(self):
|
||||
# self.client.force_authenticate(self.user01)
|
||||
# url = reverse("change_password")
|
||||
# data = {'old_password': 'test1234', 'new_password': 'pass1234'}
|
||||
# response = self.client.put(url, data=data)
|
||||
# self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# def test_user_password_change_success(self):
|
||||
# self.client.force_authenticate(self.user01)
|
||||
# url = reverse("change_password")
|
||||
# data = {'old_password': 'test1234', 'new_password': 'listlabs12'}
|
||||
# response = self.client.put(url, data=data)
|
||||
# self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user