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:
+32
-69
@@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from rota.shifts import RotaBuilder, SingleShift, days
|
||||
from rota.shifts import PostShiftConstraint, PreShiftConstraint, RotaBuilder, SingleShift, days
|
||||
from rota.workers import Worker
|
||||
import datetime
|
||||
|
||||
@@ -59,7 +59,7 @@ def test_pre(demo_rota_clear):
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
workers_required=2,
|
||||
constraint=[{"name": "pre", "options": 1}],
|
||||
constraints=[PreShiftConstraint(days=1)],
|
||||
),
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
@@ -74,7 +74,7 @@ def test_pre(demo_rota_clear):
|
||||
length=12.5,
|
||||
days=days[3],
|
||||
workers_required=1,
|
||||
constraint=[{"name": "pre", "options": 1}, {"name": "post", "options": 1}],
|
||||
constraints=[PreShiftConstraint(days=1), PostShiftConstraint(days=1)],
|
||||
),
|
||||
)
|
||||
|
||||
@@ -123,12 +123,9 @@ def test_pre_post_clear(demo_rota_clear):
|
||||
days=days[:5],
|
||||
workers_required=2,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 1,
|
||||
},
|
||||
{"name": "post", "options": 1},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=1),
|
||||
PostShiftConstraint(days=1),
|
||||
],
|
||||
),
|
||||
SingleShift(
|
||||
@@ -138,12 +135,9 @@ def test_pre_post_clear(demo_rota_clear):
|
||||
days=days[5:],
|
||||
workers_required=2,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 1,
|
||||
},
|
||||
{"name": "post", "options": 1},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=1),
|
||||
PostShiftConstraint(days=1),
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -178,12 +172,9 @@ def test_pre_post_clear2(demo_rota_clear):
|
||||
days=days[:5],
|
||||
workers_required=2,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 2,
|
||||
},
|
||||
{"name": "post", "options": 2},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=2),
|
||||
PostShiftConstraint(days=2),
|
||||
],
|
||||
),
|
||||
SingleShift(
|
||||
@@ -193,12 +184,9 @@ def test_pre_post_clear2(demo_rota_clear):
|
||||
days=days[5:],
|
||||
workers_required=2,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 2,
|
||||
},
|
||||
{"name": "post", "options": 2},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=2),
|
||||
PostShiftConstraint(days=2),
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -237,12 +225,9 @@ def test_pre_post_clear_multi_group(demo_rota_clear):
|
||||
days=days[:5],
|
||||
workers_required=2,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 2,
|
||||
},
|
||||
{"name": "post", "options": 2},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=2),
|
||||
PostShiftConstraint(days=2),
|
||||
],
|
||||
),
|
||||
SingleShift(
|
||||
@@ -252,12 +237,9 @@ def test_pre_post_clear_multi_group(demo_rota_clear):
|
||||
days=days[5:],
|
||||
workers_required=1,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 2,
|
||||
},
|
||||
{"name": "post", "options": 2},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=2),
|
||||
PostShiftConstraint(days=2),
|
||||
],
|
||||
),
|
||||
SingleShift(
|
||||
@@ -267,12 +249,9 @@ def test_pre_post_clear_multi_group(demo_rota_clear):
|
||||
days=days[5:],
|
||||
workers_required=1,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 2,
|
||||
},
|
||||
{"name": "post", "options": 2},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=2),
|
||||
PostShiftConstraint(days=2),
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -318,12 +297,9 @@ def test_pre_post_clear_force_assign(demo_rota_clear):
|
||||
days=days[:5],
|
||||
workers_required=1,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 1,
|
||||
},
|
||||
{"name": "post", "options": 1},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=1),
|
||||
PostShiftConstraint(days=1),
|
||||
],
|
||||
),
|
||||
SingleShift(
|
||||
@@ -394,12 +370,7 @@ def test_pre_post_clear_force_assign2(demo_rota_clear):
|
||||
days=days[:5],
|
||||
workers_required=1,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
#{
|
||||
# "name": "pre",
|
||||
# "options": 1,
|
||||
#},
|
||||
#{"name": "post", "options": 1},
|
||||
constraints=[
|
||||
],
|
||||
),
|
||||
SingleShift(
|
||||
@@ -417,12 +388,7 @@ def test_pre_post_clear_force_assign2(demo_rota_clear):
|
||||
days=days[5:],
|
||||
workers_required=1,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
#{
|
||||
# "name": "pre",
|
||||
# "options": 2,
|
||||
#},
|
||||
#{"name": "post", "options": 2},
|
||||
constraints=[
|
||||
],
|
||||
),
|
||||
SingleShift(
|
||||
@@ -432,12 +398,9 @@ def test_pre_post_clear_force_assign2(demo_rota_clear):
|
||||
days=days[5:],
|
||||
workers_required=1,
|
||||
assign_as_block=False, # global setting is off
|
||||
constraint=[
|
||||
{
|
||||
"name": "pre",
|
||||
"options": 1,
|
||||
},
|
||||
{"name": "post", "options": 1},
|
||||
constraints=[
|
||||
PreShiftConstraint(days=1),
|
||||
PostShiftConstraint(days=1),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user