@@ -0,0 +1,57 @@
|
||||
"""Регрессия WESP: recipe_calculator и daily_plan не ломаются при lab."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app import create_app, db
|
||||
from app.models import Component, Ingredient, Recipe
|
||||
from app.services.daily_plan.ingredient_weights import resolve_plan_ingredient_weights
|
||||
from app.services.recipe_calculator import calculate_recipe
|
||||
from app.services.setup_state import mark_setup_complete
|
||||
from tests.helpers.zootech_test_helpers import ZootechTestConfig
|
||||
|
||||
|
||||
class LabRegressionWespTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.app = create_app(ZootechTestConfig)
|
||||
self.ctx = self.app.app_context()
|
||||
self.ctx.push()
|
||||
db.create_all()
|
||||
mark_setup_complete(self.app)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
self.ctx.pop()
|
||||
|
||||
def test_recipe_calculator_still_works(self) -> None:
|
||||
result = calculate_recipe(
|
||||
ingredients=[{"weightPerHead": 2.5, "dryMatter": 85.0, "component_id": "c1"}],
|
||||
heads_count=10,
|
||||
trip_percent=100.0,
|
||||
)
|
||||
self.assertIn("totals", result)
|
||||
self.assertGreater(float(result["totals"]["totalWeight"]), 0)
|
||||
|
||||
def test_daily_plan_ingredient_weights_still_works(self) -> None:
|
||||
recipe = Recipe(id="r1", name="R", dry_matter_locked=False, content_hash="")
|
||||
ing = Ingredient(
|
||||
id="i1",
|
||||
name="Ing",
|
||||
weight_per_head=2.0,
|
||||
amount=0.0,
|
||||
dry_matter=55.0,
|
||||
order=1,
|
||||
recipe_id="r1",
|
||||
component_id="c1",
|
||||
created_by="system",
|
||||
updated_by="system",
|
||||
)
|
||||
components = {
|
||||
"c1": Component(id="c1", name="A", type="grain", dry_matter=55.0),
|
||||
}
|
||||
out = resolve_plan_ingredient_weights(
|
||||
ing, recipe, heads=10, components_by_id=components, replacement_component_id=None
|
||||
)
|
||||
self.assertEqual(out["weightPerHead"], 2.0)
|
||||
Reference in New Issue
Block a user