Merge branch 'feature/test_server_1.5' into feature/extra_time_logic
This commit is contained in:
commit
7ba5633463
@ -127,9 +127,8 @@ class InputValidationShipcall():
|
|||||||
if is_put_data:
|
if is_put_data:
|
||||||
# the type of a shipcall may not be changed. It can only be set with the initial POST-request.
|
# the type of a shipcall may not be changed. It can only be set with the initial POST-request.
|
||||||
InputValidationShipcall.check_shipcall_type_is_unchanged(loadedModel)
|
InputValidationShipcall.check_shipcall_type_is_unchanged(loadedModel)
|
||||||
else:
|
|
||||||
# time values must use future-dates
|
InputValidationShipcall.check_times_are_in_future(loadedModel, content)
|
||||||
InputValidationShipcall.check_times_are_in_future(loadedModel, content)
|
|
||||||
|
|
||||||
# some arguments must not be provided
|
# some arguments must not be provided
|
||||||
InputValidationShipcall.check_forbidden_arguments(content, forbidden_keys=forbidden_keys)
|
InputValidationShipcall.check_forbidden_arguments(content, forbidden_keys=forbidden_keys)
|
||||||
@ -328,7 +327,7 @@ class InputValidationShipcall():
|
|||||||
def check_times_are_in_future(loadedModel:dict, content:dict):
|
def check_times_are_in_future(loadedModel:dict, content:dict):
|
||||||
"""
|
"""
|
||||||
Dates should be in the future. Depending on the ShipcallType, specific values should be checked
|
Dates should be in the future. Depending on the ShipcallType, specific values should be checked
|
||||||
Perfornms datetime checks in the loadedModel (datetime.datetime objects).
|
Performs datetime checks in the loadedModel (datetime.datetime objects).
|
||||||
"""
|
"""
|
||||||
# obtain the current datetime to check, whether the provided values are after ref time
|
# obtain the current datetime to check, whether the provided values are after ref time
|
||||||
time_ref = datetime.datetime.now() - datetime.timedelta(days=1)
|
time_ref = datetime.datetime.now() - datetime.timedelta(days=1)
|
||||||
@ -367,6 +366,8 @@ class InputValidationShipcall():
|
|||||||
if (eta is None) and (etd is None):
|
if (eta is None) and (etd is None):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
time_in_a_year = datetime.datetime.now().replace(datetime.datetime.now().year + 1)
|
||||||
|
|
||||||
if type_ is None:
|
if type_ is None:
|
||||||
raise ValidationError({"type":f"when providing 'eta' or 'etd', one must provide the type of the shipcall, so the datetimes can be verified."})
|
raise ValidationError({"type":f"when providing 'eta' or 'etd', one must provide the type of the shipcall, so the datetimes can be verified."})
|
||||||
|
|
||||||
@ -384,6 +385,8 @@ class InputValidationShipcall():
|
|||||||
raise ValidationError({"eta":f"'eta' is too far in the past. Incorrect datetime provided. Current Time: {time_ref}. ETA: {eta}."})
|
raise ValidationError({"eta":f"'eta' is too far in the past. Incorrect datetime provided. Current Time: {time_ref}. ETA: {eta}."})
|
||||||
if etd is not None:
|
if etd is not None:
|
||||||
raise ValidationError({"etd":f"'etd' should not be set when the shipcall type is 'arrival'."})
|
raise ValidationError({"etd":f"'etd' should not be set when the shipcall type is 'arrival'."})
|
||||||
|
if eta > time_in_a_year:
|
||||||
|
raise ValidationError({"eta":f"'eta' is more than a year in the future. ETA: {eta}."})
|
||||||
|
|
||||||
elif int(type_)==int(ShipcallType.departure):
|
elif int(type_)==int(ShipcallType.departure):
|
||||||
if etd is None: # null values -> no violation
|
if etd is None: # null values -> no violation
|
||||||
@ -394,6 +397,8 @@ class InputValidationShipcall():
|
|||||||
|
|
||||||
if eta is not None:
|
if eta is not None:
|
||||||
raise ValidationError({"eta":f"'eta' should not be set when the shipcall type is 'departure'."})
|
raise ValidationError({"eta":f"'eta' should not be set when the shipcall type is 'departure'."})
|
||||||
|
if etd > time_in_a_year:
|
||||||
|
raise ValidationError({"etd":f"'etd' is more than a year in the future. ETD: {etd}."})
|
||||||
|
|
||||||
elif int(type_)==int(ShipcallType.shifting):
|
elif int(type_)==int(ShipcallType.shifting):
|
||||||
if (eta is None) and (etd is None): # null values -> no violation
|
if (eta is None) and (etd is None): # null values -> no violation
|
||||||
@ -411,21 +416,36 @@ class InputValidationShipcall():
|
|||||||
|
|
||||||
if (eta is not None and etd is None) or (eta is None and etd is not None):
|
if (eta is not None and etd is None) or (eta is None and etd is not None):
|
||||||
raise ValidationError({"eta_or_etd":f"'eta' and 'etd' must both be provided when the shipcall type is 'shifting'."})
|
raise ValidationError({"eta_or_etd":f"'eta' and 'etd' must both be provided when the shipcall type is 'shifting'."})
|
||||||
|
if eta > time_in_a_year:
|
||||||
|
raise ValidationError({"eta":f"'eta' is more than a year in the future. ETA: {eta}."})
|
||||||
|
if etd > time_in_a_year:
|
||||||
|
raise ValidationError({"etd":f"'etd' is more than a year in the future. ETD: {etd}."})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_tidal_window_in_future(type_, time_ref, tidal_window_from, tidal_window_to):
|
def check_tidal_window_in_future(type_, time_ref, tidal_window_from, tidal_window_to):
|
||||||
|
|
||||||
|
time_in_a_year = datetime.datetime.now().replace(datetime.datetime.now().year + 1)
|
||||||
if tidal_window_to is not None:
|
if tidal_window_to is not None:
|
||||||
if not tidal_window_to >= time_ref:
|
if not tidal_window_to >= time_ref:
|
||||||
raise ValidationError({"tidal_window_to":f"'tidal_window_to' is too far in the past. Incorrect datetime provided."})
|
raise ValidationError({"tidal_window_to":f"'tidal_window_to' is too far in the past. Incorrect datetime provided."})
|
||||||
|
if tidal_window_to > time_in_a_year:
|
||||||
|
raise ValidationError({"tidal_window_to":f"'tidal_window_to' is more than a year in the future. Found: {tidal_window_to}."})
|
||||||
|
|
||||||
if tidal_window_from is not None:
|
if tidal_window_from is not None:
|
||||||
if not tidal_window_from >= time_ref:
|
if not tidal_window_from >= time_ref:
|
||||||
raise ValidationError({"tidal_window_from":f"'tidal_window_from' is too far in the past. Incorrect datetime provided."})
|
raise ValidationError({"tidal_window_from":f"'tidal_window_from' is too far in the past. Incorrect datetime provided."})
|
||||||
|
if tidal_window_from > time_in_a_year:
|
||||||
|
raise ValidationError({"tidal_window_from":f"'tidal_window_from' is more than a year in the future. Found: {tidal_window_from}."})
|
||||||
|
|
||||||
if (tidal_window_to is not None) and (tidal_window_from is not None):
|
if (tidal_window_to is not None) and (tidal_window_from is not None):
|
||||||
if tidal_window_to < tidal_window_from:
|
if tidal_window_to < tidal_window_from:
|
||||||
raise ValidationError({"tidal_window_to_or_tidal_window_from":f"'tidal_window_to' must take place after 'tidal_window_from'. Incorrect datetime provided. Found 'tidal_window_to': {tidal_window_to}, 'tidal_window_from': {tidal_window_to}."})
|
raise ValidationError({"tidal_window_to_or_tidal_window_from":f"'tidal_window_to' must take place after 'tidal_window_from'. Incorrect datetime provided. Found 'tidal_window_to': {tidal_window_to}, 'tidal_window_from': {tidal_window_to}."})
|
||||||
|
|
||||||
|
if (tidal_window_to is not None and tidal_window_from is None) or (tidal_window_to is None and tidal_window_from is not None):
|
||||||
|
raise ValidationError({"tidal_window_to_or_tidal_window_from":f"'tidal_window_to' and 'tidal_window_from' must both be provided."})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -124,7 +124,8 @@ class InputValidationTimes():
|
|||||||
InputValidationTimes.check_if_entry_is_already_deleted(times_id)
|
InputValidationTimes.check_if_entry_is_already_deleted(times_id)
|
||||||
|
|
||||||
# 2.) Only users of the same participant_id, which the times dataset refers to, can delete the entry
|
# 2.) Only users of the same participant_id, which the times dataset refers to, can delete the entry
|
||||||
InputValidationTimes.check_user_belongs_to_same_group_as_dataset_determines(user_data, loadedModel=None, times_id=times_id)
|
if not check_if_user_is_bsmd_type(user_data):
|
||||||
|
InputValidationTimes.check_user_belongs_to_same_group_as_dataset_determines(user_data, loadedModel=None, times_id=times_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -41,7 +41,7 @@ def unbundle_validation_error_message(message):
|
|||||||
unbundle_(message, unbundled=unbundled)
|
unbundle_(message, unbundled=unbundled)
|
||||||
if len(unbundled)>0:
|
if len(unbundled)>0:
|
||||||
error_field = "ValidationError in the following field(s): " + " & ".join([unb["error_field"] for unb in unbundled])
|
error_field = "ValidationError in the following field(s): " + " & ".join([unb["error_field"] for unb in unbundled])
|
||||||
error_description = "Error Description(s): " + " & ".join([unb["error_description"] for unb in unbundled])
|
error_description = " " . join([unb["error_description"] for unb in unbundled])
|
||||||
else:
|
else:
|
||||||
error_field = "ValidationError"
|
error_field = "ValidationError"
|
||||||
error_description = "unknown validation error"
|
error_description = "unknown validation error"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user