@@ -0,0 +1,86 @@
|
||||
"""apply_from_master ставит execution в sync_queue (не lab_*)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from app import create_app, db
|
||||
from app.lab.commands import apply_from_master, seed_from_execution
|
||||
from app.lab.models import LabRationLine
|
||||
from app.models import Component, Ingredient, Recipe, SyncQueue
|
||||
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 LabApplySyncEnqueueTests(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.comp = Component(
|
||||
id=default_uuid(),
|
||||
name="Сено",
|
||||
type="Объемные корма",
|
||||
dry_matter=85.0,
|
||||
protein=10.0,
|
||||
energy=8.0,
|
||||
price=5.0,
|
||||
)
|
||||
self.recipe = Recipe(id=default_uuid(), name="Sync test", heads_per_trip=10, mixing_time=5)
|
||||
self.ingredient = Ingredient(
|
||||
id=default_uuid(),
|
||||
recipe_id=self.recipe.id,
|
||||
component_id=self.comp.id,
|
||||
name="Сено",
|
||||
amount=5.0,
|
||||
weight_per_head=5.0,
|
||||
order=0,
|
||||
)
|
||||
db.session.add_all([self.comp, self.recipe, self.ingredient])
|
||||
db.session.commit()
|
||||
seed_from_execution(self.recipe.id)
|
||||
line = LabRationLine.query.filter_by(recipe_id=self.recipe.id).first()
|
||||
line.daily_kg = 40.0
|
||||
db.session.commit()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
self.ctx.pop()
|
||||
|
||||
def test_apply_from_master_enqueues_ingredient_not_lab(self) -> None:
|
||||
before_lab = int(
|
||||
db.session.scalar(
|
||||
select(func.count()).select_from(SyncQueue).where(
|
||||
SyncQueue.table_name.like("lab_%")
|
||||
)
|
||||
)
|
||||
or 0
|
||||
)
|
||||
apply_from_master(self.recipe.id)
|
||||
after_ing = int(
|
||||
db.session.scalar(
|
||||
select(func.count()).select_from(SyncQueue).where(
|
||||
SyncQueue.table_name == "ingredient",
|
||||
SyncQueue.record_id == self.ingredient.id,
|
||||
)
|
||||
)
|
||||
or 0
|
||||
)
|
||||
after_lab = int(
|
||||
db.session.scalar(
|
||||
select(func.count()).select_from(SyncQueue).where(
|
||||
SyncQueue.table_name.like("lab_%")
|
||||
)
|
||||
)
|
||||
or 0
|
||||
)
|
||||
self.assertGreater(after_ing, 0)
|
||||
self.assertEqual(before_lab, after_lab)
|
||||
Reference in New Issue
Block a user