162 lines
5.4 KiB
Python
162 lines
5.4 KiB
Python
"""Staffing and cost: arithmetic on the rate card, never an agent's figure."""
|
|
|
|
import shutil
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from app.operating_model import staffing
|
|
from app.operating_model.staffing import RateCardError
|
|
from app.operating_model.workflow import ROOT
|
|
from tests.support import BUNDLE, CAPABILITIES, CARD, GRAPH, graph
|
|
|
|
SKILL = ROOT / "skills" / staffing.SKILL
|
|
|
|
|
|
def by_role(result) -> dict:
|
|
return {row["role"]: row for row in result["roles"]}
|
|
|
|
|
|
def test_the_figures_for_a_fixed_graph_and_card_are_reproduced_exactly():
|
|
result = staffing.compute(GRAPH, CAPABILITIES, CARD, "GBP")
|
|
rows = by_role(result)
|
|
|
|
# The SRE is responsible for incidents (60 h, 24x7) and changes (40 h): 100 h
|
|
# is two thirds of one person in Poland, but every hour of every day needs a
|
|
# rota of five. 5 x 460 a day x 220 days / 12 x 1.25 uplift x 0.79 to GBP.
|
|
assert rows["R-2"]["effort_hours_per_month"] == 100
|
|
assert rows["R-2"]["hours"] == "24x7"
|
|
assert rows["R-2"]["people"] == 5.0
|
|
assert rows["R-2"]["cost_per_month"] == 41640
|
|
# The service manager: 16 h of a 137.5 h month in the United Kingdom.
|
|
assert rows["R-3"]["people"] == 0.1
|
|
assert rows["R-3"]["cost_per_month"] == 1770
|
|
assert result["cost_per_month"] == 43410
|
|
assert result["by_party"] == {"P-2": 43410}
|
|
assert result["by_country"] == {"PL": 41640, "GB": 1770}
|
|
assert result["by_capability"] == {"C-1": 24984, "C-2": 16656, "C-3": 1770}
|
|
|
|
|
|
def test_the_customers_own_staff_are_counted_and_never_priced():
|
|
rows = by_role(staffing.compute(GRAPH, CAPABILITIES, CARD, "GBP"))
|
|
|
|
assert rows["R-1"]["cost_per_month"] is None
|
|
assert rows["R-1"]["people"] == 0.0
|
|
|
|
|
|
def test_a_customer_role_that_does_the_work_still_carries_no_cost():
|
|
model = graph()
|
|
model["responsibilities"][4]["role"] = "R-1" # the customer makes the changes
|
|
|
|
rows = by_role(staffing.compute(model, CAPABILITIES, CARD, "GBP"))
|
|
|
|
assert rows["R-1"]["effort_hours_per_month"] == 40
|
|
assert rows["R-1"]["people"] == 0.3
|
|
assert rows["R-1"]["cost_per_month"] is None
|
|
|
|
|
|
def test_a_role_on_business_hours_is_as_small_as_its_work():
|
|
model = graph()
|
|
model["roles"][1]["hours"] = "business"
|
|
capabilities = [dict(c, hours="business") for c in CAPABILITIES]
|
|
|
|
row = by_role(staffing.compute(model, capabilities, CARD, "GBP"))["R-2"]
|
|
|
|
assert row["hours"] == "business"
|
|
assert row["people"] == 0.7 # 100 h of a 146.7 h month, and no rota
|
|
|
|
|
|
def test_the_result_is_in_the_currency_the_spec_states():
|
|
pounds = staffing.compute(GRAPH, CAPABILITIES, CARD, "GBP")
|
|
dollars = staffing.compute(GRAPH, CAPABILITIES, CARD, "USD")
|
|
|
|
assert dollars["cost_per_month"] == 54948
|
|
assert pounds["conversion"] == {"from": "USD", "rate": 0.79, "as_of": "2026-10-13"}
|
|
assert dollars["conversion"]["rate"] == 1.0
|
|
|
|
|
|
def test_roles_that_share_a_capability_divide_its_effort():
|
|
model = graph()
|
|
model["responsibilities"].append(
|
|
{"id": "RS-9", "capability": "C-3", "role": "R-2", "kind": "responsible"}
|
|
)
|
|
|
|
equal = by_role(staffing.compute(model, CAPABILITIES, CARD, "GBP"))
|
|
model["responsibilities"][6]["share"] = 0.75
|
|
model["responsibilities"][-1]["share"] = 0.25
|
|
stated = by_role(staffing.compute(model, CAPABILITIES, CARD, "GBP"))
|
|
|
|
assert equal["R-2"]["effort_hours_per_month"] == 108 # 100 and half of 16
|
|
assert stated["R-2"]["effort_hours_per_month"] == 104 # 100 and a quarter of 16
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("shares", "problem"),
|
|
[
|
|
((0.75, None), "must all state a share"),
|
|
((0.75, 0.5), "do not add up to 1"),
|
|
((1.5, -0.5), "must all state a share"),
|
|
],
|
|
)
|
|
def test_shares_that_do_not_hold_together_are_a_fault(shares, problem):
|
|
entries = [
|
|
{"capability": "C-3", "role": role, "kind": "responsible", "share": share}
|
|
for role, share in zip(("R-2", "R-3"), shares, strict=True)
|
|
]
|
|
|
|
assert problem in staffing.shares(entries)[1][0]
|
|
|
|
|
|
def test_the_card_in_the_repository_is_marked_as_placeholders():
|
|
assert CARD.is_draft
|
|
assert CARD.prices == ("provider",)
|
|
|
|
|
|
def test_the_currencies_a_spec_may_state_are_the_ones_the_card_converts_to():
|
|
assert list(BUNDLE.scope_values["commercial.currency"]) == CARD.currencies()
|
|
|
|
|
|
@pytest.fixture
|
|
def skill(tmp_path):
|
|
shutil.copytree(SKILL, tmp_path / "skill")
|
|
return tmp_path / "skill"
|
|
|
|
|
|
def edit(skill, change):
|
|
path = skill / "assets" / "rates.yaml"
|
|
data = yaml.safe_load(path.read_text())
|
|
change(data)
|
|
path.write_text(yaml.safe_dump(data))
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("change", "problem"),
|
|
[
|
|
(
|
|
lambda d: d["prices"].append("customer"),
|
|
"the customer's own staff are never priced",
|
|
),
|
|
(
|
|
lambda d: d["countries"]["PL"]["day_rate"].pop("lead"),
|
|
"PL has no day rate for level lead",
|
|
),
|
|
(lambda d: d["cover"].pop("24x7"), "cover for 24x7 needs a minimum_roster"),
|
|
(
|
|
lambda d: d["conversion"]["rates"].update(GBP=0),
|
|
"conversion rate for GBP must be a number above zero",
|
|
),
|
|
(lambda d: d.pop("currency"), "needs currency"),
|
|
],
|
|
)
|
|
def test_a_rate_card_that_does_not_hold_together_is_refused(skill, change, problem):
|
|
edit(skill, change)
|
|
|
|
with pytest.raises(RateCardError, match=problem):
|
|
staffing.load(skill)
|
|
|
|
|
|
def test_a_card_whose_version_is_set_is_no_longer_a_draft(skill):
|
|
edit(skill, lambda d: d.update(version="2026-11"))
|
|
|
|
assert not staffing.load(skill).is_draft
|