#31 API Tests
* adds creation tests with minimum data for intervention, compensation, ema and ecoaccount * fixes bug where empty geometry would not be created properly using the API * reworks key fetching from POST data, so inproperly stated keys will lead to an error for the API user, instead of silently working and use default data * adds some logical checks for deductable_surface of eco account creation using api * fixes bug that would have occured on creating compensations via api
This commit is contained in:
@@ -9,6 +9,7 @@ from django.db import transaction
|
||||
|
||||
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
||||
ResponsibilityAPISerializerV1Mixin
|
||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
|
||||
from ema.models import Ema
|
||||
from intervention.models import Responsibility
|
||||
from konova.models import Geometry
|
||||
@@ -19,6 +20,13 @@ from user.models import UserActionLogEntry
|
||||
class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin):
|
||||
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):
|
||||
return {
|
||||
"conservation_office": self.konova_code_to_json(responsible.conservation_office),
|
||||
@@ -26,12 +34,25 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
||||
"handler": responsible.handler,
|
||||
}
|
||||
|
||||
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 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 initialize_objects(self, json_model, user):
|
||||
""" Initializes all needed objects from the json_model data
|
||||
|
||||
Reference in New Issue
Block a user