1
1

test_models.py 3.8 KB

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