@@ -0,0 +1,55 @@
|
||||
"""Components API: nutrients без обязательных protein/energy."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from app import create_app, db
|
||||
from app.lab.services.component_nutrients import nutrients_api_dict
|
||||
from app.models import Component
|
||||
from app.services.setup_state import mark_setup_complete
|
||||
from tests.helpers.zootech_test_helpers import ZootechTestConfig
|
||||
|
||||
|
||||
class ComponentRefactorTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.app = create_app(ZootechTestConfig)
|
||||
self.client = self.app.test_client()
|
||||
self.ctx = self.app.app_context()
|
||||
self.ctx.push()
|
||||
db.create_all()
|
||||
mark_setup_complete(self.app)
|
||||
self.client.post(
|
||||
"/api/auth/login",
|
||||
json={"login": "zootech-test-admin", "password": "zootech-test-secret"},
|
||||
)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
self.ctx.pop()
|
||||
|
||||
def test_create_component_with_nutrients(self) -> None:
|
||||
r = self.client.post(
|
||||
"/api/components",
|
||||
json={
|
||||
"name": "Тест lab nutrients",
|
||||
"type": "Концентрированные",
|
||||
"dry_matter": 88.0,
|
||||
"price": 12.0,
|
||||
"protein": 0,
|
||||
"energy": 0,
|
||||
"nutrients": {"Сыр. Протеин": 110, "СВ": 880},
|
||||
},
|
||||
)
|
||||
self.assertEqual(r.status_code, 201, r.get_data(as_text=True))
|
||||
comp_id = r.get_json()["id"]
|
||||
nutrients = nutrients_api_dict(comp_id)
|
||||
self.assertEqual(nutrients.get("Сыр. Протеин"), 110)
|
||||
|
||||
def test_get_component_returns_nutrients(self) -> None:
|
||||
r = self.client.get("/api/components")
|
||||
self.assertEqual(r.status_code, 200)
|
||||
body = r.get_json()
|
||||
self.assertTrue(isinstance(body, list))
|
||||
Reference in New Issue
Block a user