bugfix enum format
fixed required case fixed more default occurrances changed validates signature
This commit is contained in:
parent
62bd6304c4
commit
14cfb41591
@ -201,7 +201,7 @@ class Participant(Schema):
|
|||||||
ports: List[int] = field(default_factory=list)
|
ports: List[int] = field(default_factory=list)
|
||||||
|
|
||||||
@validates("type")
|
@validates("type")
|
||||||
def validate_type(self, value):
|
def validate_type(self, value, **kwargs):
|
||||||
# e.g., when an IntFlag has the values 1,2,4; the maximum valid value is 7
|
# e.g., when an IntFlag has the values 1,2,4; the maximum valid value is 7
|
||||||
max_int = sum([int(val) for val in list(ParticipantType._value2member_map_.values())])
|
max_int = sum([int(val) for val in list(ParticipantType._value2member_map_.values())])
|
||||||
min_int = 0
|
min_int = 0
|
||||||
@ -212,7 +212,7 @@ class Participant(Schema):
|
|||||||
|
|
||||||
|
|
||||||
@validates("flags")
|
@validates("flags")
|
||||||
def validate_flags(self, value):
|
def validate_flags(self, value, **kwargs):
|
||||||
# e.g., when an IntFlag has the values 1,2,4; the maximum valid value is 7
|
# e.g., when an IntFlag has the values 1,2,4; the maximum valid value is 7
|
||||||
max_int = sum([int(val) for val in list(ParticipantFlag._value2member_map_.values())])
|
max_int = sum([int(val) for val in list(ParticipantFlag._value2member_map_.values())])
|
||||||
min_int = 0
|
min_int = 0
|
||||||
@ -237,7 +237,7 @@ class ShipcallSchema(Schema):
|
|||||||
id = fields.Integer(required=True)
|
id = fields.Integer(required=True)
|
||||||
ship_id = fields.Integer(required=True)
|
ship_id = fields.Integer(required=True)
|
||||||
port_id = fields.Integer(required=True)
|
port_id = fields.Integer(required=True)
|
||||||
type = fields.Enum(ShipcallType, default=ShipcallType.undefined)
|
type = fields.Enum(ShipcallType, load_default=ShipcallType.undefined, dump_default=ShipcallType.undefined)
|
||||||
eta = fields.DateTime(required=False, allow_none=True)
|
eta = fields.DateTime(required=False, allow_none=True)
|
||||||
voyage = fields.String(allow_none=True, required=False, validate=[validate.Length(max=16)])
|
voyage = fields.String(allow_none=True, required=False, validate=[validate.Length(max=16)])
|
||||||
etd = fields.DateTime(required=False, allow_none=True)
|
etd = fields.DateTime(required=False, allow_none=True)
|
||||||
@ -258,7 +258,7 @@ class ShipcallSchema(Schema):
|
|||||||
anchored = fields.Bool(required=False, allow_none=True)
|
anchored = fields.Bool(required=False, allow_none=True)
|
||||||
moored_lock = fields.Bool(required=False, allow_none=True)
|
moored_lock = fields.Bool(required=False, allow_none=True)
|
||||||
canceled = fields.Bool(required=False, allow_none=True)
|
canceled = fields.Bool(required=False, allow_none=True)
|
||||||
evaluation = fields.Enum(EvaluationType, required=False, allow_none=True, default=EvaluationType.undefined)
|
evaluation = fields.Enum(EvaluationType, required=False, allow_none=True, load_default=EvaluationType.undefined, dump_default=ShipcallType.undefined)
|
||||||
evaluation_message = fields.Str(allow_none=True, required=False)
|
evaluation_message = fields.Str(allow_none=True, required=False)
|
||||||
evaluation_time = fields.DateTime(required=False, allow_none=True)
|
evaluation_time = fields.DateTime(required=False, allow_none=True)
|
||||||
evaluation_notifications_sent = fields.Bool(required=False, allow_none=True)
|
evaluation_notifications_sent = fields.Bool(required=False, allow_none=True)
|
||||||
@ -281,7 +281,7 @@ class ShipcallSchema(Schema):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@validates("type")
|
@validates("type")
|
||||||
def validate_type(self, value):
|
def validate_type(self, value, **kwargs):
|
||||||
valid_shipcall_type = int(value) in [item.value for item in ShipcallType]
|
valid_shipcall_type = int(value) in [item.value for item in ShipcallType]
|
||||||
|
|
||||||
if not valid_shipcall_type:
|
if not valid_shipcall_type:
|
||||||
@ -418,7 +418,7 @@ class TimesSchema(Schema):
|
|||||||
berth_info = fields.String(required=False, allow_none=True, validate=[validate.Length(max=512)])
|
berth_info = fields.String(required=False, allow_none=True, validate=[validate.Length(max=512)])
|
||||||
pier_side = fields.Bool(required=False, allow_none = True)
|
pier_side = fields.Bool(required=False, allow_none = True)
|
||||||
shipcall_id = fields.Integer(required=True)
|
shipcall_id = fields.Integer(required=True)
|
||||||
participant_type = fields.Integer(Required = False, allow_none=True)# TODO: could become Enum. # participant_type = fields.Enum(ParticipantType, required=False, allow_none=True, default=ParticipantType.undefined) #fields.Integer(required=False, allow_none=True)
|
participant_type = fields.Integer(required = False, allow_none=True) # TODO: could become Enum
|
||||||
ata = fields.DateTime(required=False, allow_none=True)
|
ata = fields.DateTime(required=False, allow_none=True)
|
||||||
atd = fields.DateTime(required=False, allow_none=True)
|
atd = fields.DateTime(required=False, allow_none=True)
|
||||||
eta_interval_end = fields.DateTime(required=False, allow_none=True)
|
eta_interval_end = fields.DateTime(required=False, allow_none=True)
|
||||||
@ -427,7 +427,7 @@ class TimesSchema(Schema):
|
|||||||
modified = fields.DateTime(required=False, allow_none=True)
|
modified = fields.DateTime(required=False, allow_none=True)
|
||||||
|
|
||||||
@validates("participant_type")
|
@validates("participant_type")
|
||||||
def validate_participant_type(self, value):
|
def validate_participant_type(self, value, **kwargs):
|
||||||
# #TODO: it may also make sense to block multi-assignments, whereas a value could be BSMD+AGENCY
|
# #TODO: it may also make sense to block multi-assignments, whereas a value could be BSMD+AGENCY
|
||||||
# while the validation fails when one of those multi-assignments is BSMD, it passes in cases,
|
# while the validation fails when one of those multi-assignments is BSMD, it passes in cases,
|
||||||
# such as AGENCY+PILOT
|
# such as AGENCY+PILOT
|
||||||
@ -440,56 +440,56 @@ class TimesSchema(Schema):
|
|||||||
raise ValidationError({"participant_type":f"the participant_type must not be .BSMD"})
|
raise ValidationError({"participant_type":f"the participant_type must not be .BSMD"})
|
||||||
|
|
||||||
@validates("eta_berth")
|
@validates("eta_berth")
|
||||||
def validate_eta_berth(self, value):
|
def validate_eta_berth(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
return
|
||||||
|
|
||||||
@validates("etd_berth")
|
@validates("etd_berth")
|
||||||
def validate_etd_berth(self, value):
|
def validate_etd_berth(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
return
|
||||||
|
|
||||||
@validates("lock_time")
|
@validates("lock_time")
|
||||||
def validate_lock_time(self, value):
|
def validate_lock_time(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
return
|
||||||
|
|
||||||
@validates("zone_entry")
|
@validates("zone_entry")
|
||||||
def validate_zone_entry(self, value):
|
def validate_zone_entry(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
return
|
||||||
|
|
||||||
@validates("operations_start")
|
@validates("operations_start")
|
||||||
def validate_operations_start(self, value):
|
def validate_operations_start(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
return
|
||||||
|
|
||||||
@validates("operations_end")
|
@validates("operations_end")
|
||||||
def validate_operations_end(self, value):
|
def validate_operations_end(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
return
|
||||||
|
|
||||||
@validates("eta_interval_end")
|
@validates("eta_interval_end")
|
||||||
def validate_eta_interval_end(self, value):
|
def validate_eta_interval_end(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
return
|
return
|
||||||
|
|
||||||
@validates("etd_interval_end")
|
@validates("etd_interval_end")
|
||||||
def validate_etd_interval_end(self, value):
|
def validate_etd_interval_end(self, value, **kwargs):
|
||||||
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
# violation when time is not in the future, but also does not exceed a threshold for the 'reasonable' future
|
||||||
# when 'value' is 'None', a ValidationError is not issued.
|
# when 'value' is 'None', a ValidationError is not issued.
|
||||||
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
valid_time = validate_time_is_in_not_too_distant_future(raise_validation_error=True, value=value, months=12)
|
||||||
@ -516,14 +516,14 @@ class UserSchema(Schema):
|
|||||||
notify_on = fields.List(fields.Enum(NotificationType), required=False, allow_none=True)
|
notify_on = fields.List(fields.Enum(NotificationType), required=False, allow_none=True)
|
||||||
|
|
||||||
@validates("user_phone")
|
@validates("user_phone")
|
||||||
def validate_user_phone(self, value):
|
def validate_user_phone(self, value, **kwargs):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
valid_characters = list(map(str,range(0,10)))+["+", " "]
|
valid_characters = list(map(str,range(0,10)))+["+", " "]
|
||||||
if not all([v in valid_characters for v in value]):
|
if not all([v in valid_characters for v in value]):
|
||||||
raise ValidationError({"user_phone":f"one of the phone number values is not valid."})
|
raise ValidationError({"user_phone":f"one of the phone number values is not valid."})
|
||||||
|
|
||||||
@validates("user_email")
|
@validates("user_email")
|
||||||
def validate_user_email(self, value):
|
def validate_user_email(self, value, **kwargs):
|
||||||
if value and not re.match(r"[^@]+@[^@]+\.[^@]+", value):
|
if value and not re.match(r"[^@]+@[^@]+\.[^@]+", value):
|
||||||
raise ValidationError({"user_email":f"invalid email address"})
|
raise ValidationError({"user_email":f"invalid email address"})
|
||||||
|
|
||||||
@ -612,15 +612,15 @@ class ShipSchema(Schema):
|
|||||||
participant_id = fields.Int(allow_none=True, required=False)
|
participant_id = fields.Int(allow_none=True, required=False)
|
||||||
length = fields.Float(allow_none=True, required=False, validate=[validate.Range(min=0, max=1000, min_inclusive=False, max_inclusive=False)])
|
length = fields.Float(allow_none=True, required=False, validate=[validate.Range(min=0, max=1000, min_inclusive=False, max_inclusive=False)])
|
||||||
width = fields.Float(allow_none=True, required=False, validate=[validate.Range(min=0, max=100, min_inclusive=False, max_inclusive=False)])
|
width = fields.Float(allow_none=True, required=False, validate=[validate.Range(min=0, max=100, min_inclusive=False, max_inclusive=False)])
|
||||||
is_tug = fields.Bool(allow_none=True, required=False, default=False)
|
is_tug = fields.Bool(allow_none=True, required=False, load_default=False, dump_default=False)
|
||||||
bollard_pull = fields.Int(allow_none=True, required=False)
|
bollard_pull = fields.Int(allow_none=True, required=False)
|
||||||
eni = fields.Int(allow_none=True, required=False)
|
eni = fields.Int(allow_none=True, required=False)
|
||||||
created = fields.DateTime(allow_none=True, required=False)
|
created = fields.DateTime(allow_none=True, required=False)
|
||||||
modified = fields.DateTime(allow_none=True, required=False)
|
modified = fields.DateTime(allow_none=True, required=False)
|
||||||
deleted = fields.Bool(allow_none=True, required=False, default=False)
|
deleted = fields.Bool(allow_none=True, required=False, load_default=False, dump_default=False)
|
||||||
|
|
||||||
@validates("name")
|
@validates("name")
|
||||||
def validate_name(self, value):
|
def validate_name(self, value, **kwargs):
|
||||||
character_length = len(str(value))
|
character_length = len(str(value))
|
||||||
if character_length<1:
|
if character_length<1:
|
||||||
raise ValidationError({"name":f"'name' argument should have at least one character"})
|
raise ValidationError({"name":f"'name' argument should have at least one character"})
|
||||||
@ -632,7 +632,7 @@ class ShipSchema(Schema):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@validates("imo")
|
@validates("imo")
|
||||||
def validate_imo(self, value):
|
def validate_imo(self, value, **kwargs):
|
||||||
value = str(value).zfill(7) # 1 becomes '0000001' (7 characters). 12345678 becomes '12345678' (8 characters)
|
value = str(value).zfill(7) # 1 becomes '0000001' (7 characters). 12345678 becomes '12345678' (8 characters)
|
||||||
imo_length = len(value)
|
imo_length = len(value)
|
||||||
if imo_length != 7:
|
if imo_length != 7:
|
||||||
@ -640,7 +640,7 @@ class ShipSchema(Schema):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@validates("callsign")
|
@validates("callsign")
|
||||||
def validate_callsign(self, value):
|
def validate_callsign(self, value, **kwargs):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
callsign_length = len(str(value))
|
callsign_length = len(str(value))
|
||||||
if callsign_length>8:
|
if callsign_length>8:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user