test_models.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import unittest
  2. from src.models.company_model import company_model
  3. from src.settings.settings_manager import settings_manager
  4. from src.models.measurement_unit_model import measurement_unit_model
  5. from src.models.nomenclature_group_model import nomenclature_group_model
  6. from src.models.nomenclature_model import nomenclature_model
  7. from src.models.warehouse_model import warehouse_model
  8. from src.models.abstract_reference import abstract_reference
  9. from src.errors.argument_exception import argument_exception
  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_base_name_validation(self):
  47. # Подготовка
  48. fn = "abc"
  49. some = abstract_reference(fn)
  50. fn *= 2
  51. # Действие
  52. some.name = fn
  53. # Проверка
  54. assert some.name == fn