diff --git a/src/server/BreCal/validators/validation_rule_functions.py b/src/server/BreCal/validators/validation_rule_functions.py index c8f00c6..0e17bbf 100644 --- a/src/server/BreCal/validators/validation_rule_functions.py +++ b/src/server/BreCal/validators/validation_rule_functions.py @@ -54,6 +54,7 @@ class ValidationRuleBaseFunctions(): self.sql_handler = sql_handler self.time_logic = TimeLogic() self.error_message_dict = error_message_dict + self.ignore_port_administration_flag = True # flag: turn off all port administration validation rules def describe_error_message(self, key)->str: """ @@ -127,7 +128,10 @@ class ValidationRuleBaseFunctions(): return violation_state # filter by participant types of interest (agency, mooring, portauthority/administration, pilot, tug) - participant_types = [ParticipantType.AGENCY.value, ParticipantType.MOORING.value, ParticipantType.PORT_ADMINISTRATION.value, ParticipantType.PILOT.value, ParticipantType.TUG.value] + if not self.ignore_port_administration_flag: + participant_types = [ParticipantType.AGENCY.value, ParticipantType.MOORING.value, ParticipantType.PORT_ADMINISTRATION.value, ParticipantType.PILOT.value, ParticipantType.TUG.value] + else: + participant_types = [ParticipantType.AGENCY.value, ParticipantType.MOORING.value, ParticipantType.PORT_ADMINISTRATION.value, ParticipantType.PILOT.value, ParticipantType.TUG.value] df_times = df_times.loc[df_times["participant_type"].isin(participant_types),:] # exclude missing entries and consider only pd.Timestamp entries (which ignores pd.NaT/null entries) @@ -326,6 +330,9 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): - Checks, if times_port_administration.eta_berth is filled in. - Measures the difference between 'now' and 'times_agency.eta_berth'. """ + if self.ignore_port_administration_flag: + return self.get_no_violation_default_output() + # check, if the header is filled in (agency & PORT_ADMINISTRATION) if (len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1) or (len(df_times.loc[df_times["participant_type"]==ParticipantType.PORT_ADMINISTRATION.value]) != 1): return self.get_no_violation_default_output() @@ -356,6 +363,9 @@ class ValidationRuleFunctions(ValidationRuleBaseFunctions): - Checks, if times_port_administration.etd_berth is filled in. - Measures the difference between 'now' and 'times_agency.etd_berth'. """ + if self.ignore_port_administration_flag: + return self.get_no_violation_default_output() + # check, if the header is filled in (agency & PORT_ADMINISTRATION) if (len(df_times.loc[df_times["participant_type"]==ParticipantType.AGENCY.value]) != 1) or (len(df_times.loc[df_times["participant_type"]==ParticipantType.PORT_ADMINISTRATION.value]) != 1): return self.get_no_violation_default_output() diff --git a/src/server/tests/validators/test_validation_rule_functions.py b/src/server/tests/validators/test_validation_rule_functions.py index 1847973..aac0f44 100644 --- a/src/server/tests/validators/test_validation_rule_functions.py +++ b/src/server/tests/validators/test_validation_rule_functions.py @@ -244,8 +244,10 @@ def test_validation_rule_fct_missing_time_portadministration_berth_eta__shipcall # apply the validation rule (state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_eta(shipcall=shipcall, df_times=df_times) - # expectation: green state, no msg - assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + if not vr.ignore_port_administration_flag: + assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + else: + assert state==StatusFlags.GREEN, f"function should return 'green', because the feature flag is set, which disables this validation rule" return @@ -266,8 +268,10 @@ def test_validation_rule_fct_missing_time_portadministration_berth_etd__shipcall # apply the validation rule (state, msg) = vr.validation_rule_fct_missing_time_portadministration_berth_etd(shipcall=shipcall, df_times=df_times) - # expectation: green state, no msg - assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + if not vr.ignore_port_administration_flag: + assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" + else: + assert state==StatusFlags.GREEN, f"function should return 'green', because the ignore flag is set" return def test_validation_rule_fct_missing_time_pilot_berth_eta__shipcall_soon_but_participant_estimated_time_undefined(build_sql_proxy_connection): @@ -286,7 +290,7 @@ def test_validation_rule_fct_missing_time_pilot_berth_eta__shipcall_soon_but_par # apply the validation rule (state, msg) = vr.validation_rule_fct_missing_time_pilot_berth_eta(shipcall=shipcall, df_times=df_times) - # expectation: green state, no msg + # expectation: yellow state assert state==StatusFlags.YELLOW, f"function should return 'yellow', because the participant did not provide a time and the shipcall takes place soon (according to the agency)" return