Refactor shift constraints in tests to use new constraint classes

- Updated test cases in `test_workers.py` to replace dictionary-based constraints with instances of `PreShiftConstraint`, `PostShiftConstraint`, and `MaxShiftsPerWeekConstraint`.
- Added a new test `test_worker_assign_as_block_preference2` to verify worker preferences for block assignments.
- Marked tests as slow where appropriate to improve test suite performance.
This commit is contained in:
Ross
2025-08-11 13:03:08 +01:00
parent d7bcfce78c
commit 76f3b48c1d
12 changed files with 790 additions and 987 deletions
+10 -3
View File
@@ -1,8 +1,9 @@
import datetime
import pytest
from pytest import approx
from rota.shifts import RotaBuilder, SingleShift, days
from rota.shifts import PostShiftConstraint, RotaBuilder, SingleShift, days
from rota.workers import Worker
from web.rota.shifts import PreShiftConstraint
@pytest.fixture
def demo_rota_nights():
@@ -48,7 +49,10 @@ def demo_rota_nights():
length=12.5,
days=days[:4],
workers_required=1,
constraint=[{"name": "pre", "options": 1}, {"name": "post", "options": 2}],
constraints=[
PreShiftConstraint(days=1),
PostShiftConstraint(days=2),
],
force_as_block=True
),
SingleShift(
@@ -56,7 +60,10 @@ def demo_rota_nights():
name="night_weekend",
length=12.5,
days=days[4:],
constraint=[{"name": "pre", "options": 1}, {"name": "post", "options": 2}],
constraints=[
PreShiftConstraint(days=1),
PostShiftConstraint(days=2),
],
force_as_block=True,
),
SingleShift(