created a feature flag, which disables the PORT_ADMINISTRATION validation rules. Currently, the flag is 'hardcoded' once in the library. Adapting the test to properly facilitate the feature flag

This commit is contained in:
scopesorting 2023-12-12 13:20:31 +01:00
parent ecdf66bff2
commit aa1512c802
2 changed files with 20 additions and 6 deletions

View File

@ -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,6 +128,9 @@ class ValidationRuleBaseFunctions():
return violation_state
# filter by participant types of interest (agency, mooring, portauthority/administration, pilot, tug)
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),:]
@ -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()

View File

@ -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
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
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