Compare commits
No commits in common. "5a7ea0b6c2c1b615f1336b6d3dc63b42cc8f5e72" and "8f40162974af188761d405e581130bce918f0e9d" have entirely different histories.
5a7ea0b6c2
...
8f40162974
@ -1,7 +0,0 @@
|
|||||||
"""
|
|
||||||
Author: Michel Peltriaux
|
|
||||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
||||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
||||||
Created on: 27.01.22
|
|
||||||
|
|
||||||
"""
|
|
@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "MultiPolygon",
|
|
||||||
"coordinates": [
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"title": "Test_compensation",
|
|
||||||
"is_cef": false,
|
|
||||||
"is_coherence_keeping": false,
|
|
||||||
"intervention": "MUST_BE_SET_IN_TEST",
|
|
||||||
"before_states": [
|
|
||||||
],
|
|
||||||
"after_states": [
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
],
|
|
||||||
"deadlines": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "MultiPolygon",
|
|
||||||
"coordinates": [
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"title": "Test_ecoaccount",
|
|
||||||
"deductable_surface": 10000.0,
|
|
||||||
"responsible": {
|
|
||||||
"conservation_office": null,
|
|
||||||
"conservation_file_number": null,
|
|
||||||
"handler": null
|
|
||||||
},
|
|
||||||
"legal": {
|
|
||||||
"agreement_date": null
|
|
||||||
},
|
|
||||||
"before_states": [
|
|
||||||
],
|
|
||||||
"after_states": [
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
],
|
|
||||||
"deadlines": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "MultiPolygon",
|
|
||||||
"coordinates": [
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"title": "Test_ema",
|
|
||||||
"responsible": {
|
|
||||||
"conservation_office": null,
|
|
||||||
"conservation_file_number": null,
|
|
||||||
"handler": null
|
|
||||||
},
|
|
||||||
"before_states": [
|
|
||||||
],
|
|
||||||
"after_states": [
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
],
|
|
||||||
"deadlines": [
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "MultiPolygon",
|
|
||||||
"coordinates": [
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"title": "Test_intervention",
|
|
||||||
"responsible": {
|
|
||||||
"registration_office": null,
|
|
||||||
"registration_file_number": null,
|
|
||||||
"conservation_office": null,
|
|
||||||
"conservation_file_number": null,
|
|
||||||
"handler": null
|
|
||||||
},
|
|
||||||
"legal": {
|
|
||||||
"registration_date": null,
|
|
||||||
"binding_date": null,
|
|
||||||
"process_type": null,
|
|
||||||
"laws": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
"""
|
|
||||||
Author: Michel Peltriaux
|
|
||||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
||||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
||||||
Created on: 27.01.22
|
|
||||||
|
|
||||||
"""
|
|
||||||
import json
|
|
||||||
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from api.tests.v1.test_api_sharing import BaseAPIV1TestCase
|
|
||||||
|
|
||||||
|
|
||||||
class APIV1CreateTestCase(BaseAPIV1TestCase):
|
|
||||||
@classmethod
|
|
||||||
def setUpTestData(cls):
|
|
||||||
super().setUpTestData()
|
|
||||||
|
|
||||||
def _run_create_request(self, url, data):
|
|
||||||
data = json.dumps(data)
|
|
||||||
response = self.client.post(
|
|
||||||
url,
|
|
||||||
data=data,
|
|
||||||
content_type="application/json",
|
|
||||||
**self.header_data
|
|
||||||
)
|
|
||||||
return response
|
|
||||||
|
|
||||||
def _test_create_object(self, url, post_body):
|
|
||||||
""" Tests the API creation of a new data object.
|
|
||||||
|
|
||||||
Post body data stored in a local json file
|
|
||||||
|
|
||||||
Args:
|
|
||||||
url (str): The api creation url
|
|
||||||
post_body (dict): The post body content as dict
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
response = self._run_create_request(url, post_body)
|
|
||||||
self.assertEqual(response.status_code, 200, msg=response.content)
|
|
||||||
content = json.loads(response.content)
|
|
||||||
self.assertIsNotNone(content.get("id", None), msg=response.content)
|
|
||||||
|
|
||||||
def test_create_intervention(self):
|
|
||||||
""" Tests api creation of bare minimum interventions
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
url = reverse("api:v1:intervention")
|
|
||||||
json_file_path = "api/tests/v1/create/intervention_create_post_body.json"
|
|
||||||
with open(json_file_path) as json_file:
|
|
||||||
post_body = json.load(fp=json_file)
|
|
||||||
self._test_create_object(url, post_body)
|
|
||||||
|
|
||||||
def test_create_compensation(self):
|
|
||||||
""" Tests api creation of bare minimum interventions
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
url = reverse("api:v1:compensation")
|
|
||||||
json_file_path = "api/tests/v1/create/compensation_create_post_body.json"
|
|
||||||
with open(json_file_path) as json_file:
|
|
||||||
post_body = json.load(fp=json_file)
|
|
||||||
post_body["properties"]["intervention"] = str(self.intervention.id)
|
|
||||||
|
|
||||||
# Expect this first request to fail, since user has no shared access on the intervention, we want to create
|
|
||||||
# a compensation for
|
|
||||||
response = self._run_create_request(url, post_body)
|
|
||||||
self.assertEqual(response.status_code, 500, msg=response.content)
|
|
||||||
content = json.loads(response.content)
|
|
||||||
self.assertGreater(len(content.get("errors", [])), 0, msg=response.content)
|
|
||||||
|
|
||||||
# Add the user to the shared users of the intervention and try again! Now everything should work as expected.
|
|
||||||
self.intervention.users.add(self.superuser)
|
|
||||||
self._test_create_object(url, post_body)
|
|
||||||
|
|
||||||
def test_create_eco_account(self):
|
|
||||||
""" Tests api creation of bare minimum interventions
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
url = reverse("api:v1:ecoaccount")
|
|
||||||
json_file_path = "api/tests/v1/create/ecoaccount_create_post_body.json"
|
|
||||||
with open(json_file_path) as json_file:
|
|
||||||
post_body = json.load(fp=json_file)
|
|
||||||
self._test_create_object(url, post_body)
|
|
||||||
|
|
||||||
def test_create_ema(self):
|
|
||||||
""" Tests api creation of bare minimum interventions
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
url = reverse("api:v1:ema")
|
|
||||||
json_file_path = "api/tests/v1/create/ema_create_post_body.json"
|
|
||||||
with open(json_file_path) as json_file:
|
|
||||||
post_body = json.load(fp=json_file)
|
|
||||||
self._test_create_object(url, post_body)
|
|
||||||
|
|
@ -7,11 +7,16 @@ from konova.tests.test_views import BaseTestCase
|
|||||||
from konova.utils.user_checks import is_default_group_only
|
from konova.utils.user_checks import is_default_group_only
|
||||||
|
|
||||||
|
|
||||||
class BaseAPIV1TestCase(BaseTestCase):
|
class APIV1SharingTestCase(BaseTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
super().setUpTestData()
|
""" Creates a test file in memory for using in further tests
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
super().setUpTestData()
|
||||||
cls.superuser.get_API_token()
|
cls.superuser.get_API_token()
|
||||||
cls.superuser.api_token.is_active = True
|
cls.superuser.api_token.is_active = True
|
||||||
cls.superuser.api_token.save()
|
cls.superuser.api_token.save()
|
||||||
@ -22,13 +27,6 @@ class BaseAPIV1TestCase(BaseTestCase):
|
|||||||
"HTTP_ksptoken": cls.superuser.api_token.token,
|
"HTTP_ksptoken": cls.superuser.api_token.token,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class APIV1SharingTestCase(BaseAPIV1TestCase):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpTestData(cls):
|
|
||||||
super().setUpTestData()
|
|
||||||
|
|
||||||
def _run_share_request(self, url, user_list: list):
|
def _run_share_request(self, url, user_list: list):
|
||||||
data = {
|
data = {
|
||||||
"users": user_list
|
"users": user_list
|
||||||
|
@ -123,8 +123,6 @@ class AbstractModelAPISerializer:
|
|||||||
if isinstance(geojson, dict):
|
if isinstance(geojson, dict):
|
||||||
geojson = json.dumps(geojson)
|
geojson = json.dumps(geojson)
|
||||||
geometry = geos.fromstr(geojson)
|
geometry = geos.fromstr(geojson)
|
||||||
if geometry.empty:
|
|
||||||
geometry = None
|
|
||||||
return geometry
|
return geometry
|
||||||
|
|
||||||
def get_obj_from_db(self, id, user):
|
def get_obj_from_db(self, id, user):
|
||||||
|
@ -79,7 +79,7 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensa
|
|||||||
Returns:
|
Returns:
|
||||||
obj (Compensation)
|
obj (Compensation)
|
||||||
"""
|
"""
|
||||||
if obj.intervention is not None and obj.intervention.id == intervention_id:
|
if obj.intervention.id == intervention_id:
|
||||||
# Nothing to do here
|
# Nothing to do here
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ from django.db import transaction
|
|||||||
|
|
||||||
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
||||||
LegalAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin, DeductableAPISerializerV1Mixin
|
LegalAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin, DeductableAPISerializerV1Mixin
|
||||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
|
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
from intervention.models import Legal, Responsibility
|
from intervention.models import Legal, Responsibility
|
||||||
from konova.models import Geometry
|
from konova.models import Geometry
|
||||||
@ -47,26 +46,6 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
"handler": responsible.handler,
|
"handler": responsible.handler,
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_responsibility(self, obj, responsibility_data: dict):
|
|
||||||
""" Sets the responsible data contents to the provided responsibility_data dict
|
|
||||||
|
|
||||||
Args:
|
|
||||||
obj (Intervention): The intervention object
|
|
||||||
responsibility_data (dict): The new data
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
obj
|
|
||||||
"""
|
|
||||||
if responsibility_data is None:
|
|
||||||
return obj
|
|
||||||
obj.responsible.conservation_office = self.konova_code_from_json(
|
|
||||||
responsibility_data["conservation_office"],
|
|
||||||
CODELIST_CONSERVATION_OFFICE_ID,
|
|
||||||
)
|
|
||||||
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
|
||||||
obj.responsible.handler = responsibility_data["handler"]
|
|
||||||
return obj
|
|
||||||
|
|
||||||
def set_legal(self, obj, legal_data):
|
def set_legal(self, obj, legal_data):
|
||||||
obj.legal.registration_date = legal_data.get("agreement_date", None)
|
obj.legal.registration_date = legal_data.get("agreement_date", None)
|
||||||
return obj
|
return obj
|
||||||
@ -116,14 +95,7 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
properties = json_model["properties"]
|
properties = json_model["properties"]
|
||||||
obj.identifier = obj.generate_new_identifier()
|
obj.identifier = obj.generate_new_identifier()
|
||||||
obj.title = properties["title"]
|
obj.title = properties["title"]
|
||||||
|
|
||||||
try:
|
|
||||||
obj.deductable_surface = float(properties["deductable_surface"])
|
obj.deductable_surface = float(properties["deductable_surface"])
|
||||||
except TypeError:
|
|
||||||
raise ValueError("Deductable surface (m²) must be a number >= 0")
|
|
||||||
if obj.deductable_surface < 0:
|
|
||||||
raise ValueError("Deductable surface (m²) must be greater or equal 0")
|
|
||||||
|
|
||||||
obj = self.set_responsibility(obj, properties["responsible"])
|
obj = self.set_responsibility(obj, properties["responsible"])
|
||||||
obj = self.set_legal(obj, properties["legal"])
|
obj = self.set_legal(obj, properties["legal"])
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ from django.db import transaction
|
|||||||
|
|
||||||
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
||||||
ResponsibilityAPISerializerV1Mixin
|
ResponsibilityAPISerializerV1Mixin
|
||||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
|
|
||||||
from ema.models import Ema
|
from ema.models import Ema
|
||||||
from intervention.models import Responsibility
|
from intervention.models import Responsibility
|
||||||
from konova.models import Geometry
|
from konova.models import Geometry
|
||||||
@ -20,13 +19,6 @@ from user.models import UserActionLogEntry
|
|||||||
class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin):
|
class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin):
|
||||||
model = Ema
|
model = Ema
|
||||||
|
|
||||||
def extend_properties_data(self, entry):
|
|
||||||
self.properties_data["responsible"] = self.responsible_to_json(entry.responsible)
|
|
||||||
self.properties_data["before_states"] = self.compensation_state_to_json(entry.before_states.all())
|
|
||||||
self.properties_data["after_states"] = self.compensation_state_to_json(entry.after_states.all())
|
|
||||||
self.properties_data["actions"] = self.compensation_actions_to_json(entry.actions.all())
|
|
||||||
self.properties_data["deadlines"] = self.deadlines_to_json(entry.deadlines.all())
|
|
||||||
|
|
||||||
def responsible_to_json(self, responsible: Responsibility):
|
def responsible_to_json(self, responsible: Responsibility):
|
||||||
return {
|
return {
|
||||||
"conservation_office": self.konova_code_to_json(responsible.conservation_office),
|
"conservation_office": self.konova_code_to_json(responsible.conservation_office),
|
||||||
@ -34,25 +26,12 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
|||||||
"handler": responsible.handler,
|
"handler": responsible.handler,
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_responsibility(self, obj, responsibility_data: dict):
|
def extend_properties_data(self, entry):
|
||||||
""" Sets the responsible data contents to the provided responsibility_data dict
|
self.properties_data["responsible"] = self.responsible_to_json(entry.responsible)
|
||||||
|
self.properties_data["before_states"] = self.compensation_state_to_json(entry.before_states.all())
|
||||||
Args:
|
self.properties_data["after_states"] = self.compensation_state_to_json(entry.after_states.all())
|
||||||
obj (Intervention): The intervention object
|
self.properties_data["actions"] = self.compensation_actions_to_json(entry.actions.all())
|
||||||
responsibility_data (dict): The new data
|
self.properties_data["deadlines"] = self.deadlines_to_json(entry.deadlines.all())
|
||||||
|
|
||||||
Returns:
|
|
||||||
obj
|
|
||||||
"""
|
|
||||||
if responsibility_data is None:
|
|
||||||
return obj
|
|
||||||
obj.responsible.conservation_office = self.konova_code_from_json(
|
|
||||||
responsibility_data["conservation_office"],
|
|
||||||
CODELIST_CONSERVATION_OFFICE_ID,
|
|
||||||
)
|
|
||||||
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
|
||||||
obj.responsible.handler = responsibility_data["handler"]
|
|
||||||
return obj
|
|
||||||
|
|
||||||
def initialize_objects(self, json_model, user):
|
def initialize_objects(self, json_model, user):
|
||||||
""" Initializes all needed objects from the json_model data
|
""" Initializes all needed objects from the json_model data
|
||||||
|
@ -168,16 +168,16 @@ class ResponsibilityAPISerializerV1Mixin:
|
|||||||
if responsibility_data is None:
|
if responsibility_data is None:
|
||||||
return obj
|
return obj
|
||||||
obj.responsible.registration_office = self.konova_code_from_json(
|
obj.responsible.registration_office = self.konova_code_from_json(
|
||||||
responsibility_data["registration_office"],
|
responsibility_data.get("registration_office", None),
|
||||||
CODELIST_REGISTRATION_OFFICE_ID
|
CODELIST_REGISTRATION_OFFICE_ID
|
||||||
)
|
)
|
||||||
obj.responsible.registration_file_number = responsibility_data["registration_file_number"]
|
obj.responsible.registration_file_number = responsibility_data.get("registration_file_number", None)
|
||||||
obj.responsible.conservation_office = self.konova_code_from_json(
|
obj.responsible.conservation_office = self.konova_code_from_json(
|
||||||
responsibility_data["conservation_office"],
|
responsibility_data.get("conservation_office", None),
|
||||||
CODELIST_CONSERVATION_OFFICE_ID,
|
CODELIST_CONSERVATION_OFFICE_ID,
|
||||||
)
|
)
|
||||||
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
obj.responsible.conservation_file_number = responsibility_data.get("conservation_file_number", None)
|
||||||
obj.responsible.handler = responsibility_data["handler"]
|
obj.responsible.handler = responsibility_data.get("handler", None)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
|||||||
z_l = v_zoom
|
z_l = v_zoom
|
||||||
break
|
break
|
||||||
zoom_lvl = z_l
|
zoom_lvl = z_l
|
||||||
except (AttributeError, IndexError) as e:
|
except AttributeError:
|
||||||
# If no geometry has been added, yet.
|
# If no geometry has been added, yet.
|
||||||
x = 1
|
x = 1
|
||||||
y = 1
|
y = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user