Add ignore_dates field to worker constraints and implement related tests
This commit is contained in:
@@ -161,6 +161,101 @@ def test_worker_block_constraint_validation():
|
||||
with pytest.raises(ValidationError):
|
||||
MaxUniqueShiftsPerWeekBlockConstraint(max_unique_shifts=0, week_block=1)
|
||||
|
||||
|
||||
def test_worker_max_days_per_week_block_pass():
|
||||
"""Positive test: constraint allowing reasonable days."""
|
||||
Rota = generate_basic_rota()
|
||||
# Add constraint allowing up to 4 days per week
|
||||
Rota.workers[0].max_days_per_week_block = [
|
||||
MaxDaysPerWeekBlockConstraint(max_days=4, week_block=1)
|
||||
]
|
||||
# Add shifts to the rota
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days,
|
||||
)
|
||||
)
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
assert Rota.results.solver.status == "ok"
|
||||
assert Rota.results.solver.termination_condition == "optimal"
|
||||
|
||||
|
||||
def test_worker_max_unique_shifts_per_week_block_pass():
|
||||
"""Positive test: allowing multiple shifts within week block."""
|
||||
Rota = generate_basic_rota()
|
||||
# Add constraint allowing up to 2 unique shifts per week
|
||||
Rota.workers[0].max_unique_shifts_per_week_block = [
|
||||
MaxUniqueShiftsPerWeekBlockConstraint(max_unique_shifts=2, week_block=1)
|
||||
]
|
||||
# Add shifts to the rota
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days,
|
||||
)
|
||||
)
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
assert Rota.results.solver.status == "ok"
|
||||
assert Rota.results.solver.termination_condition == "optimal"
|
||||
|
||||
|
||||
def test_worker_max_days_per_week_block_with_ignore_dates():
|
||||
"""Test max_days_per_week_block with ignored dates works without error."""
|
||||
Rota = generate_basic_rota()
|
||||
rota_start = Rota.start_date
|
||||
ignored_date = rota_start # Ignore first Monday
|
||||
# Add constraint with ignore_dates
|
||||
Rota.workers[0].max_days_per_week_block = [
|
||||
MaxDaysPerWeekBlockConstraint(
|
||||
max_days=3,
|
||||
week_block=1,
|
||||
ignore_dates=[ignored_date],
|
||||
)
|
||||
]
|
||||
# Add shifts to the rota
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days,
|
||||
)
|
||||
)
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
|
||||
def test_worker_max_unique_shifts_per_week_block_with_ignore_dates():
|
||||
"""Test max_unique_shifts_per_week_block with ignored dates works without error."""
|
||||
Rota = generate_basic_rota()
|
||||
rota_start = Rota.start_date
|
||||
ignored_date = rota_start + datetime.timedelta(days=1) # Ignore Tuesday
|
||||
# Add constraint with ignore_dates
|
||||
Rota.workers[0].max_unique_shifts_per_week_block = [
|
||||
MaxUniqueShiftsPerWeekBlockConstraint(
|
||||
max_unique_shifts=1,
|
||||
week_block=1,
|
||||
ignore_dates=[ignored_date],
|
||||
)
|
||||
]
|
||||
# Add shifts to the rota
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days,
|
||||
)
|
||||
)
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
# This should still be feasible with only one shift type in main rota
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
def test_pre_shift_constraint():
|
||||
Rota = generate_basic_rota()
|
||||
for i, d in enumerate(days[:6]):
|
||||
|
||||
Reference in New Issue
Block a user