Catalyst / admin/Apex 14.8 GB / 57.8 GB 40.0 GB free
Help Sign in

admin / Apex

public

Bid Management and Orchestration Tool with AI Capability

Code Issues Pull requests Pipelines Packages Security Insights Wiki Settings
Apex / Synapse-Apexv2 / backend / tests / test_costing.py 2949 B · main
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from decimal import Decimal

from app.services.costing import (
    compute_effort_lines,
    compute_licence_lines,
    price_scenario,
    sheet_totals,
)
from app.services.scheduling import sub_working_days
from datetime import date


def test_effort_per_endpoint_scales():
    rules = [{
        "name": "SD per 100 ws", "trigger": "per_endpoint", "endpoint_type": "workstations",
        "per_qty": Decimal("100"), "resource_type_id": 1, "resource_name": "SD Analyst",
        "hourly_cost_rate": Decimal("28"), "hours_recurring": Decimal("32"), "hours_oneoff": Decimal("0"),
    }]
    lines = compute_effort_lines(rules, {"endpoints": {"workstations": 250}, "term_months": 12})
    assert len(lines) == 1
    # 250/100 * 32h = 80h * £28 = £2240.00
    assert lines[0]["monthly"] == Decimal("2240.00")


def test_fixed_rule():
    rules = [{
        "name": "SDM", "trigger": "fixed", "endpoint_type": None, "per_qty": Decimal("1"),
        "resource_type_id": 4, "resource_name": "SDM", "hourly_cost_rate": Decimal("55"),
        "hours_recurring": Decimal("34"), "hours_oneoff": Decimal("0"),
    }]
    lines = compute_effort_lines(rules, {"endpoints": {}, "term_months": 12})
    assert lines[0]["monthly"] == Decimal("1870.00")  # 34 * 55


def test_licence_per_endpoint():
    lics = [{"name": "EPP", "unit": "per_endpoint", "unit_cost": Decimal("4.5"), "billing": "monthly"}]
    lines = compute_licence_lines(lics, {"endpoints": {"servers": 10, "workstations": 90}})
    assert lines[0]["monthly"] == Decimal("450.00")  # 100 * 4.5


def test_sheet_totals():
    lines = [{"monthly": Decimal("1000"), "oneoff": Decimal("500")},
             {"monthly": Decimal("200"), "oneoff": Decimal("0")}]
    t = sheet_totals(lines, 12)
    assert t["monthly"] == Decimal("1200.00")
    assert t["oneoff"] == Decimal("500.00")
    assert t["total_contract"] == Decimal("14900.00")  # 1200*12 + 500


def test_price_margin_on_price():
    # base 10000, no contingency, 20% margin on price -> 12500
    r = price_scenario(Decimal("10000"), Decimal("0"), Decimal("0"), Decimal("20"), 12)
    assert r["total_cost"] == Decimal("10000.00")
    assert r["sell_price"] == Decimal("12500.00")
    assert r["profit"] == Decimal("2500.00")


def test_price_with_contingencies():
    # base 10000, 5% risk + 10% mgmt = 11500 cost, 25% margin -> 11500/0.75
    r = price_scenario(Decimal("10000"), Decimal("5"), Decimal("10"), Decimal("25"), 10)
    assert r["risk_amount"] == Decimal("500.00")
    assert r["mgmt_amount"] == Decimal("1000.00")
    assert r["total_cost"] == Decimal("11500.00")
    assert r["sell_price"] == Decimal("15333.33")


def test_back_schedule_working_days():
    # Fri 2026-07-10 minus 3 working days -> Tue 2026-07-07
    assert sub_working_days(date(2026, 7, 10), 3) == date(2026, 7, 7)
    # crosses a weekend: Mon 2026-07-13 minus 1 wd -> Fri 2026-07-10
    assert sub_working_days(date(2026, 7, 13), 1) == date(2026, 7, 10)