test_models.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import unittest
  2. from src.models.ingredient_model import ingredient_model
  3. from src.models.recipe_model import recipe_model
  4. from src.models.company_model import company_model
  5. from src.settings.settings_manager import settings_manager
  6. from src.models.measurement_unit_model import measurement_unit_model
  7. from src.models.nomenclature_group_model import nomenclature_group_model
  8. from src.models.nomenclature_model import nomenclature_model
  9. from src.models.abstract_reference import abstract_reference
  10. from os import path
  11. class test_models(unittest.TestCase):
  12. def test_company(self):
  13. # Подготовка
  14. setman = settings_manager()
  15. setman.open(path.dirname(__file__) + "/../config/settings.json")
  16. sts = setman.settings
  17. # Действие
  18. company = company_model("Test company", sts)
  19. # Проверка
  20. assert isinstance(company, company_model)
  21. print("c", company.tax_id)
  22. print("s", sts.tax_id)
  23. assert company.tax_id == sts.tax_id
  24. assert company.bank_id == sts.bank_id
  25. assert company.bank_account_id == sts.bank_account_id
  26. assert company.property_type == sts.property_type
  27. def test_measurement_unit(self):
  28. # Подготовка
  29. g = measurement_unit_model("Граммы")
  30. kg = measurement_unit_model("Килограммы", 1000, g)
  31. # Действие
  32. # Проверка
  33. assert isinstance(g, measurement_unit_model)
  34. assert isinstance(kg, measurement_unit_model)
  35. assert g.to_base_unit(1) == 1
  36. assert kg.to_base_unit(1) == 1000
  37. def test_nomenclature(self):
  38. # Подготовка
  39. munit = measurement_unit_model("Test munit")
  40. fn = "abc"
  41. nom = nomenclature_model("Test nomenclature", fn, munit, nomenclature_group_model("Test ng"))
  42. # Действие
  43. # Проверка
  44. assert isinstance(nom, nomenclature_model)
  45. assert nom.full_name == fn
  46. def test_ingredient(self):
  47. # Подготовка
  48. munit = measurement_unit_model.create_g()
  49. nom = nomenclature_model("A", "A", munit, nomenclature_group_model("group"))
  50. amount = 10
  51. ingredient = ingredient_model("Тест", nom, amount, munit)
  52. # Действие
  53. # Проверка
  54. assert isinstance(ingredient, ingredient_model)
  55. assert ingredient.amount == amount
  56. assert ingredient.nomenclature == nom
  57. assert ingredient.measurement_unit == munit
  58. def test_recipe(self):
  59. # Подготовка
  60. munit = measurement_unit_model.create_g()
  61. nom = nomenclature_model("A", "A", munit, nomenclature_group_model("group"))
  62. nom2 = nomenclature_model("B", "B", munit, nomenclature_group_model("group"))
  63. amount = 10
  64. ingredient = ingredient_model("Тест", nom, amount, munit)
  65. ingredient2 = ingredient_model("Тест", nom2, amount, munit)
  66. steps = ["Aaaa.", "Bbbb."]
  67. recipe = recipe_model.create("Тест", [ingredient, ingredient2], steps)
  68. # Действие
  69. # Проверка
  70. assert isinstance(recipe, recipe_model)
  71. assert len(recipe.ingredients) == 2
  72. assert recipe.ingredients[0] == ingredient
  73. assert recipe.ingredients[1] == ingredient2
  74. assert len(recipe.steps) == 2
  75. assert recipe.steps[0] == steps[0]
  76. assert recipe.steps[1] == steps[1]
  77. def test_base_name_validation(self):
  78. # Подготовка
  79. fn = "abc"
  80. some = abstract_reference(fn)
  81. fn *= 2
  82. # Действие
  83. some.name = fn
  84. # Проверка
  85. assert some.name == fn