import unittest from src.models.ingredient_model import ingredient_model from src.models.recipe_model import recipe_model from src.models.company_model import company_model from src.settings.settings_manager import settings_manager from src.models.measurement_unit_model import measurement_unit_model from src.models.nomenclature_group_model import nomenclature_group_model from src.models.nomenclature_model import nomenclature_model from src.models.abstract_reference import abstract_reference from os import path class test_models(unittest.TestCase): def test_company(self): # Подготовка setman = settings_manager() setman.open(path.dirname(__file__) + "/../config/settings.json") sts = setman.settings # Действие company = company_model("Test company", sts) # Проверка assert isinstance(company, company_model) print("c", company.tax_id) print("s", sts.tax_id) assert company.tax_id == sts.tax_id assert company.bank_id == sts.bank_id assert company.bank_account_id == sts.bank_account_id assert company.property_type == sts.property_type def test_measurement_unit(self): # Подготовка g = measurement_unit_model("Граммы") kg = measurement_unit_model("Килограммы", 1000, g) # Действие # Проверка assert isinstance(g, measurement_unit_model) assert isinstance(kg, measurement_unit_model) assert g.to_base_unit(1) == 1 assert kg.to_base_unit(1) == 1000 def test_nomenclature(self): # Подготовка munit = measurement_unit_model("Test munit") fn = "abc" nom = nomenclature_model( "Test nomenclature", fn, munit, nomenclature_group_model("Test ng") ) # Действие # Проверка assert isinstance(nom, nomenclature_model) assert nom.full_name == fn def test_ingredient(self): # Подготовка munit = measurement_unit_model.create_g() nom = nomenclature_model("A", "A", munit, nomenclature_group_model("group")) amount = 10 ingredient = ingredient_model("Тест", nom, amount, munit) # Действие # Проверка assert isinstance(ingredient, ingredient_model) assert ingredient.amount == amount assert ingredient.nomenclature == nom assert ingredient.measurement_unit == munit def test_recipe(self): # Подготовка munit = measurement_unit_model.create_g() nom = nomenclature_model("A", "A", munit, nomenclature_group_model("group")) nom2 = nomenclature_model("B", "B", munit, nomenclature_group_model("group")) amount = 10 ingredient = ingredient_model("Тест", nom, amount, munit) ingredient2 = ingredient_model("Тест", nom2, amount, munit) steps = ["Aaaa.", "Bbbb."] recipe = recipe_model.create("Тест", [ingredient, ingredient2], steps) # Действие # Проверка assert isinstance(recipe, recipe_model) assert len(recipe.ingredients) == 2 assert recipe.ingredients[0] == ingredient assert recipe.ingredients[1] == ingredient2 assert len(recipe.steps) == 2 assert recipe.steps[0] == steps[0] assert recipe.steps[1] == steps[1] def test_base_name_validation(self): # Подготовка fn = "abc" some = abstract_reference(fn) fn *= 2 # Действие some.name = fn # Проверка assert some.name == fn