further tests and fixes
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import datetime
|
||||
import pytest
|
||||
from rota.shifts import InvalidShift, NoWorkers, RotaBuilder, SingleShift, days
|
||||
|
||||
from rota.workers import Worker
|
||||
|
||||
import itertools
|
||||
|
||||
|
||||
def generate_basic_rota(weeks_to_rota=10):
|
||||
start_date = datetime.date(2022, 3, 7)
|
||||
|
||||
Rota = RotaBuilder(
|
||||
start_date,
|
||||
weeks_to_rota=weeks_to_rota,
|
||||
)
|
||||
|
||||
# Add a few workers
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(Rota, "worker1", "group1", 1),
|
||||
Worker(Rota, "worker2", "group1", 1),
|
||||
]
|
||||
)
|
||||
|
||||
return Rota
|
||||
|
||||
|
||||
def date_generator(from_date, days):
|
||||
n = 0
|
||||
while True:
|
||||
yield from_date
|
||||
|
||||
n = n + 1
|
||||
if n >= days:
|
||||
break
|
||||
from_date = from_date + datetime.timedelta(days=1)
|
||||
|
||||
|
||||
class TestShifts:
|
||||
def test_duplicate_shifts(self):
|
||||
Rota = generate_basic_rota()
|
||||
|
||||
Rota.add_worker(
|
||||
Worker(
|
||||
Rota,
|
||||
"worker3",
|
||||
"group1",
|
||||
1,
|
||||
),
|
||||
)
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
("group1", "group2"),
|
||||
"a",
|
||||
12.5,
|
||||
days,
|
||||
),
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
assert Rota.results.solver.termination_condition == "optimal"
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
("group1"),
|
||||
"a",
|
||||
12.5,
|
||||
days,
|
||||
),
|
||||
)
|
||||
|
||||
with pytest.raises(InvalidShift):
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Reference in New Issue
Block a user