No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_translator_xmlfile.py 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #-*- coding: utf-8 -*-
  2. import unittest
  3. import tempfile
  4. import os
  5. import tests.loader_utils
  6. from lodel.editorial_model.translator import xmlfile
  7. from lodel.editorial_model.model import EditorialModel
  8. from lodel.editorial_model.components import *
  9. from lodel.editorial_model.exceptions import *
  10. class XmlFileTestCase(unittest.TestCase):
  11. def test_save(self):
  12. emmodel = EditorialModel("test model", description = "Test EM")
  13. cls1 = emmodel.new_class('testclass1', display_name = 'Classe de test 1', help_text = 'super aide')
  14. c1f1 = cls1.new_field('testfield1', data_handler = 'varchar')
  15. c1f2 = cls1.new_field('testfield2', data_handler = 'varchar')
  16. cls2 = emmodel.new_class('testclass2', display_name = 'Classe de test 2', help_text = 'super aide')
  17. c2f1 = cls2.new_field('testfield1', data_handler = 'varchar')
  18. c2f2 = cls2.new_field('testfield2', data_handler = 'varchar')
  19. grp1 = emmodel.new_group('testgroup1')
  20. grp1.add_components((cls1, c1f1))
  21. grp2 = emmodel.new_group('testgroup2')
  22. grp2.add_components((cls2, c1f2, c2f1, c2f2))
  23. grp2.add_dependencie(grp1)
  24. filename = {'filename' : 'savemodel.xml'}
  25. emmodel.save(xmlfile, **filename)
  26. new_model = EditorialModel.load(xmlfile, **filename)
  27. fname = {'filename' : 'savemodel_bis.xml'}
  28. new_model.save(xmlfile, **fname)
  29. #new_model2 = EditorialModel.load(xmlfile, **fname)
  30. self.assertNotEqual(id(new_model), id(emmodel))
  31. #self.assertEqual(new_model.d_hash(), new_model2.d_hash())
  32. new_cls2 = new_model.all_classes('testclass2')
  33. em_cls2 = emmodel.all_classes('testclass2')
  34. new_fields = new_cls2.fields()
  35. em_fields = em_cls2.fields()
  36. #for fld in new_fields:
  37. # print(fld.d_hash())
  38. #for fld in em_fields:
  39. # print(fld.d_hash())
  40. # fields OK
  41. new_cls1 = new_model.all_classes('testclass1')
  42. em_cls1 = emmodel.all_classes('testclass1')
  43. new_fields = new_cls1.fields()
  44. em_fields = em_cls1.fields()
  45. #for fld in new_fields:
  46. # print(fld.d_hash())
  47. #for fld in em_fields:
  48. # print(fld.d_hash())
  49. # fields OK
  50. # super().d_hash() OK si display_name et help_text dans cls2
  51. self.assertEqual(new_cls2.d_hash(),em_cls2.d_hash())
  52. self.assertEqual(new_model.all_classes('testclass1').d_hash(), cls1.d_hash())
  53. self.assertEqual(new_model.all_groups('testgroup2').d_hash(), grp2.d_hash())
  54. # Pb de d_hash required
  55. emmgrp1 = new_model.all_groups('testgroup1')
  56. for rep in emmgrp1.required_by:
  57. print(emmgrp1.required_by[rep])
  58. self.assertEqual(emmgrp1.d_hash(), grp1.d_hash())
  59. self.assertEqual(new_model.all_groups('testgroup1').d_hash(), emmodel.all_groups('testgroup1').d_hash())
  60. self.assertEqual(new_model.d_hash(), emmodel.d_hash())