"""Профили стада — прямое чтение без legacy remap.""" from __future__ import annotations import unittest from app import create_app, db from app.lab.commands.delete_profile import delete_animal_profile from app.lab.commands.upsert_profile import upsert_animal_profile from app.lab.loaders.profile_loader import list_animal_profiles, load_animal_profile from app.lab.models import LabAnimalProfile from app.services.setup_state import mark_setup_complete from tests.helpers.zootech_test_helpers import ZootechTestConfig class LabProfileLoaderTests(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_create_and_load_profile(self) -> None: result = upsert_animal_profile( None, { "profileKey": "test_beef_custom", "label": "Тест", "rationType": "BEEF", "normsData": {"dry_matter": {"min": 1, "max": 2}}, }, "test", ) pid = result["id"] data = load_animal_profile(pid) self.assertEqual(data["profileKey"], "test_beef_custom") self.assertEqual(data["normsProfileKey"], "test_beef_custom") self.assertFalse(data["legacyNormsRemapped"]) def test_list_includes_lab_math_profiles(self) -> None: db.session.add( LabAnimalProfile( profile_key="lab_math_dairy_01", label="Math 1", ration_type="DAIRY", created_by="test", updated_by="test", ) ) db.session.commit() keys = [p["profileKey"] for p in list_animal_profiles("DAIRY")] self.assertIn("lab_math_dairy_01", keys) def test_delete_profile_soft_deletes_and_hides_from_list(self) -> None: result = upsert_animal_profile( None, { "profileKey": "to_delete", "label": "На удаление", "rationType": "BEEF", }, "test", ) pid = result["id"] delete_animal_profile(pid, "test") with self.assertRaises(LookupError): load_animal_profile(pid) keys = [p["profileKey"] for p in list_animal_profiles()] self.assertNotIn("to_delete", keys) row = LabAnimalProfile.query.get(pid) self.assertTrue(row.is_deleted)