@@ -0,0 +1,56 @@
|
||||
"""ration_recalc service."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app import create_app, db
|
||||
from app.lab.models import LabRationLine, LabRecipeRation
|
||||
from app.lab.services.ration_recalc import find_rations_by_component
|
||||
from app.models import Component, Recipe
|
||||
from app.models.base import default_uuid
|
||||
from app.services.setup_state import mark_setup_complete
|
||||
from tests.helpers.zootech_test_helpers import ZootechTestConfig
|
||||
|
||||
|
||||
class RationRecalcServiceTests(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)
|
||||
self.recipe = Recipe(id=default_uuid(), name="R", heads_per_trip=10, mixing_time=5)
|
||||
self.comp = Component(
|
||||
id=default_uuid(),
|
||||
name="C",
|
||||
dry_matter=88.0,
|
||||
created_by="test",
|
||||
updated_by="test",
|
||||
)
|
||||
db.session.add_all([self.recipe, self.comp])
|
||||
db.session.add(
|
||||
LabRecipeRation(recipe_id=self.recipe.id, created_by="test", updated_by="test")
|
||||
)
|
||||
db.session.add(
|
||||
LabRationLine(
|
||||
id=default_uuid(),
|
||||
recipe_id=self.recipe.id,
|
||||
component_id=self.comp.id,
|
||||
daily_kg=10.0,
|
||||
in_ration=True,
|
||||
row_index=0,
|
||||
created_by="test",
|
||||
updated_by="test",
|
||||
)
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
self.ctx.pop()
|
||||
|
||||
def test_find_rations_by_component(self) -> None:
|
||||
ids = find_rations_by_component(self.comp.id)
|
||||
self.assertEqual(ids, [self.recipe.id])
|
||||
Reference in New Issue
Block a user