PROSLI TESTOVI
This commit is contained in:
parent
298219ab30
commit
f46bc8337e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,6 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.gis.db import models
|
from django.contrib.gis.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
class ObjektSigurnosti(models.Model):
|
class ObjektSigurnosti(models.Model):
|
||||||
naziv = models.CharField(max_length=255)
|
naziv = models.CharField(max_length=255)
|
||||||
@ -13,6 +12,7 @@ class ObjektSigurnosti(models.Model):
|
|||||||
fotografija = models.CharField(max_length=255, null=True, blank=True)
|
fotografija = models.CharField(max_length=255, null=True, blank=True)
|
||||||
id_ais = 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)
|
simbol_oznaka = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
#operater = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.naziv
|
return self.naziv
|
||||||
|
|||||||
@ -2,30 +2,24 @@ from rest_framework import serializers
|
|||||||
from django.contrib.gis.geos import Point
|
from django.contrib.gis.geos import Point
|
||||||
from .models import ObjektSigurnosti
|
from .models import ObjektSigurnosti
|
||||||
|
|
||||||
class PointSerializer(serializers.Serializer):
|
|
||||||
lat = serializers.FloatField()
|
|
||||||
lon = serializers.FloatField()
|
|
||||||
|
|
||||||
def to_representation(self, instance):
|
|
||||||
return {'lat': instance.y, 'lon': instance.x}
|
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
|
||||||
return Point(float(data['lon']), float(data['lat']))
|
|
||||||
|
|
||||||
class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
||||||
lokacija = PointSerializer()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ObjektSigurnosti
|
model = ObjektSigurnosti
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
def to_representation(self, instance):
|
|
||||||
representation = super().to_representation(instance)
|
|
||||||
representation['lokacija'] = PointSerializer(instance.lokacija).data
|
|
||||||
return representation
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
lokacija_data = validated_data.pop('lokacija')
|
lokacija_data = validated_data.pop('lokacija', None)
|
||||||
lokacija = Point(lokacija_data['lon'], lokacija_data['lat'], srid=3765)
|
lokacija = Point(lokacija_data['lon'], lokacija_data['lat'], srid=3765)
|
||||||
objekt = ObjektSigurnosti.objects.create(lokacija=lokacija, **validated_data)
|
objekt = ObjektSigurnosti.objects.create(lokacija=lokacija, **validated_data)
|
||||||
return objekt
|
return objekt
|
||||||
|
|
||||||
|
def to_representation(self, instance):
|
||||||
|
return {'lon': instance.lokacija.x, 'lat': instance.lokacija.y}
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
lokacija_data = validated_data.pop('lokacija', None)
|
||||||
|
lokacija = Point(lokacija_data['lon'], lokacija_data['lat'], srid=3765) if lokacija_data else None
|
||||||
|
instance.lokacija = lokacija
|
||||||
|
instance.save()
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ from django.urls import reverse
|
|||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
from plovidba_aplikacija.models import ObjektSigurnosti
|
from plovidba_aplikacija.models import ObjektSigurnosti
|
||||||
from plovidba_aplikacija.serializers import PointSerializer
|
|
||||||
|
|
||||||
# Testiranje listanja objekata
|
# Testiranje listanja objekata
|
||||||
class ObjektSigurnostiListTest(APITestCase):
|
class ObjektSigurnostiListTest(APITestCase):
|
||||||
@ -13,7 +13,6 @@ class ObjektSigurnostiListTest(APITestCase):
|
|||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertIn('results', response.data)
|
|
||||||
|
|
||||||
# Testiranje stvaranja objekata
|
# Testiranje stvaranja objekata
|
||||||
class ObjektSigurnostiCreateTest(APITestCase):
|
class ObjektSigurnostiCreateTest(APITestCase):
|
||||||
@ -27,6 +26,7 @@ class ObjektSigurnostiCreateTest(APITestCase):
|
|||||||
}
|
}
|
||||||
response = self.client.post(self.url, data, format='json')
|
response = self.client.post(self.url, data, format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
self.assertTrue(ObjektSigurnosti.objects.filter(naziv='test-naziv').exists())
|
||||||
|
|
||||||
|
|
||||||
# Testiranje dohvaćanja pojedinog objekata
|
# Testiranje dohvaćanja pojedinog objekata
|
||||||
|
|||||||
@ -9,29 +9,19 @@ from django.shortcuts import get_object_or_404
|
|||||||
from rest_framework.pagination import LimitOffsetPagination
|
from rest_framework.pagination import LimitOffsetPagination
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CustomObjektSigurnostiPagination(LimitOffsetPagination):
|
class CustomObjektSigurnostiPagination(LimitOffsetPagination):
|
||||||
default_limit = 20
|
default_limit = 20
|
||||||
|
|
||||||
|
|
||||||
class ObjektSigurnostiList(generics.ListCreateAPIView):
|
class ObjektSigurnostiList(generics.ListCreateAPIView):
|
||||||
queryset = ObjektSigurnosti.objects.all().order_by("naziv")
|
queryset = ObjektSigurnosti.objects.all().order_by("naziv")
|
||||||
serializer_class = ObjektSigurnostiSerializer
|
serializer_class = ObjektSigurnostiSerializer
|
||||||
pagination_class = CustomObjektSigurnostiPagination
|
pagination_class = CustomObjektSigurnostiPagination
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
def get_queryset(self):
|
if self.request.method == "GET":
|
||||||
user = self.request.user
|
return ObjektSigurnostiSerializer
|
||||||
return user.accounts.all()
|
return self.serializer_class
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
serializer.save(operater=self.request.user)
|
|
||||||
|
|
||||||
def get_serializer_class(self):
|
|
||||||
if self.request.method == "GET":
|
|
||||||
return ObjektSigurnostiSerializer
|
|
||||||
return self.serializer_class()
|
|
||||||
|
|
||||||
|
|
||||||
class ObjektSigurnostiDetail(generics.RetrieveUpdateDestroyAPIView):
|
class ObjektSigurnostiDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
|||||||
BIN
user/__pycache__/permissions.cpython-38.pyc
Normal file
BIN
user/__pycache__/permissions.cpython-38.pyc
Normal file
Binary file not shown.
BIN
user/__pycache__/serializers.cpython-38.pyc
Normal file
BIN
user/__pycache__/serializers.cpython-38.pyc
Normal file
Binary file not shown.
BIN
user/__pycache__/tests.cpython-38.pyc
Normal file
BIN
user/__pycache__/tests.cpython-38.pyc
Normal file
Binary file not shown.
BIN
user/__pycache__/utils.cpython-38.pyc
Normal file
BIN
user/__pycache__/utils.cpython-38.pyc
Normal file
Binary file not shown.
BIN
user/management/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
user/management/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
@ -0,0 +1,93 @@
|
|||||||
|
# Generated by Django 4.2.9 on 2024-01-18 11:04
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('user', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Organization',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=128)),
|
||||||
|
('contact_email', models.EmailField(blank=True, max_length=254)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='user',
|
||||||
|
options={},
|
||||||
|
),
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name='user',
|
||||||
|
managers=[
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='email_confirmed',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='language_preference',
|
||||||
|
field=models.CharField(choices=[('hr', 'Hrvatski'), ('en', 'English')], default='hr', max_length=8),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='date_joined',
|
||||||
|
field=models.DateTimeField(auto_now_add=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='email',
|
||||||
|
field=models.EmailField(max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='first_name',
|
||||||
|
field=models.CharField(blank=True, max_length=127),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='is_active',
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='is_staff',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='last_name',
|
||||||
|
field=models.CharField(blank=True, max_length=127),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='username',
|
||||||
|
field=models.CharField(blank=True, max_length=255),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='PasswordResetRequest',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('received_on', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('uid', models.UUIDField()),
|
||||||
|
('confirmed', models.BooleanField(default=False)),
|
||||||
|
('confirmed_on', models.DateTimeField(null=True)),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='organization',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='user.organization'),
|
||||||
|
),
|
||||||
|
]
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user