63 lines
3.1 KiB
Python
63 lines
3.1 KiB
Python
|
|
import json
|
||
|
|
import sys
|
||
|
|
import unittest
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
sys.path.insert(0, str(Path(__file__).parents[1] / "tools"))
|
||
|
|
from cost_model import forecast
|
||
|
|
|
||
|
|
|
||
|
|
class CostModelTest(unittest.TestCase):
|
||
|
|
def setUp(self):
|
||
|
|
root = Path(__file__).parents[1]
|
||
|
|
self.demand = json.loads((root / "data/demand/platform-audit-storage.json").read_text())
|
||
|
|
self.providers = json.loads((root / "data/providers/object-storage.json").read_text())
|
||
|
|
|
||
|
|
def test_all_scenarios_and_providers_are_projected_for_12_months(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
for rows in result["scenarios"].values():
|
||
|
|
self.assertEqual(12 * len(self.providers["providers"]), len(rows))
|
||
|
|
|
||
|
|
def test_unknown_prices_never_become_zero(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
host_europe = [r for r in result["scenarios"]["base"] if r["provider_id"] == "host-europe-cloud-storage"]
|
||
|
|
self.assertTrue(all(r["recurring_total_eur"] is None for r in host_europe))
|
||
|
|
self.assertTrue(all(r["missing_price_fields"] for r in host_europe))
|
||
|
|
|
||
|
|
def test_storage_grows_month_over_month(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
rows = [r for r in result["scenarios"]["high"] if r["provider_id"] == "scaleway-standard-multi-az"]
|
||
|
|
self.assertGreater(rows[-1]["stored_gb"], rows[0]["stored_gb"])
|
||
|
|
|
||
|
|
def test_fixed_capacity_self_hosted_option_fails_closed_when_full(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
rows = [r for r in result["scenarios"]["base"] if r["provider_id"] == "hetzner-garage-3"]
|
||
|
|
self.assertIsNotNone(rows[0]["recurring_total_eur"])
|
||
|
|
self.assertIsNone(rows[-1]["recurring_total_eur"])
|
||
|
|
|
||
|
|
def test_managed_cloud_comparators_calculate(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
ids = {"aws-s3-standard", "azure-blob-hot-zrs", "gcp-cloud-storage-standard", "stackit-object-storage"}
|
||
|
|
rows = [r for r in result["scenarios"]["base"] if r["month"] == 1 and r["provider_id"] in ids]
|
||
|
|
self.assertEqual(ids, {r["provider_id"] for r in rows})
|
||
|
|
self.assertTrue(all(r["recurring_total_eur"] is not None for r in rows))
|
||
|
|
|
||
|
|
def test_recurring_total_is_infrastructure_plus_labor(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
row = next(r for r in result["comparison_320gb"] if r["provider_id"] == "stackit-object-storage")
|
||
|
|
self.assertAlmostEqual(row["recurring_total_eur"], row["monthly_infrastructure_eur"] + row["monthly_internal_labor_eur"])
|
||
|
|
|
||
|
|
def test_normalized_comparison_uses_320gb_for_every_provider(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
self.assertEqual(len(self.providers["providers"]), len(result["comparison_320gb"]))
|
||
|
|
self.assertTrue(all(r["stored_gb"] == 320 for r in result["comparison_320gb"]))
|
||
|
|
|
||
|
|
def test_garage_external_setup_services_are_unquoted(self):
|
||
|
|
result = forecast(self.demand, self.providers)
|
||
|
|
rows = [r for r in result["comparison_320gb"] if "garage" in r["provider_id"]]
|
||
|
|
self.assertTrue(all(r["setup_external_services_eur"] is None for r in rows))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|