Added validation for length of breaks <= length of activity
This commit is contained in:
parent
3baaa02ff8
commit
a16e1f1fc9
2 changed files with 49 additions and 20 deletions
|
|
@ -205,19 +205,27 @@ class FormData:
|
|||
# Validate lunch time within the activity times.
|
||||
def validate_lunch(start, finish, time):
|
||||
return start < time < finish
|
||||
if (self.exposed_lunch_option and (
|
||||
not validate_lunch(self.exposed_start, self.exposed_finish, self.exposed_lunch_start) or
|
||||
not validate_lunch(self.exposed_start, self.exposed_finish, self.exposed_lunch_finish))):
|
||||
raise ValueError(
|
||||
"Exposed lunch break must be within presence times."
|
||||
)
|
||||
|
||||
if (self.infected_dont_have_breaks_with_exposed and self.infected_lunch_option and (
|
||||
not validate_lunch(self.infected_start, self.infected_finish, self.infected_lunch_start) or
|
||||
not validate_lunch(self.infected_start, self.infected_finish, self.infected_lunch_finish))):
|
||||
raise ValueError(
|
||||
"Infected lunch break must be within presence times."
|
||||
)
|
||||
populations = ['exposed', 'infected'] if self.infected_dont_have_breaks_with_exposed else ['exposed']
|
||||
for population in populations:
|
||||
|
||||
if (getattr(self, f'{population}_lunch_option') and (
|
||||
not validate_lunch(getattr(self, f'{population}_start'), getattr(self, f'{population}_finish'), getattr(self, f'{population}_lunch_start')) or
|
||||
not validate_lunch(getattr(self, f'{population}_start'), getattr(self, f'{population}_finish'), getattr(self, f'{population}_lunch_finish')))):
|
||||
raise ValueError(
|
||||
f"{population} lunch break must be within presence times."
|
||||
)
|
||||
|
||||
# Length of breaks < length of activity
|
||||
lunch_mins, coffee_mins = 0, 0
|
||||
if getattr(self, f'{population}_lunch_option'):
|
||||
lunch_mins = getattr(self, f'{population}_lunch_finish') - getattr(self, f'{population}_lunch_start')
|
||||
if getattr(self, f'{population}_coffee_break_option') != 'coffee_break_0':
|
||||
coffee_mins = COFFEE_OPTIONS_INT[getattr(self, f'{population}_coffee_break_option')] * getattr(self, f'{population}_coffee_duration')
|
||||
if (lunch_mins + coffee_mins) >= (getattr(self, f'{population}_finish') - getattr(self, f'{population}_start')) :
|
||||
raise ValueError(
|
||||
f"Length of breaks >= Length of {population} presence."
|
||||
)
|
||||
|
||||
validation_tuples = [('activity_type', ACTIVITY_TYPES),
|
||||
('exposed_coffee_break_option', COFFEE_OPTIONS_INT),
|
||||
|
|
|
|||
|
|
@ -257,53 +257,74 @@ def test_exposed_present_lunch_end_before_beginning(baseline_form: model_generat
|
|||
|
||||
def test_exposed_presence_lunch_start_before_begining(baseline_form: model_generator.FormData):
|
||||
baseline_form.exposed_lunch_start = minutes_since_midnight(8 * 60)
|
||||
with pytest.raises(ValueError, match='Exposed lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='exposed lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_exposed_presence_lunch_start_after_finishing(baseline_form: model_generator.FormData):
|
||||
baseline_form.exposed_lunch_start = minutes_since_midnight(19 * 60)
|
||||
baseline_form.exposed_lunch_finish = minutes_since_midnight(20 * 60)
|
||||
with pytest.raises(ValueError, match='Exposed lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='exposed lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_exposed_presence_lunch_finish_before_begining(baseline_form: model_generator.FormData):
|
||||
baseline_form.exposed_lunch_start = minutes_since_midnight(7 * 60)
|
||||
baseline_form.exposed_lunch_finish = minutes_since_midnight(8 * 60)
|
||||
with pytest.raises(ValueError, match='Exposed lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='exposed lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_exposed_presence_lunch_finish_after_finishing(baseline_form: model_generator.FormData):
|
||||
baseline_form.exposed_lunch_finish = minutes_since_midnight(19 * 60)
|
||||
with pytest.raises(ValueError, match='Exposed lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='exposed lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_infected_presence_lunch_start_before_begining(baseline_form: model_generator.FormData):
|
||||
baseline_form.infected_lunch_start = minutes_since_midnight(8 * 60)
|
||||
with pytest.raises(ValueError, match='Infected lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='infected lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_infected_presence_lunch_start_after_finishing(baseline_form: model_generator.FormData):
|
||||
baseline_form.infected_lunch_start = minutes_since_midnight(19 * 60)
|
||||
baseline_form.infected_lunch_finish = minutes_since_midnight(20 * 60)
|
||||
with pytest.raises(ValueError, match='Infected lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='infected lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_infected_presence_lunch_finish_before_begining(baseline_form: model_generator.FormData):
|
||||
baseline_form.infected_lunch_start = minutes_since_midnight(7 * 60)
|
||||
baseline_form.infected_lunch_finish = minutes_since_midnight(8 * 60)
|
||||
with pytest.raises(ValueError, match='Infected lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='infected lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_infected_presence_lunch_finish_after_finishing(baseline_form: model_generator.FormData):
|
||||
baseline_form.infected_lunch_finish = minutes_since_midnight(19 * 60)
|
||||
with pytest.raises(ValueError, match='Infected lunch break must be within presence times.'):
|
||||
with pytest.raises(ValueError, match='infected lunch break must be within presence times.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_exposed_breaks_length(baseline_form: model_generator.FormData):
|
||||
baseline_form.exposed_coffee_break_option = 'coffee_break_4'
|
||||
baseline_form.exposed_coffee_duration = 30
|
||||
baseline_form.exposed_start = minutes_since_midnight(10 * 60)
|
||||
baseline_form.exposed_finish = minutes_since_midnight(11 * 60)
|
||||
baseline_form.exposed_lunch_option = False
|
||||
with pytest.raises(ValueError, match='Length of breaks >= Length of exposed presence.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
def test_infected_breaks_length(baseline_form: model_generator.FormData):
|
||||
baseline_form.infected_start = minutes_since_midnight(9 * 60)
|
||||
baseline_form.infected_finish = minutes_since_midnight(12 * 60)
|
||||
baseline_form.infected_lunch_start = minutes_since_midnight(10 * 60)
|
||||
baseline_form.infected_lunch_finish = minutes_since_midnight(11 * 60)
|
||||
baseline_form.infected_coffee_break_option = 'coffee_break_4'
|
||||
baseline_form.infected_coffee_duration = 30
|
||||
with pytest.raises(ValueError, match='Length of breaks >= Length of infected presence.'):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue