test_models.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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(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()
  40. fn = "abc"
  41. nom = nomenclature_model(fn, munit, None)
  42. # Действие
  43. # Проверка
  44. assert isinstance(nom, nomenclature_model)
  45. assert nom.full_name == fn
  46. def test_base_name_validation(self):
  47. # Подготовка
  48. some = abstract_reference()
  49. fn = "abc"
  50. # Действие
  51. some.name = fn
  52. # Проверка
  53. self.assertRaises(argument_exception, some.name(""))
  54. self.assertRaises(argument_exception, some.name(" " * 51))
  55. self.assertRaises(argument_exception, 10)
  56. assert some.name == fn